headers.c 13.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2004 Dimitrie O. Paun
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17
 *
18 19
 * This file contains tests to ensure the consistency between symbols
 * defined in the regular msvcrt headers, and the corresponding duplicated
20
 * symbols defined in msvcrt.h (prefixed by MSVCRT_).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 */

#include "dos.h"
#include "math.h"
#include "stdlib.h"
#include "io.h"
#include "errno.h"
#include "fcntl.h"
#include "malloc.h"
#include "limits.h"
#include "mbctype.h"
#include "stdio.h"
#include "wchar.h"
#include "ctype.h"
#include "crtdbg.h"
#include "share.h"
#include "search.h"
#include "wctype.h"
#include "float.h"
#include "stddef.h"
#include "mbstring.h"
#include "sys/locking.h"
#include "sys/utime.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "sys/timeb.h"
#include "direct.h"
#include "conio.h"
#include "process.h"
#include "string.h"
51
#include "signal.h"
52 53 54 55 56
#include "time.h"
#include "locale.h"
#include "setjmp.h"
#include "wine/test.h"

57 58 59 60 61 62
#ifdef __WINE_USE_MSVCRT
/* Wine-specific msvcrt headers */
#define __WINE_MSVCRT_TEST
#include "eh.h"
#include "msvcrt.h"

63 64 65 66 67 68 69 70
#ifdef __GNUC__
#define TYPEOF(type) typeof(type)
#else
#define TYPEOF(type) int
#endif
#define MSVCRT(x)    MSVCRT_##x
#define OFFSET(T,F) ((unsigned int)((char *)&((struct T *)0L)->F - (char *)0L))
#define CHECK_SIZE(e) ok(sizeof(e) == sizeof(MSVCRT(e)), "Element has different sizes\n")
71
#define CHECK_TYPE(t) { TYPEOF(t) a = 0; TYPEOF(MSVCRT(t)) b = a; a = b; CHECK_SIZE(t); }
72 73
#define CHECK_STRUCT(s) ok(sizeof(struct s) == sizeof(struct MSVCRT(s)), "Struct has different sizes\n")
#define CHECK_FIELD(s,e) ok(OFFSET(s,e) == OFFSET(MSVCRT(s),e), "Bad offset\n")
74
#define CHECK_DEF(d) ok(d == MSVCRT_##d, "Defines (MSVCRT_)" #d " are different: %d vs. %d\n", d, MSVCRT_##d)
75 76

/************* Checking types ***************/
77
static void test_types(void)
78 79 80 81 82 83 84
{
    CHECK_TYPE(wchar_t);
    CHECK_TYPE(wint_t);
    CHECK_TYPE(wctype_t);
    CHECK_TYPE(_ino_t);
    CHECK_TYPE(_fsize_t);
    CHECK_TYPE(size_t);
85 86
    CHECK_TYPE(intptr_t);
    CHECK_TYPE(uintptr_t);
87 88 89
    CHECK_TYPE(_dev_t);
    CHECK_TYPE(_off_t);
    CHECK_TYPE(clock_t);
90
    CHECK_TYPE(__time32_t);
91
    CHECK_TYPE(__time64_t);
92 93 94 95 96 97 98 99 100
    CHECK_TYPE(fpos_t);
    CHECK_SIZE(FILE);
    CHECK_TYPE(terminate_handler);
    CHECK_TYPE(terminate_function);
    CHECK_TYPE(unexpected_handler);
    CHECK_TYPE(unexpected_function);
    CHECK_TYPE(_se_translator_function);
    CHECK_TYPE(_beginthread_start_routine_t);
    CHECK_TYPE(_onexit_t);
101
    CHECK_TYPE(__sighandler_t);
102 103 104
}

