Debian Codegraph @

ext/safestringlib/unittests/Safe_String_UnitTestMain.c

raw
1 /*
2 ============================================================================
3 Name : Safe_String_Extensions.c
4 Author : David M. Wheeler
5 Version :
6 Copyright : (C) Intel Corp 2014
7 Description : Safe String Test Suite
8 ============================================================================
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <safe_lib.h>
14 #include <snprintf_s.h>
15
16 extern int test_memcmp_s();
17 extern int test_memcmp16_s();
18 extern int test_memcmp32_s();
19 extern int test_memcpy_s();
20 extern int test_memcpy16_s();
21 extern int test_memcpy32_s();
22 extern int test_memmove_s();
23 extern int test_memmove16_s();
24 extern int test_memmove32_s();
25 extern int test_memset_s();
26 extern int test_memset16_s();
27 extern int test_memset32_s();
28 extern int test_memzero_s();
29 extern int test_memzero16_s();
30 extern int test_memzero32_s();
31 extern int test_strcasecmp_s();
32 extern int test_strcasestr_s();
33 extern int test_strcat_s();
34 extern int test_strcmp_s();
35 extern int test_strcmpfld_s();
36 extern int test_strcpy_s();
37 extern int test_strcpyfld_s();
38 extern int test_strcpyfldin_s();
39 extern int test_strcpyfldout_s();
40 extern int test_strcspn_s ();
41 extern int test_strfirstchar_s();
42 extern int test_strfirstdiff_s();
43 extern int test_strfirstsame_s();
44 extern int test_strisalphanumeric_s();
45 extern int test_strisascii_s();
46 extern int test_strisdigit_s();
47 extern int test_strishex_s();
48 extern int test_strislowercase_s();
49 extern int test_strismixed_s();
50 extern int test_strispassword_s();
51 extern int test_strisuppercase_s();
52 extern int test_strlastchar_s();
53 extern int test_strlastdiff_s();
54 extern int test_strlastsame_s();
55 extern int test_strljustify_s();
56 extern int test_strncat_s ();
57 extern int test_strncpy_s ();
58 extern int test_strnlen_s ();
59 extern int test_strnterminate_s();
60 extern int test_strpbrk_s ();
61 extern int test_strprefix_s();
62 extern int test_strremovews_s();
63 extern int test_strspn_s ();
64 extern int test_strstr_s ();
65 extern int test_strtok_s();
66 extern int test_strtolowercase_s();
67 extern int test_strtouppercase_s();
68 extern int test_strzero_s();
69 extern int test_stpncpy_s();
70 extern int test_stpcpy_s();
71 extern int test_wcpcpy_s();
72 extern int test_wcscat_s();
73 extern int test_wcscpy_s();
74 extern int test_wcsncat_s();
75 extern int test_wcsncpy_s (void);
76 extern int test_wcsnlen_s (void);
77 extern int test_wmemcpy_s(void);
78 extern int test_wmemmove_s(void);
79 extern int test_wmemset_s(void);
80 extern int test_wmemcmp_s(void);
81
82 int main(void) {
83
84 char dest[128];
85 char src[128];
86 rsize_t dmax = 128;
87 rsize_t smax = 21;
88 errno_t err;
89
90 puts("!!!Basic Test Suite for Safe String Operations!!!");
91 puts(" ERRORS PRINT TO CONSOLE");
92 puts("----------------BEGIN TEST--------------------");
93 test_memcmp_s();
94 test_memcmp16_s();
95 test_memcmp32_s();
96 test_memcpy_s();
97 test_memcpy16_s();
98 test_memcpy32_s();
99 test_memmove_s();
100 test_memmove16_s();
101 test_memmove32_s();
102 test_memset_s();
103 test_memset16_s();
104 test_memset32_s();
105 test_memzero_s();
106 test_memzero16_s();
107 test_memzero32_s();
108
109
110 test_stpcpy_s(); /* New - Done */
111 test_stpncpy_s(); /* New - Done */
112
113 test_strcasecmp_s();
114 test_strcasestr_s();
115 test_strcat_s();
116 test_strcmp_s();
117 test_strcmpfld_s();
118 test_strcpy_s();
119 test_strcpyfld_s();
120 test_strcpyfldin_s();
121 test_strcpyfldout_s();
122 test_strcspn_s ();
123
124 test_strfirstchar_s();
125 test_strfirstdiff_s();
126 test_strfirstsame_s();
127 test_strisalphanumeric_s();
128 test_strisascii_s();
129 test_strisdigit_s();
130 test_strishex_s();
131 test_strislowercase_s();
132 test_strismixed_s();
133 test_strispassword_s();
134 test_strisuppercase_s();
135
136 test_strlastchar_s();
137 test_strlastdiff_s();
138 test_strlastsame_s();
139 test_strljustify_s();
140
141 test_strncat_s ();
142 test_strncpy_s ();
143 test_strnlen_s ();
144 test_strnterminate_s();
145 test_strpbrk_s ();
146 test_strprefix_s();
147 test_strremovews_s();
148 test_strspn_s ();
149 test_strstr_s ();
150 test_strtok_s();
151 test_strtolowercase_s();
152 test_strtouppercase_s();
153 test_strzero_s();
154
155 test_wcpcpy_s(); /* New - Done */
156 test_wcscat_s(); /* New - Done */
157 test_wcscpy_s(); /* New - Done */
158 test_wcsncat_s(); /* New - Done */
159 test_wcsncpy_s(); /* New - Done */
160 test_wcsnlen_s(); /* New - Done */
161 test_wmemcpy_s(); /* New - Done */
162 test_wmemmove_s(); /* New - Done */
163 test_wmemset_s(); /* New - Done */
164 test_wmemcmp_s(); /* New - Done */
165
166 char str[] = "This is a char array";
167 char str2[] = "...And another one.";
168 int indicator = -1;
169
170 strcpy_s(dest, dmax, str);
171 char *ret = stpcpy_s(&dest[20], 108, str2, &err);
172 if (err != EOK) {
173 puts("stpcpy_s returned failure");
174 }
175
176 int val = 55;
177 if ( (err = snprintf_s_si(src, 128, "Test sprintf_s_si() with simple format string [%s] and %d", dest, val)) < 0 ) {
178 if ( SNPRFNEGATE(ESBADFMT) == err ) {
179 puts("snprintf_s_si returned failure: Error Bad Format String.");
180 } else if ( SNPRFNEGATE(ESFMTTYP) == err ) {
181 puts("snprintf_s_si returned failure: Error Bad Argument Type for format string.");
182 } else {
183 printf("snprintf_s_si failed with unknown error: %d\n", err);
184 }
185 } else if ((strcmp_s(src, smax, "Test sprintf_s_si() with simple format string [This is a char array...And another one.] and 55", &indicator) != EOK ) || (indicator != 0 )) {
186 puts("snprintf_s_si() failed - output was:");
187 puts(src);
188 }
189 puts("----------------END TEST--------------------");
190 return EXIT_SUCCESS;
191 }
192