Эх сурвалжийг харах

Move window tests into own file

Kajetan Johannes Hammerle 11 сар өмнө
parent
commit
e6ae238a1f
4 өөрчлөгдсөн 59 нэмэгдсэн , 53 устгасан
  1. 1 0
      CMakeLists.txt
  2. 2 52
      test/Main.c
  3. 2 1
      test/Tests.h
  4. 54 0
      test/modules/WindowTests.c

+ 1 - 0
CMakeLists.txt

@@ -15,6 +15,7 @@ set(SRC_TESTS
     "test/Main.c"
     "test/modules/ImageTests.c"
     "test/modules/NetworkTests.c"
+    "test/modules/WindowTests.c"
 )
 
 if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")

+ 2 - 52
test/Main.c

@@ -1,64 +1,14 @@
 #define IMPORT_CORE
-#include <GLFW/glfw3.h>
 #include <core/Logger.h>
 #include <core/Utility.h>
-#include <stdio.h>
 #include <string.h>
 
 #include "Tests.h"
-#include "core/Window.h"
-
-static int ticks = 200;
-static Button closeButton = 0;
-static Button testButton = 0;
-
-static bool isRunning(void*) {
-    return !shouldWindowClose() && ticks > 0 && !coreControlsDown(closeButton);
-}
-
-static void tick(void*) {
-    ticks -= ticks > 0;
-    printf("TPS: %.3f\nFPS: %.3f\n", (double)getWindowTicksPerSecond(),
-           (double)getWindowFramesPerSecond());
-    printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
-           coreControlsName(closeButton), coreControlsDown(closeButton),
-           coreControlsDownTime(closeButton),
-           coreControlsReleased(closeButton));
-    printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
-           coreControlsName(testButton), coreControlsDown(testButton),
-           coreControlsDownTime(testButton), coreControlsReleased(testButton));
-
-    Vector2 mouse = coreControlsLastMousePosition();
-    printf("Mouse: %.2f %.2f\n", (double)mouse.data[0], (double)mouse.data[1]);
-}
-
-static void render(void*, float) {
-}
-
-static void testWindow(void) {
-    WindowOptions options = {{{800, 480}}, false, "Test"};
-    if(openWindow(&options)) {
-        return;
-    }
-
-    closeButton = coreControlsAdd("Close Button");
-    coreControlsBindKey(closeButton, GLFW_KEY_Q);
-    testButton = coreControlsAdd("Test Button");
-    coreControlsBindKey(testButton, GLFW_KEY_T);
-
-    showWindow();
-    setWindowRunHandler(isRunning, nullptr);
-    setWindowTickHandler(tick, nullptr);
-    setWindowRenderHandler(render, nullptr);
-    setWindowNanosPerTick(50000000);
-    runWindow();
-    closeWindow();
-}
 
 int main(int argAmount, char** args) {
     (void)args;
     if(argAmount < 3) {
-        CORE_LOG_ERROR("missing path to images and/or mode");
+        LOG_ERROR("missing path to images and/or mode");
         return 0;
     } else if(strcmp("test", args[2]) == 0) {
         testImageReader(args[1]);
@@ -67,6 +17,6 @@ int main(int argAmount, char** args) {
         testWindow();
     }
     finalizeTests();
-    corePrintMemoryReport();
+    printMemoryReport();
     return 0;
 }

+ 2 - 1
test/Tests.h

@@ -3,7 +3,8 @@
 
 #include "core/Test.h"
 
-void testNetwork(void);
 void testImageReader(const char* path);
+void testNetwork(void);
+void testWindow(void);
 
 #endif

+ 54 - 0
test/modules/WindowTests.c

@@ -0,0 +1,54 @@
+#define IMPORT_CORE
+#include <GLFW/glfw3.h>
+#include <core/Logger.h>
+#include <stdio.h>
+
+#include "../Tests.h"
+#include "core/Window.h"
+
+static int ticks = 200;
+static Button closeButton = 0;
+static Button testButton = 0;
+
+static bool isRunning(void*) {
+    return !shouldWindowClose() && ticks > 0 && !coreControlsDown(closeButton);
+}
+
+static void tick(void*) {
+    ticks -= ticks > 0;
+    printf("TPS: %.3f\nFPS: %.3f\n", (double)getWindowTicksPerSecond(),
+           (double)getWindowFramesPerSecond());
+    printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
+           coreControlsName(closeButton), coreControlsDown(closeButton),
+           coreControlsDownTime(closeButton),
+           coreControlsReleased(closeButton));
+    printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
+           coreControlsName(testButton), coreControlsDown(testButton),
+           coreControlsDownTime(testButton), coreControlsReleased(testButton));
+
+    Vector2 mouse = coreControlsLastMousePosition();
+    printf("Mouse: %.2f %.2f\n", (double)mouse.data[0], (double)mouse.data[1]);
+}
+
+static void render(void*, float) {
+}
+
+void testWindow(void) {
+    WindowOptions options = {{{800, 480}}, false, "Test"};
+    if(openWindow(&options)) {
+        return;
+    }
+
+    closeButton = coreControlsAdd("Close Button");
+    coreControlsBindKey(closeButton, GLFW_KEY_Q);
+    testButton = coreControlsAdd("Test Button");
+    coreControlsBindKey(testButton, GLFW_KEY_T);
+
+    showWindow();
+    setWindowRunHandler(isRunning, nullptr);
+    setWindowTickHandler(tick, nullptr);
+    setWindowRenderHandler(render, nullptr);
+    setWindowNanosPerTick(50000000);
+    runWindow();
+    closeWindow();
+}