/************* Checking structs ***************/
105
static void test_structs(void)
106 107 108 109 110 111 112 113 114 115 116
{
    CHECK_STRUCT(tm);
    CHECK_FIELD(tm, tm_sec);
    CHECK_FIELD(tm, tm_min);
    CHECK_FIELD(tm, tm_hour);
    CHECK_FIELD(tm, tm_mday);
    CHECK_FIELD(tm, tm_mon);
    CHECK_FIELD(tm, tm_year);
    CHECK_FIELD(tm, tm_wday);
    CHECK_FIELD(tm, tm_yday);
    CHECK_FIELD(tm, tm_isdst);
117 118 119 120 121 122 123 124 125 126
    CHECK_STRUCT(__timeb32);
    CHECK_FIELD(__timeb32, time);
    CHECK_FIELD(__timeb32, millitm);
    CHECK_FIELD(__timeb32, timezone);
    CHECK_FIELD(__timeb32, dstflag);
    CHECK_STRUCT(__timeb64);
    CHECK_FIELD(__timeb64, time);
    CHECK_FIELD(__timeb64, millitm);
    CHECK_FIELD(__timeb64, timezone);
    CHECK_FIELD(__timeb64, dstflag);
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    CHECK_STRUCT(_iobuf);
    CHECK_FIELD(_iobuf, _ptr);
    CHECK_FIELD(_iobuf, _cnt);
    CHECK_FIELD(_iobuf, _base);
    CHECK_FIELD(_iobuf, _flag);
    CHECK_FIELD(_iobuf, _file);
    CHECK_FIELD(_iobuf, _charbuf);
    CHECK_FIELD(_iobuf, _bufsiz);
    CHECK_FIELD(_iobuf, _tmpfname);
    CHECK_STRUCT(lconv);
    CHECK_FIELD(lconv, decimal_point);
    CHECK_FIELD(lconv, thousands_sep);
    CHECK_FIELD(lconv, grouping);
    CHECK_FIELD(lconv, int_curr_symbol);
    CHECK_FIELD(lconv, currency_symbol);
    CHECK_FIELD(lconv, mon_decimal_point);
    CHECK_FIELD(lconv, mon_thousands_sep);
    CHECK_FIELD(lconv, mon_grouping);
    CHECK_FIELD(lconv, positive_sign);
    CHECK_FIELD(lconv, negative_sign);
    CHECK_FIELD(lconv, int_frac_digits);
    CHECK_FIELD(lconv, frac_digits);
    CHECK_FIELD(lconv, p_cs_precedes);
    CHECK_FIELD(lconv, p_sep_by_space);
    CHECK_FIELD(lconv, n_cs_precedes);
    CHECK_FIELD(lconv, n_sep_by_space);
    CHECK_FIELD(lconv, p_sign_posn);
    CHECK_FIELD(lconv, n_sign_posn);
    CHECK_STRUCT(_exception);
    CHECK_FIELD(_exception, type);
    CHECK_FIELD(_exception, name);
    CHECK_FIELD(_exception, arg1);
    CHECK_FIELD(_exception, arg2);
    CHECK_FIELD(_exception, retval);
    CHECK_STRUCT(_complex);
    CHECK_FIELD(_complex, x);
    CHECK_FIELD(_complex, y);
164 165 166 167 168 169
    CHECK_STRUCT(_div_t);
    CHECK_FIELD(_div_t, quot);
    CHECK_FIELD(_div_t, rem);
    CHECK_STRUCT(_ldiv_t);
    CHECK_FIELD(_ldiv_t, quot);
    CHECK_FIELD(_ldiv_t, rem);
170 171 172 173
    CHECK_STRUCT(_heapinfo);
    CHECK_FIELD(_heapinfo, _pentry);
    CHECK_FIELD(_heapinfo, _size);
    CHECK_FIELD(_heapinfo, _useflag);
174
#ifdef __i386__
175 176 177 178 179 180 181 182 183 184 185 186
    CHECK_STRUCT(__JUMP_BUFFER);
    CHECK_FIELD(__JUMP_BUFFER, Ebp);
    CHECK_FIELD(__JUMP_BUFFER, Ebx);
    CHECK_FIELD(__JUMP_BUFFER, Edi);
    CHECK_FIELD(__JUMP_BUFFER, Esi);
    CHECK_FIELD(__JUMP_BUFFER, Esp);
    CHECK_FIELD(__JUMP_BUFFER, Eip);
    CHECK_FIELD(__JUMP_BUFFER, Registration);
    CHECK_FIELD(__JUMP_BUFFER, TryLevel);
    CHECK_FIELD(__JUMP_BUFFER, Cookie);
    CHECK_FIELD(__JUMP_BUFFER, UnwindFunc);
    CHECK_FIELD(__JUMP_BUFFER, UnwindData[6]);
187
#endif
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
    CHECK_STRUCT(_diskfree_t);
    CHECK_FIELD(_diskfree_t, total_clusters);
    CHECK_FIELD(_diskfree_t, avail_clusters);
    CHECK_FIELD(_diskfree_t, sectors_per_cluster);
    CHECK_FIELD(_diskfree_t, bytes_per_sector);
    CHECK_STRUCT(_finddata_t);
    CHECK_FIELD(_finddata_t, attrib);
    CHECK_FIELD(_finddata_t, time_create);
    CHECK_FIELD(_finddata_t, time_access);
    CHECK_FIELD(_finddata_t, time_write);
    CHECK_FIELD(_finddata_t, size);
    CHECK_FIELD(_finddata_t, name[260]);
    CHECK_STRUCT(_finddatai64_t);
    CHECK_FIELD(_finddatai64_t, attrib);
    CHECK_FIELD(_finddatai64_t, time_create);
    CHECK_FIELD(_finddatai64_t, time_access);
    CHECK_FIELD(_finddatai64_t, time_write);
    CHECK_FIELD(_finddatai64_t, size);
    CHECK_FIELD(_finddatai64_t, name[260]);
    CHECK_STRUCT(_wfinddata_t);
    CHECK_FIELD(_wfinddata_t, attrib);
    CHECK_FIELD(_wfinddata_t, time_create);
    CHECK_FIELD(_wfinddata_t, time_access);
    CHECK_FIELD(_wfinddata_t, time_write);
    CHECK_FIELD(_wfinddata_t, size);
    CHECK_FIELD(_wfinddata_t, name[260]);
    CHECK_STRUCT(_wfinddatai64_t);
    CHECK_FIELD(_wfinddatai64_t, attrib);
    CHECK_FIELD(_wfinddatai64_t, time_create);
    CHECK_FIELD(_wfinddatai64_t, time_access);
    CHECK_FIELD(_wfinddatai64_t, time_write);
    CHECK_FIELD(_wfinddatai64_t, size);
    CHECK_FIELD(_wfinddatai64_t, name[260]);
221 222 223 224 225 226
    CHECK_STRUCT(__utimbuf32);
    CHECK_FIELD(__utimbuf32, actime);
    CHECK_FIELD(__utimbuf32, modtime);
    CHECK_STRUCT(__utimbuf64);
    CHECK_FIELD(__utimbuf64, actime);
    CHECK_FIELD(__utimbuf64, modtime);
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    CHECK_STRUCT(_stat);
    CHECK_FIELD(_stat, st_dev);
    CHECK_FIELD(_stat, st_ino);
    CHECK_FIELD(_stat, st_mode);
    CHECK_FIELD(_stat, st_nlink);
    CHECK_FIELD(_stat, st_uid);
    CHECK_FIELD(_stat, st_gid);
    CHECK_FIELD(_stat, st_rdev);
    CHECK_FIELD(_stat, st_size);
    CHECK_FIELD(_stat, st_atime);
    CHECK_FIELD(_stat, st_mtime);
    CHECK_FIELD(_stat, st_ctime);
    CHECK_STRUCT(_stati64);
    CHECK_FIELD(_stati64, st_dev);
    CHECK_FIELD(_stati64, st_ino);
    CHECK_FIELD(_stati64, st_mode);
    CHECK_FIELD(_stati64, st_nlink);
    CHECK_FIELD(_stati64, st_uid);
    CHECK_FIELD(_stati64, st_gid);
    CHECK_FIELD(_stati64, st_rdev);
    CHECK_FIELD(_stati64, st_size);
    CHECK_FIELD(_stati64, st_atime);
    CHECK_FIELD(_stati64, st_mtime);
    CHECK_FIELD(_stati64, st_ctime);
251 252 253 254 255 256 257 258 259 260 261 262
    CHECK_STRUCT(_stat64);
    CHECK_FIELD(_stat64, st_dev);
    CHECK_FIELD(_stat64, st_ino);
    CHECK_FIELD(_stat64, st_mode);
    CHECK_FIELD(_stat64, st_nlink);
    CHECK_FIELD(_stat64, st_uid);
    CHECK_FIELD(_stat64, st_gid);
    CHECK_FIELD(_stat64, st_rdev);
    CHECK_FIELD(_stat64, st_size);
    CHECK_FIELD(_stat64, st_atime);
    CHECK_FIELD(_stat64, st_mtime);
    CHECK_FIELD(_stat64, st_ctime);
263
    CHECK_SIZE(_CRT_FLOAT);
264 265 266
}

