Mercurial > flash_v2
annotate packages/language/c/libc/current/tests/string/strncat1.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // strncat1.c | |
| 4 // | |
| 5 // Testcase for C library strncat() | |
| 6 // | |
| 7 //================================================================= | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //================================================================= | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): ctarpy, jlarmour |
| 35 // Contributors: jlarmour | |
| 0 | 36 // Date: 1998/6/3 |
| 37 // Description: Contains testcode for C library strncat() function | |
| 38 // | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 | |
| 42 // Declarations for test system: | |
| 43 // | |
| 44 // TESTCASE_TYPE=CYG_TEST_MODULE | |
| 45 // COMPOUND_TESTCASE | |
| 46 | |
| 47 | |
| 48 // CONFIGURATION | |
| 49 | |
| 50 #include <pkgconf/libc.h> // Configuration header | |
| 51 | |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <string.h> | |
| 55 #include <cyg/infra/testcase.h> | |
| 56 #include <sys/cstartup.h> // C library initialisation | |
| 57 | |
| 58 | |
| 59 // FUNCTIONS | |
| 60 | |
| 61 | |
| 62 externC void | |
| 63 cyg_package_start( void ) | |
| 64 { | |
| 65 #ifdef CYGPKG_LIBC | |
| 66 cyg_iso_c_start(); | |
| 67 #else | |
| 68 (void)main(0, NULL); | |
| 69 #endif | |
| 70 } // cyg_package_start() | |
| 71 | |
| 72 | |
| 73 | |
| 74 #ifdef CYGPKG_LIBC | |
| 75 | |
| 76 // Functions to avoid having to use libc strings | |
| 77 | |
| 78 static int my_strlen(const char *s) | |
| 79 { | |
| 80 const char *ptr; | |
| 81 | |
| 82 ptr = s; | |
| 83 for ( ptr=s ; *ptr != '\0' ; ptr++ ) | |
| 84 ; | |
| 85 | |
| 86 return (int)(ptr-s); | |
| 87 } // my_strlen() | |
| 88 | |
| 89 | |
| 90 static int my_strcmp(const char *s1, const char *s2) | |
| 91 { | |
| 92 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 93 { | |
| 94 if ( *s1 == '\0' ) | |
| 95 break; | |
| 96 } // for | |
| 97 | |
| 98 return (*s1 - *s2); | |
| 99 } // my_strcmp() | |
| 100 | |
| 101 | |
| 102 static char *my_strcpy(char *s1, const char *s2) | |
| 103 { | |
| 104 while (*s2 != '\0') { | |
| 105 *(s1++) = *(s2++); | |
| 106 } | |
| 107 *s1 = '\0'; | |
| 108 | |
| 109 return s1; | |
| 110 } // my_strcpy() | |
| 111 #endif // ifdef CYGPKG_LIBC | |
| 112 | |
| 113 | |
| 114 int main( int argc, char *argv[] ) | |
| 115 { | |
| 116 #ifdef CYGPKG_LIBC | |
| 117 char x[300]; | |
| 118 char y[300]; | |
| 119 char *ret; | |
| 120 #endif | |
| 121 | |
| 122 CYG_TEST_INIT(); | |
| 123 | |
| 124 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 125 "memmove() function"); | |
| 126 CYG_TEST_INFO("This testcase provides simple basic tests"); | |
| 127 | |
| 128 | |
| 129 #ifdef CYGPKG_LIBC | |
| 130 | |
| 131 // Check 1 | |
| 132 my_strcpy(x, "One ring to rule them all."); | |
| 133 my_strcpy(y, "One ring to find them."); | |
| 134 ret = strncat(x, y, my_strlen(y)+1); | |
| 135 if ( my_strcmp(x, "One ring to rule them all.One ring to find them.")==0 ) | |
| 136 CYG_TEST_PASS("Simple concatenation"); | |
| 137 else | |
| 138 CYG_TEST_FAIL("Simple concatenation"); | |
| 139 // Check return val | |
| 140 CYG_TEST_PASS_FAIL( ( ret == x ), "Simple concatenation return value" ); | |
| 141 | |
| 142 | |
| 143 // Check 2 | |
| 144 my_strcpy(x, "One ring to bring them all,"); | |
| 145 my_strcpy(y, ""); | |
| 146 ret = strncat(x, y, my_strlen(y)+1); | |
| 147 if ( my_strcmp(x, "One ring to bring them all,")==0 ) | |
| 148 CYG_TEST_PASS("Concatenation of empty string"); | |
| 149 else | |
| 150 CYG_TEST_FAIL("Concatenation of empty string"); | |
| 151 // Check return val | |
| 152 CYG_TEST_PASS_FAIL( ( ret == x ), | |
| 153 "Concatenation of empty string return value" ); | |
| 154 | |
| 155 | |
| 156 // Check 3 | |
| 157 my_strcpy(x, "and in the darkness bind them"); | |
| 158 my_strcpy(y, ""); | |
| 159 ret = strncat(y, x, my_strlen(x)+1 ); | |
| 160 if ( my_strcmp(x, "and in the darkness bind them")==0 ) | |
| 161 CYG_TEST_PASS("Concatenation to empty string"); | |
| 162 else | |
| 163 CYG_TEST_FAIL("Concatenation to empty string"); | |
| 164 // Check return val | |
| 165 CYG_TEST_PASS_FAIL( ( ret == y ), | |
| 166 "Concatenation to empty string return value" ); | |
| 167 | |
| 168 // Check 4 | |
| 169 my_strcpy(x, "in the land of "); | |
| 170 my_strcpy(y, "Mordor, where the shadows lie"); | |
| 171 ret = strncat(x, y, 6 ); | |
| 172 if ( my_strcmp(x, "in the land of Mordor")==0 ) | |
| 173 CYG_TEST_PASS("Concatenation of partial string string"); | |
| 174 else | |
| 175 CYG_TEST_FAIL("Concatenation of partial string"); | |
| 176 // Check return val | |
| 177 CYG_TEST_PASS_FAIL( ( ret == x ), | |
| 178 "Concatenation to empty string return value" ); | |
| 179 | |
| 180 #else // ifndef CYGPKG_LIBC | |
| 2 | 181 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 182 #endif // ifndef CYGPKG_LIBC |
| 183 | |
| 184 | |
| 185 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 186 "strncat() function"); | |
| 187 } // main() | |
| 188 | |
| 189 | |
| 190 // EOF strncat1.c |
