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