Main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <threads.h>
  5. #include "Tests.h"
  6. #include "core/Logger.h"
  7. #include "core/Test.h"
  8. #include "core/Utility.h"
  9. static void finalize() {
  10. finalizeTests();
  11. printMemoryReport();
  12. }
  13. static void onExit(int code, void* data) {
  14. unsigned int i = *(unsigned int*)(data);
  15. LOG_WARNING("Hello from exit %d: %u", code, i);
  16. finalize();
  17. }
  18. static void printReport(
  19. LogLevel l, const char* file, int line, void*, const char* message) {
  20. printLog(l, file, line, "", "IGNORE: ", "%s", message);
  21. setReportHandler(nullptr, nullptr);
  22. }
  23. int main(int argAmount, const char** args) {
  24. if(argAmount >= 2 && strcmp(args[1], "help") == 0) {
  25. puts("alloc");
  26. puts("realloc");
  27. puts("pre_canary");
  28. puts("post_canary");
  29. puts("test;ignore");
  30. puts("terminal");
  31. puts("light;readLineTest");
  32. return 0;
  33. }
  34. setlocale(LC_ALL, "en_US.utf8");
  35. bool light = false;
  36. for(int i = 0; i < argAmount; i++) {
  37. if(strcmp(args[i], "light") == 0) {
  38. light = true;
  39. } else if(strcmp(args[i], "alloc") == 0) {
  40. testInvalidAllocate();
  41. } else if(strcmp(args[i], "realloc") == 0) {
  42. testInvalidReallocate();
  43. } else if(strcmp(args[i], "pre_canary") == 0) {
  44. testPreCanary();
  45. } else if(strcmp(args[i], "post_canary") == 0) {
  46. testPostCanary();
  47. } else if(strcmp(args[i], "test") == 0) {
  48. testTest();
  49. return 0;
  50. } else if(strcmp(args[i], "terminal") == 0) {
  51. testTerminal(true);
  52. finalize();
  53. return 0;
  54. } else if(strcmp(args[i], "iterminal") == 0) {
  55. testInteractiveTerminal();
  56. return 0;
  57. }
  58. }
  59. setReportHandler(printReport, nullptr);
  60. testBitArray();
  61. testBox();
  62. testBuffer(light);
  63. testComponents();
  64. testFrustum();
  65. testHashMap(light);
  66. testList(light);
  67. testMatrix();
  68. testPlane();
  69. testQuaternion();
  70. testQueue();
  71. testRandom(light);
  72. if(light) {
  73. testReadLine();
  74. }
  75. testSpinLock();
  76. testTerminal(!light);
  77. testUnicode();
  78. testUtility(light);
  79. testVector();
  80. testView();
  81. logLevel = LOG_WARNING;
  82. LOG_DEBUG("You won't see this!");
  83. logLevel = LOG_DEBUG;
  84. unsigned int data = 123'456'789;
  85. setExitHandler(onExit, &data);
  86. EXIT(1);
  87. }