Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set (EXECUTABLE_OUTPUT_PATH ${BIN_FOLDER}/test)

include_directories(${GKIT_SOURCE_DIR}/src)
include_directories(${GKIT_SOURCE_DIR}/include)
include_directories(${GKIT_SOURCE_DIR}/test)
include_directories(${GKIT_SOURCE_DIR}/src/c_abi/include)
include_directories(${GKIT_SOURCE_DIR}/third_party/glad_generated/include)

Expand Down
14 changes: 12 additions & 2 deletions test/core/input/test_key_input.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include "./min_window_for_input_test.hpp"
#include "test_utils.hpp"

#include <core/misc/sdl_event_dispatcher.hpp>
#include <cstdint>
#include <iostream>

#include <gkit/core/input/input.hpp>

auto main() -> int {
auto test_key_input_loop() -> bool {
using gkit::input::Action;
using gkit::input::Key;
using gkit::input::KeyChord;
using gkit::input::Mod;

gkit::test::logln("=== key input interactive loop (press Ctrl+S to save, Q to quit) ===");

gkit::test::Window win;
auto& event_dispatcher = gkit::core::SDLEventDispatcher::instance();
auto& input = gkit::Input::instance();
Expand Down Expand Up @@ -46,5 +49,12 @@ auto main() -> int {
}
}

return true;
}

auto main() -> int {
auto test_runner = gkit::test::TestRunner().add_test_func(test_key_input_loop);

test_runner.run();
return 0;
}
}
19 changes: 16 additions & 3 deletions test/core/input/test_mouse_input.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include "min_window_for_input_test.hpp"
#include "./min_window_for_input_test.hpp"
#include "test_utils.hpp"

#include <core/misc/sdl_event_dispatcher.hpp>
#include <cstdint>
#include <cstdio>
#include <iostream>

#include <gkit/core/input/input.hpp>

auto main() -> int {
auto test_mouse_input_loop() -> bool {
using gkit::input::Action;
using gkit::input::Mod;
using gkit::input::MouseChord;

gkit::test::logln("=== mouse input interactive loop (press Q to quit) ===");

auto win = gkit::test::Window{};
auto& input = gkit::Input::instance();
auto& event_dispatcher = gkit::core::SDLEventDispatcher::instance();
Expand Down Expand Up @@ -68,4 +72,13 @@ auto main() -> int {
std::printf("Mouse wheel x = %f, y = %f\n", x, y);
}
}
}

return true;
}

auto main() -> int {
auto test_runner = gkit::test::TestRunner().add_test_func(test_mouse_input_loop);

test_runner.run();
return 0;
}
50 changes: 24 additions & 26 deletions test/core/reflect/test_reflect.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "gkit/core/object.hpp"
#include "gkit/core/reflect/registry.hpp"
#include "test_utils.hpp"

#include <cassert>
#include <iostream>
#include <string>