/************* Checking defines ***************/
267
static void test_defines(void)
268
{
269 270 271
    CHECK_DEF(WEOF);
    CHECK_DEF(EOF);
    CHECK_DEF(TMP_MAX);
272
    CHECK_DEF(RAND_MAX);
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
    CHECK_DEF(BUFSIZ);
    CHECK_DEF(STDIN_FILENO);
    CHECK_DEF(STDOUT_FILENO);
    CHECK_DEF(STDERR_FILENO);
    CHECK_DEF(_IOFBF);
    CHECK_DEF(_IONBF);
    CHECK_DEF(_IOLBF);
    CHECK_DEF(FILENAME_MAX);
    CHECK_DEF(_P_WAIT);
    CHECK_DEF(_P_NOWAIT);
    CHECK_DEF(_P_OVERLAY);
    CHECK_DEF(_P_NOWAITO);
    CHECK_DEF(_P_DETACH);
    CHECK_DEF(EPERM);
    CHECK_DEF(ENOENT);
    CHECK_DEF(ESRCH);
    CHECK_DEF(EINTR);
    CHECK_DEF(EIO);
    CHECK_DEF(ENXIO);
    CHECK_DEF(E2BIG);
    CHECK_DEF(ENOEXEC);
    CHECK_DEF(EBADF);
    CHECK_DEF(ECHILD);
    CHECK_DEF(EAGAIN);
    CHECK_DEF(ENOMEM);
    CHECK_DEF(EACCES);
    CHECK_DEF(EFAULT);
    CHECK_DEF(EBUSY);
    CHECK_DEF(EEXIST);
    CHECK_DEF(EXDEV);
    CHECK_DEF(ENODEV);
    CHECK_DEF(ENOTDIR);
    CHECK_DEF(EISDIR);
    CHECK_DEF(EINVAL);
    CHECK_DEF(ENFILE);
    CHECK_DEF(EMFILE);
    CHECK_DEF(ENOTTY);
    CHECK_DEF(EFBIG);
    CHECK_DEF(ENOSPC);
    CHECK_DEF(ESPIPE);
    CHECK_DEF(EROFS);
    CHECK_DEF(EMLINK);
    CHECK_DEF(EPIPE);
    CHECK_DEF(EDOM);
    CHECK_DEF(ERANGE);
    CHECK_DEF(EDEADLK);
    CHECK_DEF(EDEADLOCK);
    CHECK_DEF(ENAMETOOLONG);
    CHECK_DEF(ENOLCK);
    CHECK_DEF(ENOSYS);
    CHECK_DEF(ENOTEMPTY);
324
    CHECK_DEF(EILSEQ);
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
    CHECK_DEF(LC_ALL);
    CHECK_DEF(LC_COLLATE);
    CHECK_DEF(LC_CTYPE);
    CHECK_DEF(LC_MONETARY);
    CHECK_DEF(LC_NUMERIC);
    CHECK_DEF(LC_TIME);
    CHECK_DEF(LC_MIN);
    CHECK_DEF(LC_MAX);
    CHECK_DEF(CLOCKS_PER_SEC);
    CHECK_DEF(_HEAPEMPTY);
    CHECK_DEF(_HEAPOK);
    CHECK_DEF(_HEAPBADBEGIN);
    CHECK_DEF(_HEAPBADNODE);
    CHECK_DEF(_HEAPEND);
    CHECK_DEF(_HEAPBADPTR);
    CHECK_DEF(_FREEENTRY);
    CHECK_DEF(_USEDENTRY);
    CHECK_DEF(_OUT_TO_DEFAULT);
343 344
    CHECK_DEF(_OUT_TO_STDERR);
    CHECK_DEF(_OUT_TO_MSGBOX);
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
    CHECK_DEF(_REPORT_ERRMODE);
    CHECK_DEF(_UPPER);
    CHECK_DEF(_LOWER);
    CHECK_DEF(_DIGIT);
    CHECK_DEF(_SPACE);
    CHECK_DEF(_PUNCT);
    CHECK_DEF(_CONTROL);
    CHECK_DEF(_BLANK);
    CHECK_DEF(_HEX);
    CHECK_DEF(_LEADBYTE);
    CHECK_DEF(_ALPHA);
    CHECK_DEF(_IOREAD);
    CHECK_DEF(_IOWRT);
    CHECK_DEF(_IOMYBUF);
    CHECK_DEF(_IOEOF);
    CHECK_DEF(_IOERR);
    CHECK_DEF(_IOSTRG);
    CHECK_DEF(_IORW);
    CHECK_DEF(_S_IEXEC);
    CHECK_DEF(_S_IWRITE);
    CHECK_DEF(_S_IREAD);
    CHECK_DEF(_S_IFIFO);
    CHECK_DEF(_S_IFCHR);
    CHECK_DEF(_S_IFDIR);
    CHECK_DEF(_S_IFREG);
    CHECK_DEF(_S_IFMT);
    CHECK_DEF(_LK_UNLCK);
    CHECK_DEF(_LK_LOCK);
    CHECK_DEF(_LK_NBLCK);
    CHECK_DEF(_LK_RLCK);
    CHECK_DEF(_LK_NBRLCK);
    CHECK_DEF(_O_RDONLY);
    CHECK_DEF(_O_WRONLY);
    CHECK_DEF(_O_RDWR);
    CHECK_DEF(_O_ACCMODE);
    CHECK_DEF(_O_APPEND);
    CHECK_DEF(_O_RANDOM);
    CHECK_DEF(_O_SEQUENTIAL);
    CHECK_DEF(_O_TEMPORARY);
    CHECK_DEF(_O_NOINHERIT);
    CHECK_DEF(_O_CREAT);
    CHECK_DEF(_O_TRUNC);
    CHECK_DEF(_O_EXCL);
    CHECK_DEF(_O_SHORT_LIVED);
    CHECK_DEF(_O_TEXT);
    CHECK_DEF(_O_BINARY);
    CHECK_DEF(_O_RAW);
    CHECK_DEF(_SW_INEXACT);
    CHECK_DEF(_SW_UNDERFLOW);
    CHECK_DEF(_SW_OVERFLOW);
    CHECK_DEF(_SW_ZERODIVIDE);
    CHECK_DEF(_SW_INVALID);
    CHECK_DEF(_SW_UNEMULATED);
    CHECK_DEF(_SW_SQRTNEG);
    CHECK_DEF(_SW_STACKOVERFLOW);
    CHECK_DEF(_SW_STACKUNDERFLOW);
    CHECK_DEF(_SW_DENORMAL);
    CHECK_DEF(_FPCLASS_SNAN);
    CHECK_DEF(_FPCLASS_QNAN);
    CHECK_DEF(_FPCLASS_NINF);
    CHECK_DEF(_FPCLASS_NN);
    CHECK_DEF(_FPCLASS_ND);
    CHECK_DEF(_FPCLASS_NZ);
    CHECK_DEF(_FPCLASS_PZ);
    CHECK_DEF(_FPCLASS_PD);
    CHECK_DEF(_FPCLASS_PN);
    CHECK_DEF(_FPCLASS_PINF);
    CHECK_DEF(SIGINT);
    CHECK_DEF(SIGILL);
    CHECK_DEF(SIGFPE);
    CHECK_DEF(SIGSEGV);
    CHECK_DEF(SIGTERM);
    CHECK_DEF(SIGBREAK);
    CHECK_DEF(SIGABRT);
    CHECK_DEF(NSIG);
420 421 422 423 424 425 426 427 428 429 430
    CHECK_DEF(_FPE_INVALID);
    CHECK_DEF(_FPE_DENORMAL);
    CHECK_DEF(_FPE_ZERODIVIDE);
    CHECK_DEF(_FPE_OVERFLOW);
    CHECK_DEF(_FPE_UNDERFLOW);
    CHECK_DEF(_FPE_INEXACT);
    CHECK_DEF(_FPE_UNEMULATED);
    CHECK_DEF(_FPE_SQRTNEG);
    CHECK_DEF(_FPE_STACKOVERFLOW);
    CHECK_DEF(_FPE_STACKUNDERFLOW);
    CHECK_DEF(_FPE_EXPLICITGEN);
431 432 433 434 435
    CHECK_DEF(_MCW_EM);
    CHECK_DEF(_MCW_IC);
    CHECK_DEF(_MCW_RC);
    CHECK_DEF(_MCW_PC);
    CHECK_DEF(_MCW_DN);
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
    CHECK_DEF(_EM_INVALID);
    CHECK_DEF(_EM_DENORMAL);
    CHECK_DEF(_EM_ZERODIVIDE);
    CHECK_DEF(_EM_OVERFLOW);
    CHECK_DEF(_EM_UNDERFLOW);
    CHECK_DEF(_EM_INEXACT);
    CHECK_DEF(_IC_AFFINE);
    CHECK_DEF(_IC_PROJECTIVE);
    CHECK_DEF(_RC_CHOP);
    CHECK_DEF(_RC_UP);
    CHECK_DEF(_RC_DOWN);
    CHECK_DEF(_RC_NEAR);
    CHECK_DEF(_PC_24);
    CHECK_DEF(_PC_53);
    CHECK_DEF(_PC_64);
451 452 453 454 455
    CHECK_DEF(_DN_SAVE);
    CHECK_DEF(_DN_FLUSH);
    CHECK_DEF(_DN_FLUSH_OPERANDS_SAVE_RESULTS);
    CHECK_DEF(_DN_SAVE_OPERANDS_FLUSH_RESULTS);
    CHECK_DEF(_EM_AMBIGUOUS);
456 457
    CHECK_DEF(_OVERFLOW);
    CHECK_DEF(_UNDERFLOW);
458 459
    CHECK_DEF(_WRITE_ABORT_MSG);
    CHECK_DEF(_CALL_REPORTFAULT);
460
    CHECK_DEF(_TWO_DIGIT_EXPONENT);
461 462
}

463 464
#endif /* __WINE_USE_MSVCRT */

465 466
START_TEST(headers)
{
467
#ifdef __WINE_USE_MSVCRT
468 469 470
    test_types();
    test_structs();
    test_defines();
471
#endif
472
}