You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

std_testcase.h 3.9 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef _STD_TESTCASE_H
  2. #define _STD_TESTCASE_H
  3. /* This file exists in order to:
  4. * 1) Include lots of standardized headers in one place
  5. * 2) To avoid #include-ing things in the middle of your code
  6. * #include-ing in the middle of a C/C++ file is apt to cause compiler errors
  7. * 3) To get good #define's in place
  8. *
  9. * In reality you need a complex interaction of scripts of build processes to do
  10. * this correctly (i.e., autoconf)
  11. */
  12. #ifdef _WIN32
  13. /* Ensure the CRT does not disable the "insecure functions"
  14. * Ensure not to generate warnings about ANSI C functions.
  15. */
  16. #define _CRT_SECURE_NO_DEPRECATE 1
  17. #define _CRT_SECURE_NO_WARNING 1
  18. /* We do not use _malloca as it sometimes allocates memory on the heap and we
  19. * do not want this to happen in test cases that expect stack-allocated memory
  20. * Also, _alloca_s cannot be used as it is deprecated and has been replaced
  21. * with _malloca */
  22. #define ALLOCA _alloca
  23. /* disable warnings about use of POSIX names for functions like execl()
  24. Visual Studio wants you to use the ISO C++ name, such as _execl() */
  25. #pragma warning(disable:4996)
  26. #else
  27. /* Linux/GNU wants this macro, otherwise stdint.h and limits.h are mostly useless */
  28. # define __STDC_LIMIT_MACROS 1
  29. #define ALLOCA alloca
  30. #endif
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <stddef.h>
  34. #include <time.h>
  35. #include <limits.h>
  36. #include <string.h>
  37. #include <stdint.h>
  38. #ifndef _WIN32
  39. /* SIZE_MAX, int64_t, etc. are in this file on Linux */
  40. # include <stdint.h>
  41. #endif
  42. #include <ctype.h>
  43. #include <fcntl.h>
  44. #include <sys/types.h>
  45. #include <sys/stat.h>
  46. #ifdef _WIN32
  47. #include <io.h> /* for open/close etc */
  48. #endif
  49. #ifdef __cplusplus
  50. #include <new> // for placement new
  51. /* classes used in some test cases as a custom type */
  52. class TwoIntsClass
  53. {
  54. public: // Needed to access variables from label files
  55. int intOne;
  56. int intTwo;
  57. };
  58. class OneIntClass
  59. {
  60. public: // Needed to access variables from label files
  61. int intOne;
  62. };
  63. #endif
  64. #ifndef __cplusplus
  65. /* Define true and false, which are included in C++, but not in C */
  66. #define true 1
  67. #define false 0
  68. #endif /* end ifndef __cplusplus */
  69. /* rand only returns 15 bits, so we xor 3 calls together to get the full result (13 bits overflow, but that is okay) */
  70. // shifting signed values might overflow and be undefined
  71. #define URAND31() (((unsigned)rand()<<30) ^ ((unsigned)rand()<<15) ^ rand())
  72. // choose to produce a positive or a negative number. Note: conditional only evaluates one URAND31
  73. #define RAND32() ((int)(rand() & 1 ? URAND31() : -URAND31() - 1))
  74. /* rand only returns 15 bits, so we xor 5 calls together to get the full result (11 bits overflow, but that is okay) */
  75. // shifting signed values might overflow and be undefined
  76. #define URAND63() (((uint64_t)rand()<<60) ^ ((uint64_t)rand()<<45) ^ ((uint64_t)rand()<<30) ^ ((uint64_t)rand()<<15) ^ rand())
  77. // choose to produce a positive or a negative number. Note: conditional only evaluates one URAND63
  78. #define RAND64() ((int64_t)(rand() & 1 ? URAND63() : -URAND63() - 1))
  79. /* struct used in some test cases as a custom type */
  80. typedef struct _twoIntsStruct
  81. {
  82. int intOne;
  83. int intTwo;
  84. } twoIntsStruct;
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. /* The variables below are declared "const", so a tool should
  89. be able to identify that reads of these will always return their
  90. initialized values. */
  91. extern const int GLOBAL_CONST_TRUE; /* true */
  92. extern const int GLOBAL_CONST_FALSE; /* false */
  93. extern const int GLOBAL_CONST_FIVE; /* 5 */
  94. /* The variables below are not defined as "const", but are never
  95. assigned any other value, so a tool should be able to identify that
  96. reads of these will always return their initialized values. */
  97. extern int globalTrue; /* true */
  98. extern int globalFalse; /* false */
  99. extern int globalFive; /* 5 */
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #include "std_testcase_io.h"
  104. #endif

No Description

Contributors (1)