Mercurial > ecos
annotate packages/language/c/libc/current/tests/string/memchr.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 // memchr.c | |
| 4 // | |
| 5 // Testcase for C library memchr() | |
| 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 memchr() 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 // Functions to avoid having to use libc strings | |
| 74 | |
| 75 #ifdef CYGPKG_LIBC | |
| 76 static int my_strcmp(const char *s1, const char *s2) | |
| 77 { | |
| 78 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 79 { | |
| 80 if ( *s1 == '\0' ) | |
| 81 break; | |
| 82 } // for | |
| 83 | |
| 84 return (*s1 - *s2); | |
| 85 } // my_strcmp() | |
| 86 #endif | |
| 87 | |
| 88 | |
| 89 int main( int argc, char *argv[] ) | |
| 90 { | |
| 91 #ifdef CYGPKG_LIBC | |
| 92 char x[] = "Your feeble skills are no match for the power of " | |
| 93 "the dark side!"; | |
| 94 void *ret; | |
| 95 #endif | |
| 96 | |
| 97 CYG_TEST_INIT(); | |
| 98 | |
| 99 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 100 "memchr() function"); | |
| 101 | |
| 102 #ifdef CYGPKG_LIBC | |
| 103 // Check 1 | |
| 104 ret = memchr(x, (int)'k', sizeof(x)); | |
| 105 CYG_TEST_PASS_FAIL( (my_strcmp(ret, x+13) == 0), "Simple test 1" ); | |
| 106 | |
| 107 // Check 2 | |
| 108 ret = memchr(x, (int)'p', sizeof(x)); | |
| 109 CYG_TEST_PASS_FAIL( (my_strcmp(ret, x+40) == 0), "Simple test 2" ); | |
| 110 | |
| 111 // Check 3 | |
| 112 ret = memchr(x, (int)'z', sizeof(x)); | |
| 113 CYG_TEST_PASS_FAIL( (ret == NULL), "Simple test 3" ); | |
| 114 | |
| 115 // Check 4 (boundary condition) | |
| 116 ret = memchr(x, (int)'\0', sizeof(x)); | |
| 117 CYG_TEST_PASS_FAIL( ret == (x+sizeof(x)-1), "Boundary test 1" ); | |
| 118 | |
| 119 // Check 5 (boundary condition) | |
| 120 ret = memchr(x, (int)'\0', sizeof(x)-1); | |
| 121 CYG_TEST_PASS_FAIL( ret == NULL, "Boundary test 2" ); | |
| 122 | |
| 123 // Check 6 (boundary condition) | |
| 124 ret = memchr( (void *)"", (int)'\0', 0 ); | |
| 125 CYG_TEST_PASS_FAIL( ret == NULL, "Boundary test 3" ); | |
| 126 | |
| 127 #else // ifndef CYGPKG_LIBC | |
| 2 | 128 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 129 #endif // ifndef CYGPKG_LIBC |
| 130 | |
| 131 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 132 "memchr() function"); | |
| 133 } // main() | |
| 134 | |
| 135 // EOF memchr.c |