using gkit::core::Object;
using gkit::core::Value;
using gkit::core::reflect::ClassDB;
Expand Down Expand Up @@ -61,20 +63,20 @@ auto init_reflect() -> void {
// =========================================================================

auto test_regist_and_find() -> bool {
std::cout << "=== Test: regist and find ===" << '\n';
gkit::test::logln("=== Test: regist and find ===");

auto* info = ClassDB::instance().find("ReflectTestObj");
assert(info != nullptr);
assert(info->class_name == "ReflectTestObj");
std::cout << " find existing class: OK" << '\n';
gkit::test::assert_if(info != nullptr, "Class info of ReflectTestObj from ClassDB is null");
gkit::test::assert_if(info->class_name == "ReflectTestObj", "Class name is not experted");
gkit::test::logln(" find existing class: OK");

auto* info_with_raw = ClassDB::instance().find_with_raw(typeid(ReflectTestObj).name());
assert(info_with_raw != nullptr);
std::cout << " find existing class with raw name: OK" << '\n';
gkit::test::assert_if(info_with_raw != nullptr, "Failed to get ClassInfo with raw name");
gkit::test::logln(" find existing class with raw name: OK");

auto* missing = ClassDB::instance().find("NonExistent");
assert(missing == nullptr);
std::cout << " find missing class returns nullptr: OK" << '\n';
gkit::test::assert_if(missing == nullptr, "Find result is not experted(nullptr)");
gkit::test::logln(" find missing class returns nullptr: OK");
return true;
}

Expand Down Expand Up @@ -305,22 +307,18 @@ auto test_create_object() -> bool {
auto main() -> int {
init_reflect();

auto ok = true;
ok &= test_regist_and_find();
ok &= test_add_field();
ok &= test_get_field();
ok &= test_set_field();
ok &= test_readonly_property();
ok &= test_parent_inheritance();
ok &= test_for_each_field_inheritance();
ok &= test_get_field_inherited();
ok &= test_set_field_inherited();
ok &= test_create_object();

if (ok) {
std::cout << '\n' << "All tests passed." << '\n';
return 0;
}
std::cerr << '\n' << "Some tests failed." << '\n';
return 1;
auto test_runner = gkit::test::TestRunner()
.add_test_func(test_regist_and_find)
.add_test_func(test_add_field)
.add_test_func(test_get_field)
.add_test_func(test_set_field)
.add_test_func(test_readonly_property)
.add_test_func(test_parent_inheritance)
.add_test_func(test_for_each_field_inheritance)
.add_test_func(test_get_field_inherited)
.add_test_func(test_set_field_inherited)
.add_test_func(test_create_object);

test_runner.run();
return 0;
}
25 changes: 16 additions & 9 deletions test/core/test_log.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include <iostream>
#include "test_utils.hpp"

#include <cstdint>
#include <string>
#include <thread>
#include <vector>

#include <gkit/core/log.hpp>

using gkit::core::Log;

auto main() -> int {
auto test_concurrent_logging() -> bool {
gkit::test::logln("=== concurrent logging ===");

auto& logger = Log::instance();
logger.set_log_file_path("./test_log.txt");

Expand Down Expand Up @@ -35,14 +40,16 @@ auto main() -> int {
const std::uint64_t total =
static_cast<std::uint64_t>(producer_count) * static_cast<std::uint64_t>(logs_per_thread);

std::cout << "total=" << total << " enqueued=" << s.enqueued << " dropped=" << s.dropped_full
<< " processed=" << s.processed << '\n';
gkit::test::logln(" total={} enqueued={} dropped={} processed={}", total, s.enqueued, s.dropped_full, s.processed);

if (s.enqueued + s.dropped_full != total) {
std::cerr << "stats mismatch" << '\n';
return 1;
}
gkit::test::assert_if(s.enqueued + s.dropped_full == total, "stats mismatch: enqueued + dropped != total");
gkit::test::logln(" Finished logging");
return true;
}

auto main() -> int {
auto test_runner = gkit::test::TestRunner().add_test_func(test_concurrent_logging);

std::cout << "Finished logging" << '\n';
test_runner.run();
return 0;
}
28 changes: 18 additions & 10 deletions test/graphic/test_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
#include "gkit/graphic/VertexBufferLayout.hpp"
#include "graphic/backend/opengl/Texture.hpp"
#include "graphic/backend/opengl/config.hpp"
#include "test_utils.hpp"

#include <filesystem>
#include <iostream>

#include "SDL3/SDL.h"
#include <glad/gl.h>

int main(int argc, char* argv[]) {
// Get executable directory for resource paths
std::filesystem::path exe_path = argv[0];
// exe at bin/.../test/test_window.exe, go up 4 levels to reach project root
std::filesystem::path resource_base = exe_path.parent_path().parent_path().parent_path().parent_path() / "test";
namespace fs = std::filesystem;

auto test_window_render_loop() -> bool {
// Resource files live in <project>/test/graphic/, same folder as this source file
fs::path resource_base = fs::path(__FILE__).parent_path();

#pragma region Init
// Initialize SDL
if (!SDL_Init(SDL_INIT_VIDEO)) {
std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << '\n';
return 1;
return false;
}

// Request OpenGL 4.6 Core Profile
Expand All @@ -36,7 +37,7 @@ int main(int argc, char* argv[]) {
if (window == nullptr) {
std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << '\n';
SDL_Quit();
return 1;
return false;
}

// Create OpenGL context
Expand All @@ -45,7 +46,7 @@ int main(int argc, char* argv[]) {
std::cerr << "OpenGL context could not be created! SDL_Error: " << SDL_GetError() << '\n';
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
return false;
}

// Initialize GLAD
Expand All @@ -54,7 +55,7 @@ int main(int argc, char* argv[]) {
SDL_GL_DestroyContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
return false;
}

// Print OpenGL version
Expand Down Expand Up @@ -171,6 +172,13 @@ int main(int argc, char* argv[]) {
SDL_DestroyWindow(window);
SDL_Quit();

std::cout << "Window closed successfully" << '\n';
gkit::test::logln("window closed successfully");
return true;
}

auto main() -> int {
auto test_runner = gkit::test::TestRunner().add_test_func(test_window_render_loop);

test_runner.run();
return 0;
}
Loading
Loading