ReactOS 0.4.15-dev-6712-g46b4b55
crtdata.c
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS CRT API tests
3* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4* PURPOSE: Tests for crt data exports
5* COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6*/
7
8#include <apitest.h>
9#include <apitest_guard.h>
10
11#define WIN32_NO_STATUS
12#include <stdio.h>
13#include <stdlib.h>
14#include <time.h>
15#include <locale.h>
16#include <mbctype.h>
17
19extern char __ImageBase;
20static void* s_ImageEnd;
21
23{
24 return ((Address >= (void*)&__ImageBase) && (Address <= s_ImageEnd));
25}
26
27#ifndef TEST_STATIC
28#define test_is_local_symbol(addr, is) ok_int(IsLocalSymbol(addr), (is))
29#else
30#define test_is_local_symbol(addr, is)
31#endif
32
33void Test___argc(void)
34{
35 void* p = &__argc;
37
38 #undef __argc
39 ok_ptr(&__argc, p);
40#ifdef _M_IX86
42#endif
43}
44
45void Test___argv(void)
46{
47 void* p = &__argv;
49
50 #undef __argv
51 ok_ptr(&__argv, p);
52#ifdef _M_IX86
54#endif
55}
56
58{
59 typedef struct _ioinfo ioinfo;
60 _CRTIMP extern ioinfo* __badioinfo[];
61 ok(__badioinfo != NULL, "__badioinfo is NULL\n");
62 ok(__badioinfo[0] != NULL, "__badioinfo is NULL\n");
63}
64
65#ifndef _M_ARM
67{
68 _CRTIMP extern char** __initenv;
69 ok(__initenv != NULL, "__initenv is NULL\n");
70 ok(*__initenv != NULL, "*__initenv is NULL\n");
71#ifdef _M_IX86
72 _CRTIMP char*** __p___initenv(void);
74#endif
75}
76
78{
79 _CRTIMP extern unsigned int __lc_codepage;
85}
86
88{
89 _CRTIMP extern int __lc_collate_cp;
96}
97#endif // !_M_ARM
98
100{
101 _CRTIMP int __lc_handle;
102 ok_int(__lc_handle, 0);
105 __lc_handle++;
107 __lc_handle--;
108}
109
111{
112 void* p = &__mb_cur_max;
115
116 #undef __mb_cur_max
117 _CRTIMP extern int __mb_cur_max;
119
121#ifdef _M_IX86
122 _CRTIMP int* __p___mb_cur_max(void);
124#endif
125 __mb_cur_max++;
126 if (s_osvi.dwMajorVersion >= 6)
127 {
129#ifdef _M_IX86
131#endif
132 }
133 else
134 {
136#ifdef _M_IX86
137 todo_ros ok_ptr(__p___mb_cur_max(), p); // wine code handles it like on Vista+
139#endif
140 }
141
142 __mb_cur_max--;
143}
144
146{
147
148}
149
150#ifndef _M_ARM
152{
153 _CRTIMP extern unsigned int __setlc_active;
155
156 _CRTIMP unsigned int ___setlc_active_func(void);
161}
162
164{
165 _CRTIMP extern unsigned int __unguarded_readlc_active;
168
171}
172#endif // !_M_ARM
173
174void Test___wargv(void)
175{
176 void* p = &__wargv;
178
179 #undef __wargv
180 _CRTIMP extern wchar_t ** __wargv;
181 ok_ptr(&__wargv, p);
182#ifdef _M_IX86
183 ok_ptr(__p___wargv(), p);
184#endif
185}
186
187#ifndef _M_ARM
189{
190 _CRTIMP extern wchar_t** __winitenv;
191 todo_ros ok(__winitenv == NULL, "__winitenv is not NULL\n");
192#ifdef _M_IX86
193 _CRTIMP wchar_t*** __p___winitenv(void);
195#endif
196}
197#endif
198
199void Test__acmdln(void)
200{
201 _CRTIMP extern char* _acmdln;
202 ok(_acmdln != NULL, "__winitenv is NULL\n");
203#ifdef _M_IX86
204 _CRTIMP char** __p__acmdln(void);
206#endif
207}
208
209#ifdef _M_IX86
210void Test__adjust_fdiv(void)
211{
212 _CRTIMP extern int _adjust_fdiv;
214}
215#endif
216
218{
219 typedef void (*_exit_t)(int exitcode);
220 _CRTIMP extern _exit_t _aexit_rtn;
222}
223
225{
226 void* p = &_commode;
228 ok_int(_commode, 0);
229
230 #undef _commode
231 _CRTIMP extern int _commode;
232 ok_ptr(&_commode, p);
233#ifdef _M_IX86
235#endif
236}
237
238void Test__ctype(void)
239{
240 _CRTIMP extern const unsigned short _ctype[];
241 ok_int(_ctype[0], 0);
243
244 #undef _pctype
245 _CRTIMP extern const unsigned short* _pctype;
246 ok(_pctype != &_ctype[0], "_pwctype should not match &_wctype[0]");
247 if (s_osvi.dwMajorVersion >= 6)
248 {
249 ok(_pctype != &_ctype[1], "_pwctype should not match &_wctype[1]");
250 }
251 else
252 {
253 ok(_pctype == &_ctype[1], "_pwctype should match &_wctype[1]");
254 }
255
256 ok(__pctype_func() != _ctype, "__pctype_func() should not match _ctype\n");
259#ifdef _M_IX86
260 _CRTIMP const unsigned short** __cdecl __p__pctype(void);
262#endif
263}
264
265void Test__wctype(void)
266{
267 ok_int(_wctype[0], 0);
269
270 #undef _pwctype
271 _CRTIMP extern const unsigned short* _pwctype;
272 ok_ptr(_pwctype, &_wctype[1]);
273
274 ok(__pwctype_func() != _wctype, "__pwctype_func() == _wctype\n");
277#ifdef _M_IX86
278 _CRTIMP const unsigned short** __cdecl __p__pwctype(void);
280#endif
281}
282
284{
285 void* p = &_daylight;
287
288 #undef _daylight
289 _CRTIMP extern int _daylight;
290 ok_ptr(&_daylight, p);
291
292#ifdef _M_IX86
293 _CRTIMP void* __p__daylight(void);
295#endif
296#if (WINVER >= 0x600)
297 _CRTIMP int* __cdecl __daylight(void);
298 ok_ptr(&__daylight, &_daylight);
299#endif
300}
301
302#ifndef _M_ARM
304{
305 void* p = &_dstbias;
307
308 #undef _dstbias
309 _CRTIMP extern long _dstbias;
310 ok_ptr(&_dstbias, p);
311#ifdef _M_IX86
312 _CRTIMP long* __cdecl __p__dstbias(void);
314#endif
315#if (WINVER >= 0x600)
316 _CRTIMP long* __cdecl __dstbias(void);
317 ok_ptr(&__dstbias, &_dstbias);
318#endif
319}
320
322{
323 void* p = &_environ;
324 ok(_environ != NULL, "_environ == NULL\n");
325
326 #undef _environ
327 _CRTIMP extern char** _environ;
328 ok_ptr(&_environ, p);
329#ifdef _M_IX86
331#endif
332}
333
335{
336 _CRTIMP extern int _fileinfo;
337 ok_int(_fileinfo, -1);
338
339#ifdef _M_IX86
340 _CRTIMP int* __p__fileinfo();
342#endif
343}
344#endif // !_M_ARM
345
346void Test__fmode(void)
347{
348 void* p = &_fmode;
350 ok_int(_fmode, 0);
351
352 #undef _fmode
353 _CRTIMP extern int _fmode;
354 ok_ptr(&_fmode, p);
355
356#ifdef _M_IX86
358 ok_ptr(__p__fmode(), p);
359#endif
360
361#if (_WIN32_WINNT >= 0x600)
362 _fmode = 1234;
364 int mode;
365 ok_int(_get_fmode(&mode), 0);
367 _fmode = 0;
368#endif
369}
370
371void Test__iob(void)
372{
373 void* p = &_iob;
375 ok_ptr(&_iob[0], stdin);
376 ok_ptr(&_iob[1], stdout);
377 ok_ptr(&_iob[2], stderr);
378
379 #undef _iob
380 _CRTIMP extern FILE _iob[];
381 ok_ptr(&_iob, p);
382
384
385#ifdef _M_IX86
386 _CRTIMP int* __cdecl __p__iob();
387 ok_ptr(__p__iob(), p);
388#endif
389}
390
392{
393 void* p = &_mbcasemap;
394 ok_int(_mbcasemap[0], 0);
395
396 #undef _mbcasemap
398
399#ifdef _M_IX86
400 _CRTIMP unsigned char* __cdecl __p__mbcasemap();
402#endif
403}
404
406{
407 void* p = &_mbctype;
408 ok_int(_mbctype[0], 0);
409
410 #undef _mbctype
411 ok_ptr(&_mbctype, p);
412
413#ifdef _M_IX86
414 _CRTIMP unsigned char* __cdecl __p__mbctype();
415 todo_ros ok_ptr(__p__mbctype(), &_mbctype); // wine implements thiss like on Vista
416#endif
417}
418
419#ifndef _M_ARM
421{
423#if (WINVER >= 0x600)
424 _CRTIMP unsigned int __cdecl _get_osplatform(void);
426#endif
427}
428#endif
429
430void Test__osver(void)
431{
433
434#ifdef _M_IX86
437#endif
438}
439
440void Test__pgmptr(void)
441{
442 void* p = &_pgmptr;
443 ok(_pgmptr != NULL, "_pgmptr should not be NULL\n");
444
445 #undef _pgmptr
446 _CRTIMP extern char* _pgmptr;
447 ok_ptr(&_pgmptr, p);
448#ifdef _M_IX86
450#endif
451#if (WINVER >= 0x600)
452 _CRTIMP char* __cdecl _get_pgmptr(void);
454#endif
455}
456
458{
459 void* p = &_sys_errlist;
461 ok_int(strcmp(_sys_errlist[42], strerror(42)), 0);
462
463 #undef _sys_errlist
464 _CRTIMP extern char* _sys_errlist[];
466}
467
469{
470 void* p = &_sys_nerr;
471 ok_int(_sys_nerr, 43);
472
473 #undef _sys_nerr
474 _CRTIMP extern int _sys_nerr;
475 ok_ptr(&_sys_nerr, p);
476}
477
479{
480 void* p = &_timezone;
482
483 #undef _timezone
484 _CRTIMP extern long _timezone;
485 ok_ptr(&_timezone, p);
486
487#ifdef _M_IX86
488 _CRTIMP char** __p__timezone();
490#endif
491}
492
493void Test__tzname(void)
494{
495 void* p = &_tzname;
497 ok(_tzname[0] != NULL, "_tzname[0] == NULL\n");
498 ok(_tzname[0] != NULL, "_tzname[0] == NULL\n");
499
500 #undef _tzname
501 _CRTIMP extern char * _tzname[2];
502 ok_ptr(_tzname, p);
503
504#ifdef _M_IX86
505 _CRTIMP char** __p__tzname();
507#endif
508#if (WINVER >= 0x600)
509 _CRTIMP char* __cdecl __tzname(void);
510 ok_ptr(__tzname(), _wenviron);
511#endif
512}
513
514void Test__wcmdln(void)
515{
516 _CRTIMP extern wchar_t* _wcmdln;
517#ifdef _M_IX86
518 _CRTIMP wchar_t** __p__wcmdln(void);
520#endif
521}
522
523#ifndef _M_ARM
525{
526 void* p = &_wenviron;
527 todo_ros ok(_wenviron == NULL, "_wenviron is not NULL\n");
528
529 #undef _wenviron
530 _CRTIMP extern wchar_t** _wenviron;
531 ok_ptr(&_wenviron, p);
532#ifdef _M_IX86
534#endif
535#if (WINVER >= 0x600)
536 _CRTIMP unsigned int __cdecl _get_wenviron(void);
538#endif
539}
540#endif
541
543{
545#ifdef _M_IX86
546 _CRTIMP unsigned int* __cdecl __p__winmajor();
548#endif
549#if (WINVER >= 0x600)
550 _CRTIMP unsigned int __cdecl _get_winmajor(void);
552#endif
553}
554
556{
558#ifdef _M_IX86
559 _CRTIMP unsigned int* __cdecl __p__winminor();
561#endif
562#if (WINVER >= 0x600)
563 _CRTIMP unsigned int __cdecl _get_winminor(void);
565#endif
566}
567
568#ifndef _M_ARM
569void Test__winver(void)
570{
572#ifdef _M_IX86
573 _CRTIMP unsigned int* __cdecl __p__winver();
575#endif
576#if (WINVER >= 0x600)
577 _CRTIMP unsigned int __cdecl _get_winver(void);
579#endif
580}
581#endif
582
584{
585 void* p = _wpgmptr;
587
588 #undef _wpgmptr
589 ok_ptr(_wpgmptr, p);
590
591#ifdef _M_IX86
592 _CRTIMP wchar_t ** __cdecl __p__wpgmptr();
594#endif
595#if (WINVER >= 0x600)
596 _CRTIMP unsigned int __cdecl _get_wpgmptr(void);
598#endif
599}
600
602{
603 /* Initialize image size */
605 PIMAGE_NT_HEADERS ntHeaders = (PIMAGE_NT_HEADERS)((PUCHAR)dosHeader + dosHeader->e_lfanew);
606 s_ImageEnd = (PUCHAR)dosHeader + ntHeaders->OptionalHeader.SizeOfImage;
607
608 /* initialize version info */
611
612 Test___argc();
613 Test___argv();
615#ifndef _M_ARM
619#endif
623#ifndef _M_ARM
626#endif
627 Test___wargv();
628#ifndef _M_ARM
630#endif
631 Test__acmdln();
632#ifdef _M_IX86
633 Test__adjust_fdiv();
634#endif
637 Test__ctype();
639#ifndef _M_ARM
643#endif
644 Test__fmode();
645 Test__iob();
648#ifndef _M_ARM
650#endif
651 Test__osver();
652 Test__pgmptr();
656 Test__tzname();
657 Test__wcmdln();
658 Test__wctype();
659#ifndef _M_ARM
661#endif
664#ifndef _M_ARM
665 Test__winver();
666#endif
668}
const wchar_t ** __p__wcmdln(void)
Definition: environ.c:376
const char ** __p__acmdln(void)
Definition: environ.c:368
void _exit(int exitcode)
Definition: _exit.c:25
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define __cdecl
Definition: accygwin.h:79
int _adjust_fdiv
Definition: adjust.c:2
aexit_t _aexit_rtn
Definition: amsg.c:39
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define ok_ptr(expression, result)
Definition: atltest.h:108
void Test__tzname(void)
Definition: crtdata.c:493
char __ImageBase
void Test__winminor(void)
Definition: crtdata.c:555
void Test__osplatform(void)
Definition: crtdata.c:420
void Test__osver(void)
Definition: crtdata.c:430
int IsLocalSymbol(void *Address)
Definition: crtdata.c:22
void Test__dstbias(void)
Definition: crtdata.c:303
void Test__acmdln(void)
Definition: crtdata.c:199
void Test__mbcasemap(void)
Definition: crtdata.c:391
void Test__fileinfo(void)
Definition: crtdata.c:334
void Test___argc(void)
Definition: crtdata.c:33
void Test__sys_errlist(void)
Definition: crtdata.c:457
void Test__winver(void)
Definition: crtdata.c:569
void Test__wpgmptr(void)
Definition: crtdata.c:583
void Test___wargv(void)
Definition: crtdata.c:174
void Test__daylight(void)
Definition: crtdata.c:283
void Test___initenv(void)
Definition: crtdata.c:66
void Test__wenviron(void)
Definition: crtdata.c:524
void Test__mbctype(void)
Definition: crtdata.c:405
void Test___winitenv(void)
Definition: crtdata.c:188
void Test__fmode(void)
Definition: crtdata.c:346
void Test__ctype(void)
Definition: crtdata.c:238
void Test___setlc_active(void)
Definition: crtdata.c:151
static OSVERSIONINFOW s_osvi
Definition: crtdata.c:18
void Test__sys_nerr(void)
Definition: crtdata.c:468
void Test__pgmptr(void)
Definition: crtdata.c:440
void Test___argv(void)
Definition: crtdata.c:45
static void * s_ImageEnd
Definition: crtdata.c:20
void Test__aexit_rtn(void)
Definition: crtdata.c:217
void Test__environ(void)
Definition: crtdata.c:321
void Test___pioinfo(void)
Definition: crtdata.c:145
void Test__wcmdln(void)
Definition: crtdata.c:514
void Test__commode(void)
Definition: crtdata.c:224
void Test__iob(void)
Definition: crtdata.c:371
void Test___mb_cur_max(void)
Definition: crtdata.c:110
void Test__timezone(void)
Definition: crtdata.c:478
void Test__winmajor(void)
Definition: crtdata.c:542
void Test___lc_handle(void)
Definition: crtdata.c:99
void Test__wctype(void)
Definition: crtdata.c:265
void Test___unguarded_readlc_active(void)
Definition: crtdata.c:163
void Test___lc_collate_cp(void)
Definition: crtdata.c:87
void Test___badioinfo(void)
Definition: crtdata.c:57
#define test_is_local_symbol(addr, is)
Definition: crtdata.c:28
void Test___lc_codepage(void)
Definition: crtdata.c:77
#define _CRTIMP
Definition: crtdefs.h:72
int errno_t
Definition: crtdefs.h:374
const unsigned short ** __p__pwctype(void)
Definition: ctype.c:564
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
char ** __initenv
Definition: environ.c:24
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** _wenviron
Definition: environ.c:23
char ** _environ
Definition: environ.c:22
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
void * __p__fileinfo()
Definition: stubs.c:16
int _fileinfo
Definition: stubs.c:13
void * __p__mbcasemap()
Definition: stubs.c:24
unsigned char _mbcasemap[1]
Definition: stubs.c:21
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
GLenum mode
Definition: glext.h:6217
GLfloat GLfloat p
Definition: glext.h:8902
#define _CONTROL
Definition: ctype.h:71
#define __mb_cur_max
Definition: ctype.h:629
#define ___mb_cur_max_func()
Definition: ctype.h:636
_CRTIMP unsigned int __cdecl ___lc_collate_cp_func(void)
Definition: locale.c:635
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:627
#define stdout
Definition: stdio.h:99
_CRTIMP int _commode
Definition: environ.c:31
#define stderr
Definition: stdio.h:100
_CRTIMP FILE *__cdecl __iob_func(void)
Definition: file.c:682
#define stdin
Definition: stdio.h:98
_CRTIMP errno_t __cdecl _get_fmode(_Out_ int *_PMode)
_CRTIMP char * _sys_errlist[]
Definition: strerror.c:68
_CRTIMP char **__cdecl __p__pgmptr()
Definition: environ.c:454
_CRTIMP char ***__cdecl __p___argv()
Definition: getargs.c:483
_CRTIMP wchar_t * _wpgmptr
Definition: environ.c:29
_CRTIMP int _fmode
Definition: fmode.c:4
_CRTIMP errno_t __cdecl _get_wenviron(_Out_ wchar_t ***)
errno_t __cdecl _get_winver(_Out_ unsigned int *_Value)
_CRTIMP char ** __argv
Definition: getargs.c:18
_CRTIMP wchar_t ***__cdecl __p___wargv()
Definition: getargs.c:491
_CRTIMP wchar_t ***__cdecl __p__wenviron()
Definition: environ.c:392
errno_t __cdecl _get_winmajor(_Out_ unsigned int *_Value)
_CRTIMP int _sys_nerr
Definition: strerror.c:80
_CRTIMP wchar_t **__cdecl __p__wpgmptr()
Definition: environ.c:477
_CRTIMP errno_t __cdecl _get_wpgmptr(_Outptr_result_z_ wchar_t **_Value)
_CRTIMP errno_t __cdecl _get_pgmptr(_Outptr_result_z_ char **_Value)
_CRTIMP int __argc
Definition: getargs.c:21
errno_t __cdecl _get_osplatform(_Out_ unsigned int *_Value)
_CRTIMP int *__cdecl __p___argc()
Definition: getargs.c:475
_CRTIMP wchar_t ** __wargv
Definition: getargs.c:20
errno_t __cdecl _get_winminor(_Out_ unsigned int *_Value)
_CRTIMP char ***__cdecl __p__environ()
Definition: environ.c:384
_CRTIMP char * _pgmptr
Definition: environ.c:27
#define __pwctype_func()
Definition: wctype.h:68
#define __pctype_func()
Definition: wctype.h:34
#define _pctype
Definition: wctype.h:43
#define _wctype
Definition: wctype.h:58
#define _pwctype
Definition: wctype.h:67
unsigned char * __p__mbctype(void)
Definition: ismblead.c:48
_CRTIMP unsigned char _mbctype[257]
Definition: locale.c:40
int *__cdecl __p___mb_cur_max(void)
Definition: environ.c:430
unsigned int *__cdecl __p__fmode(void)
Definition: fmode.c:9
const char * strerror(int err)
Definition: compat_str.c:23
#define _Out_
Definition: ms_sal.h:345
char * _acmdln
Definition: environ.c:18
unsigned int _winminor
Definition: environ.c:12
unsigned int _winmajor
Definition: environ.c:13
wchar_t * _wcmdln
Definition: environ.c:19
unsigned int _osver
Definition: environ.c:11
unsigned int _osplatform
Definition: environ.c:10
unsigned int _winver
Definition: environ.c:14
static WCHAR Address[46]
Definition: ping.c:68
#define todo_ros
Definition: test.h:167
_CRTIMP ioinfo * __badioinfo[]
Definition: file.c:126
const unsigned short _ctype[257]
Definition: ctype.c:36
int __lc_collate_cp
unsigned int __lc_codepage
Definition: locale.c:34
LCID *CDECL ___lc_handle_func(void)
Definition: locale.c:619
unsigned int __unguarded_readlc_active
Definition: environ.c:17
unsigned int CDECL ___setlc_active_func(void)
Definition: locale.c:1481
const unsigned short ** __p__pctype(void)
Definition: locale.c:1518
unsigned int *CDECL ___unguarded_readlc_active_add_func(void)
Definition: locale.c:1490
unsigned int __setlc_active
Definition: environ.c:16
wchar_t *** __p___winitenv(void)
Definition: environ.c:408
unsigned int * __p__winminor(void)
Definition: environ.c:508
unsigned int * __p__winmajor(void)
Definition: environ.c:500
unsigned int * __p__winver(void)
Definition: environ.c:516
char *** __p___initenv(void)
Definition: environ.c:400
unsigned int * __p__osver(void)
Definition: environ.c:446
int * __p__commode(void)
Definition: environ.c:352
FILE _iob[_IOB_ENTRIES]
Definition: file.c:133
long * __p__dstbias(void)
Definition: timezone.c:69
void * __p__daylight(void)
Definition: timezone.c:37
char ** __p__tzname(void)
Definition: timezone.c:79
int _daylight
Definition: timezone.c:30
char * _tzname[2]
Definition: timezone.c:22
long * __p__timezone(void)
Definition: timezone.c:53
long _dstbias
Definition: timezone.c:62
long _timezone
Definition: timezone.c:46
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
ULONG dwMinorVersion
Definition: rtltypes.h:248
ULONG dwPlatformId
Definition: rtltypes.h:250
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
ULONG dwMajorVersion
Definition: rtltypes.h:247
ULONG dwBuildNumber
Definition: rtltypes.h:249
Definition: file.c:40
unsigned char * PUCHAR
Definition: typedefs.h:53