EAStdCTest.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #if defined(_MSC_VER)
  5. #pragma warning (disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  6. #endif
  7. #include <EAStdC/internal/Config.h>
  8. #include <EAStdC/EAStdC.h>
  9. #include <EAStdC/EAStopwatch.h>
  10. #include <EAStdC/version.h>
  11. #include <EAStdCTest/EAStdCTest.h>
  12. #include <EATest/EATest.h>
  13. #include <EATest/EAMissingImpl.inl>
  14. #include <EAMain/EAEntryPointMain.inl>
  15. #include <new>
  16. #if defined(EASTDCTEST_DEFINES_CHAR16)
  17. char16_t* char16_convert(const wchar_t* pText)
  18. {
  19. typedef eastl::map<const wchar_t*, ea_char16_str> WChar16Map; // Map of wchar_t* to char16_t*
  20. static WChar16Map sTable; // Not thread safe.
  21. ea_char16_str s = ea_char16_str(pText);
  22. eastl::pair<WChar16Map::iterator, bool> result = sTable.insert(eastl::make_pair(pText, s));
  23. return result.first->second.mpData;
  24. }
  25. char16_t char16_convert(wchar_t c)
  26. {
  27. return (char16_t)c;
  28. }
  29. #endif
  30. #if defined(EASTDCTEST_DEFINES_CHAR32)
  31. char32_t* char32_convert(const wchar_t* pText)
  32. {
  33. typedef eastl::map<const wchar_t*, ea_char32_str> WChar32Map; // Map of wchar_t* to char32_t*
  34. static WChar32Map sTable; // Not thread safe.
  35. ea_char32_str s = ea_char32_str(pText);
  36. eastl::pair<WChar32Map::iterator, bool> result = sTable.insert(eastl::make_pair(pText, s));
  37. return result.first->second.mpData;
  38. }
  39. char32_t char32_convert(wchar_t character)
  40. {
  41. return (char32_t)character;
  42. }
  43. #endif
  44. // EASTDC_STOPWATCH_DISABLE_CPU_CALIBRATION test
  45. //
  46. // It might be useful to test this macro under some circumstances, but doing
  47. // so (intentionally) causes the CPU cycle-based timing to not work. So we'd
  48. // have to disable those tests if we want to test this macro.
  49. //
  50. //#if defined(_MSC_VER)
  51. // #pragma warning(disable: 4074)
  52. // #pragma init_seg(compiler)
  53. //#endif
  54. //
  55. //EASTDC_STOPWATCH_DISABLE_CPU_CALIBRATION()
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // operator new
  58. //
  59. // EASTL requires some of the following new operators to be defined, while
  60. // various platform SDKs require others.
  61. ///////////////////////////////////////////////////////////////////////////////
  62. void* operator new(size_t size, const char*, int, unsigned, const char*, int)
  63. {
  64. return ::operator new(size);
  65. }
  66. void* operator new[](size_t size, const char*, int, unsigned, const char*, int)
  67. {
  68. return ::operator new[](size);
  69. }
  70. void* operator new[](size_t size, size_t, size_t, const char*, int, unsigned, const char*, int)
  71. {
  72. return ::operator new[](size);
  73. }
  74. void* operator new(size_t size, size_t /*alignment*/, size_t /*alignmentOffset*/, const char* /*name*/,
  75. int /*flags*/, unsigned /*debugFlags*/, const char* /*file*/, int /*line*/)
  76. {
  77. // We will have a problem if alignment is non-default.
  78. return ::operator new(size);
  79. }
  80. void operator delete(void* p, size_t, size_t, const char*, int, unsigned, const char*, int)
  81. {
  82. if (p)
  83. ::operator delete(p);
  84. }
  85. void operator delete(void* p, char const*, int, unsigned, char const*, int)
  86. {
  87. if (p)
  88. ::operator delete(p);
  89. }
  90. #if !defined(EA_STDCTEST_ENABLE_NEW_REPLACEMENT)
  91. #define EA_STDCTEST_ENABLE_NEW_REPLACEMENT 0
  92. #endif
  93. #if EA_STDCTEST_ENABLE_NEW_REPLACEMENT
  94. void* operator new (size_t size, const ::std::nothrow_t&) EA_THROW_SPEC_NEW_NONE()
  95. {
  96. return malloc(size);
  97. }
  98. void* operator new[] (size_t size, const ::std::nothrow_t&) EA_THROW_SPEC_NEW_NONE()
  99. {
  100. return malloc(size);
  101. }
  102. void* operator new[] (size_t size) EA_THROW_SPEC_NEW(std::bad_alloc)
  103. {
  104. return malloc(size);
  105. }
  106. void* operator new (size_t size) EA_THROW_SPEC_NEW(std::bad_alloc)
  107. {
  108. return malloc(size);
  109. }
  110. void operator delete (void* p) EA_THROW_SPEC_DELETE_NONE()
  111. {
  112. if (p)
  113. free(p);
  114. }
  115. void operator delete[] (void* p) EA_THROW_SPEC_DELETE_NONE()
  116. {
  117. if (p)
  118. free(p);
  119. }
  120. #endif
  121. // On some Sony platforms, you must explicitly set the LibC heap size. Because the EAStdC
  122. // tests use direct calls to the LibC memory functions, we cannot get around this.
  123. // This sets the LibC heap size to 128MB.
  124. #if defined(EA_PLATFORM_SONY)
  125. size_t sceLibcHeapSize = 128*1024*1024;
  126. #endif
  127. ///////////////////////////////////////////////////////////////////////////////
  128. // EAMain
  129. //
  130. int EAMain(int argc, char** argv)
  131. {
  132. using namespace EA::UnitTest;
  133. EA::EAMain::PlatformStartup();
  134. EA::StdC::Init();
  135. // Add the tests
  136. TestApplication testSuite("EAStdC Unit Tests", argc, argv);
  137. testSuite.AddTest("Callback", TestCallback);
  138. testSuite.AddTest("String", TestString);
  139. testSuite.AddTest("Sprintf", TestSprintf);
  140. testSuite.AddTest("Random", TestRandom);
  141. testSuite.AddTest("TextUtil", TestTextUtil);
  142. testSuite.AddTest("Scanf", TestScanf);
  143. testSuite.AddTest("Memory", TestMemory);
  144. testSuite.AddTest("Endian", TestEndian);
  145. testSuite.AddTest("DateTime", TestDateTime);
  146. testSuite.AddTest("Singleton", TestSingleton);
  147. testSuite.AddTest("Process", TestProcess);
  148. testSuite.AddTest("Stopwatch", TestStopwatch);
  149. testSuite.AddTest("CType", TestCType);
  150. testSuite.AddTest("BitTricks", TestBitTricks);
  151. testSuite.AddTest("Alignment", TestAlignment);
  152. testSuite.AddTest("ByteCrackers", TestByteCrackers);
  153. testSuite.AddTest("FixedPoint", TestFixedPoint);
  154. testSuite.AddTest("Hash", TestHash);
  155. testSuite.AddTest("Global", TestGlobal);
  156. testSuite.AddTest("MathHelp", TestMathHelp);
  157. testSuite.AddTest("Int128", TestInt128);
  158. // Parse command line arguments
  159. const int testResult = testSuite.Run();
  160. EA::StdC::Shutdown();
  161. EA::EAMain::PlatformShutdown(testResult);
  162. return testResult;
  163. }