VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstNoCrt-1.cpp@ 107044

Last change on this file since 107044 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 19.8 KB
Line 
1/* $Id: tstNoCrt-1.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Testcase for the No-CRT assembly bits.
4 */
5
6/*
7 * Copyright (C) 2008-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/nocrt/string.h>
42#include <iprt/stream.h>
43#include <iprt/initterm.h>
44#include <iprt/string.h>
45#ifdef RT_WITHOUT_NOCRT_WRAPPERS
46# error "Build error."
47#endif
48
49
50/*********************************************************************************************************************************
51* Structures and Typedefs *
52*********************************************************************************************************************************/
53#define TSTBUF_SIZE 8192
54typedef struct TSTBUF
55{
56 uint8_t abHeadFence[2048];
57 uint8_t abBuf[TSTBUF_SIZE];
58 uint8_t abTailFence[2048];
59} TSTBUF, *PTSTBUF;
60
61
62/*********************************************************************************************************************************
63* Global Variables *
64*********************************************************************************************************************************/
65static unsigned g_cErrors = 0;
66
67
68static void my_memset(void *pv, int ch, size_t cb)
69{
70 uint8_t *pb = (uint8_t *)pv;
71 while (cb--)
72 *pb++ = ch;
73}
74
75static void my_memcheck(const void *pv, int ch, size_t cb, const char *pszDesc)
76{
77 uint8_t *pb = (uint8_t *)pv;
78 while (cb--)
79 {
80 if (*pb != (uint8_t)ch)
81 {
82 g_cErrors++;
83 size_t off;
84 for (off = 1; off < cb && pb[off] != (uint8_t)ch; off++)
85 /* nandemonai */;
86 off--;
87 pb += off;
88 cb -= off;
89 if (off)
90 RTPrintf("tstNoCrt-1: %s: %p:%p - %02x instead of %02x\n",
91 pszDesc, (uintptr_t)pb - (uintptr_t)pv,
92 (uint8_t *)pb - (uint8_t *)pv + off, *pb, (uint8_t)ch);
93 else
94 RTPrintf("tstNoCrt-1: %s: %p - %02x instead of %02x\n",
95 pszDesc, (uint8_t *)pb - (uint8_t *)pv, *pb, (uint8_t)ch);
96 }
97
98 /* next*/
99 pb++;
100 }
101}
102
103
104static void TstBufInit(PTSTBUF pBuf, int ch)
105{
106 my_memset(pBuf->abHeadFence, 0x55, sizeof(pBuf->abHeadFence));
107 my_memset(pBuf->abBuf, ch, sizeof(pBuf->abBuf));
108 my_memset(pBuf->abTailFence, 0x77, sizeof(pBuf->abHeadFence));
109}
110
111
112static void TstBufCheck(PTSTBUF pBuf, const char *pszDesc)
113{
114 my_memcheck(pBuf->abHeadFence, 0x55, sizeof(pBuf->abHeadFence), pszDesc);
115 my_memcheck(pBuf->abTailFence, 0x77, sizeof(pBuf->abTailFence), pszDesc);
116}
117
118
119#if 0 /* enable this to test the testcase. */
120# undef RT_NOCRT
121# define RT_NOCRT(a) a
122# ifdef _MSC_VER
123# define mempcpy nocrt_mempcpy
124# endif
125#endif
126
127int main()
128{
129 /*
130 * Prologue.
131 */
132 RTR3InitExeNoArguments(0);
133 RTPrintf("tstNoCrt-1: TESTING...\n");
134
135 /*
136 * Sanity.
137 */
138 TSTBUF Buf1;
139 TstBufInit(&Buf1, 1);
140 my_memcheck(Buf1.abBuf, 1, TSTBUF_SIZE, "sanity buf1");
141 TstBufCheck(&Buf1, "sanity buf1");
142
143 TSTBUF Buf2;
144 TstBufInit(&Buf2, 2);
145 my_memcheck(Buf2.abBuf, 2, TSTBUF_SIZE, "sanity buf2");
146 TstBufCheck(&Buf2, "sanity buf2");
147 if (g_cErrors)
148 {
149 RTPrintf("tstNoCrt-1: FAILED - fatal sanity error\n");
150 return 1;
151 }
152
153#define CHECK_CCH(expect) \
154 do \
155 { \
156 if (cch != (expect)) \
157 { \
158 RTPrintf("tstNoCrt-1(%d): cb=%zu expected=%zu\n", __LINE__, cch, (expect)); \
159 g_cErrors++; \
160 } \
161 } while (0)
162 size_t cch;
163
164#define CHECK_PV(expect) \
165 do \
166 { \
167 if (pv != (expect)) \
168 { \
169 RTPrintf("tstNoCrt-1(%d): pv=%p expected=%p\n", __LINE__, pv, (expect)); \
170 g_cErrors++; \
171 } \
172 } while (0)
173 void *pv;
174
175#define CHECK_DIFF(op) \
176 do \
177 { \
178 if (!(iDiff op 0)) \
179 { \
180 RTPrintf("tstNoCrt-1(%d): iDiff=%d expected: %s 0\n", __LINE__, iDiff, #op); \
181 g_cErrors++; \
182 } \
183 } while (0)
184 int iDiff;
185
186 static char s_szTest1[] = "0123456789abcdef";
187 static char s_szTest2[] = "0123456789abcdef";
188 static char s_szTest3[] = "fedcba9876543210";
189
190 /*
191 * memcpy.
192 */
193 RTPrintf("tstNoCrt-1: memcpy\n");
194 TstBufInit(&Buf1, 1);
195 TstBufInit(&Buf2, 2);
196 pv = RT_NOCRT(memcpy)(Buf1.abBuf, Buf2.abBuf, TSTBUF_SIZE); CHECK_PV(Buf1.abBuf);
197 my_memcheck(Buf1.abBuf, 2, TSTBUF_SIZE, "memcpy1-dst");
198 my_memcheck(Buf2.abBuf, 2, TSTBUF_SIZE, "memcpy1-src");
199 TstBufCheck(&Buf1, "memcpy1");
200 TstBufCheck(&Buf2, "memcpy1");
201
202 TstBufInit(&Buf1, 3);
203 TstBufInit(&Buf2, 4);
204 pv = RT_NOCRT(memcpy)(Buf2.abBuf, Buf1.abBuf, TSTBUF_SIZE); CHECK_PV(Buf2.abBuf);
205 my_memcheck(Buf1.abBuf, 3, TSTBUF_SIZE, "memcpy2-dst");
206 my_memcheck(Buf2.abBuf, 3, TSTBUF_SIZE, "memcpy2-src");
207 TstBufCheck(&Buf1, "memcpy2");
208 TstBufCheck(&Buf2, "memcpy2");
209
210 TstBufInit(&Buf1, 5);
211 TstBufInit(&Buf2, 6);
212 pv = RT_NOCRT(memcpy)(Buf2.abBuf, Buf1.abBuf, 0); CHECK_PV(Buf2.abBuf);
213 my_memcheck(Buf1.abBuf, 5, TSTBUF_SIZE, "memcpy3-dst");
214 my_memcheck(Buf2.abBuf, 6, TSTBUF_SIZE, "memcpy3-src");
215 TstBufCheck(&Buf1, "memcpy3-dst");
216 TstBufCheck(&Buf2, "memcpy3-src");
217
218 for (unsigned off1 = 0; off1 <= 128; off1++)
219 {
220 for (unsigned off2 = 0; off2 <= 256; off2++)
221 {
222 char sz[32];
223 RTStrPrintf(sz, sizeof(sz), "memcpy4-%d-%d", off1, off2);
224 TstBufInit(&Buf1, 1);
225 TstBufInit(&Buf2, 2);
226 size_t cb = off2;
227 pv = RT_NOCRT(memcpy)(&Buf2.abBuf[off2], &Buf1.abBuf[off1], cb); CHECK_PV(&Buf2.abBuf[off2]);
228 my_memcheck(Buf1.abBuf, 1, TSTBUF_SIZE, sz);
229 my_memcheck(Buf2.abBuf, 2, off2, sz);
230 my_memcheck(&Buf2.abBuf[off2], 1, cb, sz);
231 my_memcheck(&Buf2.abBuf[off2 + cb], 2, TSTBUF_SIZE - cb - off2, sz);
232 TstBufCheck(&Buf1, sz);
233 TstBufCheck(&Buf2, sz);
234 }
235 }
236
237 /*
238 * mempcpy.
239 */
240 RTPrintf("tstNoCrt-1: mempcpy\n");
241 TstBufInit(&Buf1, 1);
242 TstBufInit(&Buf2, 2);
243 pv = RT_NOCRT(mempcpy)(Buf1.abBuf, Buf2.abBuf, TSTBUF_SIZE); CHECK_PV(&Buf1.abBuf[TSTBUF_SIZE]);
244 my_memcheck(Buf1.abBuf, 2, TSTBUF_SIZE, "mempcpy1-dst");
245 my_memcheck(Buf2.abBuf, 2, TSTBUF_SIZE, "mempcpy1-src");
246 TstBufCheck(&Buf1, "mempcpy1");
247 TstBufCheck(&Buf2, "mempcpy1");
248
249 TstBufInit(&Buf1, 3);
250 TstBufInit(&Buf2, 4);
251 pv = RT_NOCRT(mempcpy)(Buf2.abBuf, Buf1.abBuf, TSTBUF_SIZE); CHECK_PV(&Buf2.abBuf[TSTBUF_SIZE]);
252 my_memcheck(Buf1.abBuf, 3, TSTBUF_SIZE, "mempcpy2-dst");
253 my_memcheck(Buf2.abBuf, 3, TSTBUF_SIZE, "mempcpy2-src");
254 TstBufCheck(&Buf1, "mempcpy2");
255 TstBufCheck(&Buf2, "mempcpy2");
256
257 TstBufInit(&Buf1, 5);
258 TstBufInit(&Buf2, 6);
259 pv = RT_NOCRT(mempcpy)(Buf2.abBuf, Buf1.abBuf, 0); CHECK_PV(Buf2.abBuf);
260 my_memcheck(Buf1.abBuf, 5, TSTBUF_SIZE, "mempcpy3-dst");
261 my_memcheck(Buf2.abBuf, 6, TSTBUF_SIZE, "mempcpy3-src");
262 TstBufCheck(&Buf1, "mempcpy3-dst");
263 TstBufCheck(&Buf2, "mempcpy3-src");
264
265 for (unsigned off1 = 0; off1 <= 128; off1++)
266 {
267 for (unsigned off2 = 0; off2 <= 256; off2++)
268 {
269 char sz[32];
270 RTStrPrintf(sz, sizeof(sz), "mempcpy4-%d-%d", off1, off2);
271 TstBufInit(&Buf1, 1);
272 TstBufInit(&Buf2, 2);
273 size_t cb = off2;
274 pv = RT_NOCRT(mempcpy)(&Buf2.abBuf[off2], &Buf1.abBuf[off1], cb); CHECK_PV(&Buf2.abBuf[off2 + cb]);
275 my_memcheck(Buf1.abBuf, 1, TSTBUF_SIZE, sz);
276 my_memcheck(Buf2.abBuf, 2, off2, sz);
277 my_memcheck(&Buf2.abBuf[off2], 1, cb, sz);
278 my_memcheck(&Buf2.abBuf[off2 + cb], 2, TSTBUF_SIZE - cb - off2, sz);
279 TstBufCheck(&Buf1, sz);
280 TstBufCheck(&Buf2, sz);
281 }
282 }
283
284 /*
285 * memmove.
286 */
287 RTPrintf("tstNoCrt-1: memmove\n");
288 TstBufInit(&Buf1, 1);
289 TstBufInit(&Buf2, 2);
290 pv = RT_NOCRT(memmove)(Buf1.abBuf, Buf2.abBuf, TSTBUF_SIZE); CHECK_PV(Buf1.abBuf);
291 my_memcheck(Buf1.abBuf, 2, TSTBUF_SIZE, "memmove1-dst");
292 my_memcheck(Buf2.abBuf, 2, TSTBUF_SIZE, "memmove1-src");
293 TstBufCheck(&Buf1, "memmove1");
294 TstBufCheck(&Buf2, "memmove1");
295
296 TstBufInit(&Buf1, 3);
297 TstBufInit(&Buf2, 4);
298 pv = RT_NOCRT(memmove)(Buf2.abBuf, Buf1.abBuf, TSTBUF_SIZE); CHECK_PV(Buf2.abBuf);
299 my_memcheck(Buf1.abBuf, 3, TSTBUF_SIZE, "memmove2-dst");
300 my_memcheck(Buf2.abBuf, 3, TSTBUF_SIZE, "memmove2-src");
301 TstBufCheck(&Buf1, "memmove2");
302 TstBufCheck(&Buf2, "memmove2");
303
304 TstBufInit(&Buf1, 5);
305 TstBufInit(&Buf2, 6);
306 pv = RT_NOCRT(memmove)(Buf2.abBuf, Buf1.abBuf, 0); CHECK_PV(Buf2.abBuf);
307 my_memcheck(Buf1.abBuf, 5, TSTBUF_SIZE, "memmove3-dst");
308 my_memcheck(Buf2.abBuf, 6, TSTBUF_SIZE, "memmove3-src");
309 TstBufCheck(&Buf1, "memmove3-dst");
310 TstBufCheck(&Buf2, "memmove3-src");
311
312 for (unsigned off1 = 1; off1 <= 128; off1++)
313 {
314 for (unsigned off2 = 0; off2 <= 256; off2++)
315 {
316 /* forward */
317 char sz[32];
318 RTStrPrintf(sz, sizeof(sz), "memmove4-%d-%d", off1, off2);
319 TstBufInit(&Buf1, off1 + 1);
320 my_memset(Buf1.abBuf, off1, off1);
321 pv = RT_NOCRT(memmove)(Buf1.abBuf, &Buf1.abBuf[off2], TSTBUF_SIZE - off2); CHECK_PV(Buf1.abBuf);
322 if (off2 < off1)
323 {
324 unsigned cbLead = off1 - off2;
325 my_memcheck(Buf1.abBuf, off1, cbLead, sz);
326 my_memcheck(&Buf1.abBuf[cbLead], off1 + 1, TSTBUF_SIZE - cbLead, sz);
327 }
328 else
329 my_memcheck(Buf1.abBuf, off1 + 1, TSTBUF_SIZE, sz);
330 TstBufCheck(&Buf1, sz);
331
332 /* backward */
333 RTStrPrintf(sz, sizeof(sz), "memmove5-%d-%d", off1, off2);
334 TstBufInit(&Buf1, off1 + 1);
335 my_memset(&Buf1.abBuf[TSTBUF_SIZE - off1], off1, off1);
336 pv = RT_NOCRT(memmove)(&Buf1.abBuf[off2], Buf1.abBuf, TSTBUF_SIZE - off2); CHECK_PV(&Buf1.abBuf[off2]);
337 if (off2 < off1)
338 {
339 unsigned cbLead = off1 - off2;
340 my_memcheck(&Buf1.abBuf[TSTBUF_SIZE - cbLead], off1, cbLead, sz);
341 my_memcheck(Buf1.abBuf, off1 + 1, TSTBUF_SIZE - cbLead, sz);
342 }
343 else
344 my_memcheck(Buf1.abBuf, off1 + 1, TSTBUF_SIZE, sz);
345 TstBufCheck(&Buf1, sz);
346 /* small unaligned */
347 RTStrPrintf(sz, sizeof(sz), "memmove6-%d-%d", off1, off2);
348 TstBufInit(&Buf1, 1);
349 TstBufInit(&Buf2, 2);
350 size_t cb = off2;
351 pv = RT_NOCRT(memmove)(&Buf2.abBuf[off2], &Buf1.abBuf[off1], cb); CHECK_PV(&Buf2.abBuf[off2]);
352 my_memcheck(Buf1.abBuf, 1, TSTBUF_SIZE, sz);
353 my_memcheck(Buf2.abBuf, 2, off2, sz);
354 my_memcheck(&Buf2.abBuf[off2], 1, cb, sz);
355 my_memcheck(&Buf2.abBuf[off2 + cb], 2, TSTBUF_SIZE - cb - off2, sz);
356 TstBufCheck(&Buf1, sz);
357 TstBufCheck(&Buf2, sz);
358 }
359 }
360
361 /*
362 * memset
363 */
364 RTPrintf("tstNoCrt-1: memset\n");
365 TstBufInit(&Buf1, 1);
366 pv = RT_NOCRT(memset)(Buf1.abBuf, 0, TSTBUF_SIZE); CHECK_PV(Buf1.abBuf);
367 my_memcheck(Buf1.abBuf, 0, TSTBUF_SIZE, "memset-1");
368 TstBufCheck(&Buf1, "memset-1");
369
370 TstBufInit(&Buf1, 1);
371 pv = RT_NOCRT(memset)(Buf1.abBuf, 0xff, TSTBUF_SIZE); CHECK_PV(Buf1.abBuf);
372 my_memcheck(Buf1.abBuf, 0xff, TSTBUF_SIZE, "memset-2");
373 TstBufCheck(&Buf1, "memset-2");
374
375 TstBufInit(&Buf1, 1);
376 pv = RT_NOCRT(memset)(Buf1.abBuf, 0xff, 0); CHECK_PV(Buf1.abBuf);
377 my_memcheck(Buf1.abBuf, 1, TSTBUF_SIZE, "memset-3");
378 TstBufCheck(&Buf1, "memset-3");
379
380 for (unsigned off = 0; off < 256; off++)
381 {
382 /* move start byte by byte. */
383 char sz[32];
384 RTStrPrintf(sz, sizeof(sz), "memset4-%d", off);
385 TstBufInit(&Buf1, 0);
386 pv = RT_NOCRT(memset)(&Buf1.abBuf[off], off, TSTBUF_SIZE - off); CHECK_PV(&Buf1.abBuf[off]);
387 my_memcheck(Buf1.abBuf, 0, off, sz);
388 my_memcheck(&Buf1.abBuf[off], off, TSTBUF_SIZE - off, sz);
389 TstBufCheck(&Buf1, sz);
390
391 /* move end byte by byte. */
392 RTStrPrintf(sz, sizeof(sz), "memset5-%d", off);
393 TstBufInit(&Buf1, 0);
394 pv = RT_NOCRT(memset)(Buf1.abBuf, off, TSTBUF_SIZE - off); CHECK_PV(Buf1.abBuf);
395 my_memcheck(Buf1.abBuf, off, TSTBUF_SIZE - off, sz);
396 my_memcheck(&Buf1.abBuf[TSTBUF_SIZE - off], 0, off, sz);
397 TstBufCheck(&Buf1, sz);
398
399 /* move both start and size byte by byte. */
400 RTStrPrintf(sz, sizeof(sz), "memset6-%d", off);
401 TstBufInit(&Buf1, 0);
402 pv = RT_NOCRT(memset)(&Buf1.abBuf[off], off, off); CHECK_PV(&Buf1.abBuf[off]);
403 my_memcheck(Buf1.abBuf, 0, off, sz);
404 my_memcheck(&Buf1.abBuf[off], off, off, sz);
405 my_memcheck(&Buf1.abBuf[off * 2], 0, TSTBUF_SIZE - off * 2, sz);
406 TstBufCheck(&Buf1, sz);
407 }
408
409 /*
410 * strcpy (quick smoke testing).
411 */
412 RTPrintf("tstNoCrt-1: strcpy\n");
413 TstBufInit(&Buf1, 1);
414 const char *pszSrc = s_szTest1;
415 char *pszDst = (char *)&Buf1.abBuf[0];
416 pv = RT_NOCRT(strcpy)(pszDst, pszSrc);
417 CHECK_PV(pszDst);
418 TstBufCheck(&Buf1, "strcpy 1");
419 iDiff = RT_NOCRT(strcmp)(pszDst, pszSrc); CHECK_DIFF( == );
420
421 pszSrc = s_szTest1;
422 for (unsigned i = 0; i < sizeof(s_szTest1) / 2; i++)
423 {
424 pszSrc++;
425 TstBufInit(&Buf1, 2);
426 pszDst = (char *)&Buf1.abBuf[sizeof(Buf1.abBuf) - strlen(pszSrc) - 1];
427 pv = RT_NOCRT(strcpy)(pszDst, pszSrc);
428 CHECK_PV(pszDst);
429 TstBufCheck(&Buf1, "strcpy 3");
430 iDiff = RT_NOCRT(strcmp)(pszDst, pszSrc); CHECK_DIFF( == );
431 }
432
433
434 /*
435 * memchr & strchr.
436 */
437 RTPrintf("tstNoCrt-1: memchr\n");
438 pv = RT_NOCRT(memchr)(&s_szTest1[0x00], 'f', sizeof(s_szTest1)); CHECK_PV(&s_szTest1[0xf]);
439 pv = RT_NOCRT(memchr)(&s_szTest1[0x0f], 'f', sizeof(s_szTest1)); CHECK_PV(&s_szTest1[0xf]);
440 pv = RT_NOCRT(memchr)(&s_szTest1[0x03], 0, sizeof(s_szTest1)); CHECK_PV(&s_szTest1[0x10]);
441 pv = RT_NOCRT(memchr)(&s_szTest1[0x10], 0, sizeof(s_szTest1)); CHECK_PV(&s_szTest1[0x10]);
442 pv = RT_NOCRT(memchr)(&s_szTest1, 0, ~(size_t)0); CHECK_PV(&s_szTest1[0x10]);
443 pv = RT_NOCRT(memchr)(&s_szTest1, 0, ~(size_t)1); CHECK_PV(&s_szTest1[0x10]);
444 pv = RT_NOCRT(memchr)(&s_szTest1, 0, ~(size_t)16); CHECK_PV(&s_szTest1[0x10]);
445 for (unsigned i = 0; i < sizeof(s_szTest1); i++)
446 for (unsigned j = 0; j <= i; j++)
447 {
448 pv = RT_NOCRT(memchr)(&s_szTest1[j], s_szTest1[i], sizeof(s_szTest1));
449 CHECK_PV(&s_szTest1[i]);
450 }
451
452 RTPrintf("tstNoCrt-1: strchr\n");
453 pv = RT_NOCRT(strchr)(&s_szTest1[0x00], 'f'); CHECK_PV(&s_szTest1[0xf]);
454 pv = RT_NOCRT(strchr)(&s_szTest1[0x0f], 'f'); CHECK_PV(&s_szTest1[0xf]);
455 pv = RT_NOCRT(strchr)(&s_szTest1[0x03], 0); CHECK_PV(&s_szTest1[0x10]);
456 pv = RT_NOCRT(strchr)(&s_szTest1[0x10], 0); CHECK_PV(&s_szTest1[0x10]);
457 for (unsigned i = 0; i < sizeof(s_szTest1); i++)
458 for (unsigned j = 0; j <= i; j++)
459 {
460 pv = RT_NOCRT(strchr)(&s_szTest1[j], s_szTest1[i]);
461 CHECK_PV(&s_szTest1[i]);
462 }
463
464 /*
465 * Some simple memcmp/strcmp checks.
466 */
467 RTPrintf("tstNoCrt-1: memcmp\n");
468 iDiff = RT_NOCRT(memcmp)(s_szTest1, s_szTest1, sizeof(s_szTest1)); CHECK_DIFF( == );
469 iDiff = RT_NOCRT(memcmp)(s_szTest1, s_szTest2, sizeof(s_szTest1)); CHECK_DIFF( == );
470 iDiff = RT_NOCRT(memcmp)(s_szTest2, s_szTest1, sizeof(s_szTest1)); CHECK_DIFF( == );
471 iDiff = RT_NOCRT(memcmp)(s_szTest3, s_szTest3, sizeof(s_szTest1)); CHECK_DIFF( == );
472 iDiff = RT_NOCRT(memcmp)(s_szTest1, s_szTest3, sizeof(s_szTest1)); CHECK_DIFF( < );
473 iDiff = RT_NOCRT(memcmp)(s_szTest3, s_szTest1, sizeof(s_szTest1)); CHECK_DIFF( > );
474 iDiff = RT_NOCRT(memcmp)("1234", "1a34", 4); CHECK_DIFF( < );
475
476 RTPrintf("tstNoCrt-1: strcmp\n");
477 iDiff = RT_NOCRT(strcmp)(s_szTest1, s_szTest1); CHECK_DIFF( == );
478 iDiff = RT_NOCRT(strcmp)(s_szTest1, s_szTest2); CHECK_DIFF( == );
479 iDiff = RT_NOCRT(strcmp)(s_szTest2, s_szTest1); CHECK_DIFF( == );
480 iDiff = RT_NOCRT(strcmp)(s_szTest3, s_szTest3); CHECK_DIFF( == );
481 iDiff = RT_NOCRT(strcmp)(s_szTest1, s_szTest3); CHECK_DIFF( < );
482 iDiff = RT_NOCRT(strcmp)(s_szTest3, s_szTest1); CHECK_DIFF( > );
483
484 /*
485 * Some simple strlen checks.
486 */
487 RTPrintf("tstNoCrt-1: strlen\n");
488 cch = RT_NOCRT(strlen)(""); CHECK_CCH(0);
489 cch = RT_NOCRT(strlen)("1"); CHECK_CCH(1);
490 cch = RT_NOCRT(strlen)("12"); CHECK_CCH(2);
491 cch = RT_NOCRT(strlen)("123"); CHECK_CCH(3);
492 cch = RT_NOCRT(strlen)("1234"); CHECK_CCH(4);
493 cch = RT_NOCRT(strlen)("12345"); CHECK_CCH(5);
494 cch = RT_NOCRT(strlen)(s_szTest1); CHECK_CCH(sizeof(s_szTest1) - 1);
495 cch = RT_NOCRT(strlen)(&s_szTest1[1]); CHECK_CCH(sizeof(s_szTest1) - 1 - 1);
496 cch = RT_NOCRT(strlen)(&s_szTest1[2]); CHECK_CCH(sizeof(s_szTest1) - 1 - 2);
497 cch = RT_NOCRT(strlen)(&s_szTest1[3]); CHECK_CCH(sizeof(s_szTest1) - 1 - 3);
498 cch = RT_NOCRT(strlen)(&s_szTest1[4]); CHECK_CCH(sizeof(s_szTest1) - 1 - 4);
499 cch = RT_NOCRT(strlen)(&s_szTest1[5]); CHECK_CCH(sizeof(s_szTest1) - 1 - 5);
500 cch = RT_NOCRT(strlen)(&s_szTest1[6]); CHECK_CCH(sizeof(s_szTest1) - 1 - 6);
501 cch = RT_NOCRT(strlen)(&s_szTest1[7]); CHECK_CCH(sizeof(s_szTest1) - 1 - 7);
502 cch = RT_NOCRT(strlen)(s_szTest2); CHECK_CCH(sizeof(s_szTest2) - 1);
503 cch = RT_NOCRT(strlen)(s_szTest3); CHECK_CCH(sizeof(s_szTest3) - 1);
504
505#ifdef _MSC_VER
506 /*
507 * Some simple wcslen checks.
508 */
509 RTPrintf("tstNoCrt-1: wcslen\n");
510 cch = RT_NOCRT(wcslen)(L""); CHECK_CCH(0);
511 cch = RT_NOCRT(wcslen)(L"1"); CHECK_CCH(1);
512 cch = RT_NOCRT(wcslen)(L"12"); CHECK_CCH(2);
513 cch = RT_NOCRT(wcslen)(L"123"); CHECK_CCH(3);
514 cch = RT_NOCRT(wcslen)(L"1234"); CHECK_CCH(4);
515 cch = RT_NOCRT(wcslen)(L"12345"); CHECK_CCH(5);
516#endif
517
518 /*
519 * Summary.
520 */
521 if (!g_cErrors)
522 RTPrintf("tstNoCrt-1: SUCCESS\n");
523 else
524 RTPrintf("tstNoCrt-1: FAILURE - %d errors\n", g_cErrors);
525 return !!g_cErrors;
526}
527
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette