|
0
|
1 //================================================================= |
|
|
2 // |
|
|
3 // strspn.c |
|
|
4 // |
|
|
5 // Testcase for C library strspn() |
|
|
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 |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): ctarpy, jlarmour |
|
|
33 // Contributors: jlarmour |
|
0
|
34 // Date: 1998/6/3 |
|
|
35 // Description: Contains testcode for C library strspn() 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 // Functions to avoid having to use libc strings |
|
|
73 |
|
|
74 #ifdef CYGPKG_LIBC |
|
|
75 static char *my_strcpy(char *s1, const char *s2) |
|
|
76 { |
|
|
77 while (*s2 != '\0') { |
|
|
78 *(s1++) = *(s2++); |
|
|
79 } |
|
|
80 *s1 = '\0'; |
|
|
81 |
|
|
82 return s1; |
|
|
83 } // my_strcpy() |
|
|
84 #endif |
|
|
85 |
|
|
86 |
|
|
87 int main( int argc, char *argv[] ) |
|
|
88 { |
|
|
89 #ifdef CYGPKG_LIBC |
|
|
90 char x[300]; |
|
|
91 char y[300]; |
|
|
92 int ret; |
|
|
93 #endif |
|
|
94 |
|
|
95 |
|
|
96 CYG_TEST_INIT(); |
|
|
97 |
|
|
98 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " |
|
|
99 "strspn() function"); |
|
|
100 CYG_TEST_INFO("This testcase provides simple basic tests"); |
|
|
101 |
|
|
102 #ifdef CYGPKG_LIBC |
|
|
103 |
|
|
104 // Check 1 |
|
|
105 my_strcpy(x, "ah blow my nose at you, so-called Arthur king!"); |
|
|
106 my_strcpy(y, "wolbah "); |
|
|
107 ret = strspn(x, y); |
|
|
108 CYG_TEST_PASS_FAIL( (ret == 8), "Simple strspn() #1" ); |
|
|
109 |
|
|
110 |
|
|
111 // Check 2 |
|
|
112 my_strcpy(x, "Not bad for a little fur ball. You! Stay here."); |
|
|
113 my_strcpy(y, "litea rofdbN"); |
|
|
114 ret = strspn(x, y); |
|
|
115 CYG_TEST_PASS_FAIL( (ret == 22), "Simple strspn() #2" ); |
|
|
116 |
|
|
117 // Check 3 |
|
|
118 my_strcpy(x, "Not bad for a little fur ball. You! Stay here."); |
|
|
119 my_strcpy(y, "litearofdbN"); |
|
|
120 ret = strspn(x, y); |
|
|
121 CYG_TEST_PASS_FAIL( (ret == 3), "Simple strspn() #3"); |
|
|
122 |
|
|
123 // Check 4 (boundary condition) |
|
|
124 my_strcpy(x, "Not bad for a little fur ball. You! Stay here."); |
|
|
125 my_strcpy(y, "litearofdb"); |
|
|
126 ret = strspn(x, y); |
|
|
127 CYG_TEST_PASS_FAIL( (ret == 0), "First character not in string"); |
|
|
128 |
|
|
129 |
|
|
130 // Check 5 (boundary condition) |
|
|
131 my_strcpy(x, "So, if she weighs the same as a duck, she's made of wood!"); |
|
|
132 my_strcpy(y, "zx"); |
|
|
133 ret = strspn(x, y); |
|
|
134 CYG_TEST_PASS_FAIL( (ret == 0), "No characters in string" ); |
|
|
135 |
|
|
136 // Check 6 (boundary condition) |
|
|
137 my_strcpy(x, ""); |
|
|
138 my_strcpy(y, "qwerty"); |
|
|
139 ret = strspn(x, y); |
|
|
140 CYG_TEST_PASS_FAIL( (ret == 0), "Empty search string" ); |
|
|
141 |
|
|
142 |
|
|
143 #else // ifndef CYGPKG_LIBC |
|
2
|
144 CYG_TEST_NA("Testing is not applicable to this configuration"); |
|
0
|
145 #endif // ifndef CYGPKG_LIBC |
|
|
146 |
|
|
147 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " |
|
|
148 "strspn() function"); |
|
|
149 } // main() |
|
|
150 |
|
|
151 // EOF strspn.c |