EAStdCTest.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #ifndef EASTDC_EASTDCTEST_H
  5. #define EASTDC_EASTDCTEST_H
  6. EA_DISABLE_ALL_VC_WARNINGS()
  7. EA_DISABLE_VC_WARNING(4530) // C++ exception handler used, but unwind semantics are not enabled.
  8. #include <stddef.h>
  9. EA_RESTORE_VC_WARNING()
  10. EA_RESTORE_ALL_VC_WARNINGS()
  11. int TestCallback();
  12. int TestString();
  13. int TestCType();
  14. int TestBitTricks();
  15. int TestAlignment();
  16. int TestByteCrackers();
  17. int TestDateTime();
  18. int TestEndian();
  19. int TestFixedPoint();
  20. int TestRandom();
  21. int TestHash();
  22. int TestGlobal();
  23. int TestMathHelp();
  24. int TestMemory();
  25. int TestProcess();
  26. int TestScanf();
  27. int TestSingleton();
  28. int TestSprintf();
  29. int TestStopwatch();
  30. int TestTextUtil();
  31. int TestInt128();
  32. extern volatile int gWriteToEnsureFunctionCalled;
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // EA_WCHAR / EA_CHAR16 / EA_CHAR32
  35. //
  36. // We define these in the case that EABase doesn't define them so that our
  37. // tests can exercize them. For example, on Windows EABase doesn't define
  38. // EA_CHAR32, as it's impossible to do so in an efficient way and would be
  39. // bad for user code. But for our unit tests we don't care about this and
  40. // it's useful to have it.
  41. ///////////////////////////////////////////////////////////////////////////////
  42. // Always defind as L""
  43. // The purpose of this in our unit tests is to make it explicit in
  44. // the test code that we really mean L""/L'' and not EA_CHAR16 or EA_CHAR32.
  45. #if !defined(EA_WCHAR)
  46. #define EA_WCHAR(s) L ## s
  47. #endif
  48. #if !defined(EA_CHAR16)
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <EASTL/map.h>
  52. #include <EAStdC/EAString.h>
  53. // This class has no purpose other than to convert 32 bit wchar_t strings to 16 bit char16_t strings.
  54. // The code below probably wouldn't compile or make sense unless wchar_t was 32 bits or more.
  55. class ea_char16_str
  56. {
  57. public:
  58. ea_char16_str() : mpData(NULL), mLength(0) {}
  59. ea_char16_str(const wchar_t* pText)
  60. {
  61. mLength = EA::StdC::Strlen(pText);
  62. mpData = (char16_t*)malloc((mLength + 1) * sizeof(char16_t));
  63. for(size_t i = 0; i < (mLength + 1); ++i)
  64. mpData[i] = (char16_t)pText[i];
  65. }
  66. ea_char16_str(const ea_char16_str& str)
  67. {
  68. CopyFrom(str);
  69. }
  70. ea_char16_str& operator=(const ea_char16_str& str)
  71. {
  72. if(&str != this)
  73. {
  74. if(mpData)
  75. free(mpData);
  76. CopyFrom(str);
  77. }
  78. return *this;
  79. }
  80. void CopyFrom(const ea_char16_str& str)
  81. {
  82. mLength = str.mLength;
  83. mpData = (char16_t*)malloc((mLength + 1) * sizeof(char16_t));
  84. for(size_t i = 0; i < (mLength + 1); ++i)
  85. mpData[i] = str.mpData[i];
  86. }
  87. ~ea_char16_str()
  88. {
  89. if(mpData)
  90. free(mpData);
  91. }
  92. char16_t* mpData;
  93. size_t mLength;
  94. };
  95. char16_t* char16_convert(const wchar_t* pText);
  96. char16_t char16_convert(wchar_t c);
  97. #define EA_CHAR16(s) char16_convert(L ## s)
  98. #define EASTDCTEST_DEFINES_CHAR16
  99. #endif
  100. #if !defined(EA_CHAR32)
  101. #include <stdlib.h>
  102. #include <string.h>
  103. #include <EASTL/map.h>
  104. #include <EAStdC/EAString.h>
  105. // This class has no purpose other than to convert 16 bit wchar_t strings to 32 bit char32_t strings.
  106. // The code below probably wouldn't compile or make sense unless wchar_t was 16 bits or less.
  107. class ea_char32_str
  108. {
  109. public:
  110. ea_char32_str() : mpData(NULL), mLength(0) {}
  111. ea_char32_str(const wchar_t* pText)
  112. {
  113. mLength = EA::StdC::Strlen(pText);
  114. mpData = (char32_t*)malloc((mLength + 1) * sizeof(char32_t));
  115. if(mpData)
  116. {
  117. for(size_t i = 0; i < (mLength + 1); ++i)
  118. mpData[i] = (char32_t)pText[i];
  119. }
  120. }
  121. ea_char32_str(const ea_char32_str& str)
  122. {
  123. CopyFrom(str);
  124. }
  125. ea_char32_str& operator=(const ea_char32_str& str)
  126. {
  127. if(&str != this)
  128. {
  129. if(mpData)
  130. free(mpData);
  131. CopyFrom(str);
  132. }
  133. return *this;
  134. }
  135. void CopyFrom(const ea_char32_str& str)
  136. {
  137. mLength = str.mLength;
  138. mpData = (char32_t*)malloc((mLength + 1) * sizeof(char32_t));
  139. if(mpData)
  140. {
  141. for(size_t i = 0; i < (mLength + 1); ++i)
  142. mpData[i] = str.mpData[i];
  143. }
  144. }
  145. ~ea_char32_str()
  146. {
  147. if(mpData)
  148. free(mpData);
  149. }
  150. char32_t* mpData;
  151. size_t mLength;
  152. };
  153. char32_t* char32_convert(const wchar_t* pText);
  154. char32_t char32_convert(wchar_t character);
  155. #define EA_CHAR32(s) char32_convert(L ## s)
  156. #define EASTDCTEST_DEFINES_CHAR32
  157. #endif
  158. #endif // Header include guard