test_core.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) Amer Koleci and Contributors.
  2. // Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
  3. #include <gtest/gtest.h>
  4. #include "joltc.h"
  5. class CoreTest : public ::testing::Test {
  6. protected:
  7. void SetUp() override {}
  8. void TearDown() override {}
  9. };
  10. // ============================================================================
  11. // Init/Shutdown Tests
  12. // ============================================================================
  13. TEST_F(CoreTest, Init_Shutdown) {
  14. EXPECT_TRUE(JPH_Init());
  15. JPH_Shutdown();
  16. }
  17. TEST_F(CoreTest, Init_Multiple_Times) {
  18. // First init
  19. EXPECT_TRUE(JPH_Init());
  20. JPH_Shutdown();
  21. // Second init should also work
  22. EXPECT_TRUE(JPH_Init());
  23. JPH_Shutdown();
  24. }
  25. // ============================================================================
  26. // JobSystem Tests
  27. // ============================================================================
  28. class JobSystemTest : public ::testing::Test {
  29. protected:
  30. void SetUp() override {
  31. ASSERT_TRUE(JPH_Init());
  32. }
  33. void TearDown() override {
  34. JPH_Shutdown();
  35. }
  36. };
  37. TEST_F(JobSystemTest, ThreadPool_Create_Default) {
  38. JPH_JobSystem* jobSystem = JPH_JobSystemThreadPool_Create(nullptr);
  39. ASSERT_NE(jobSystem, nullptr);
  40. JPH_JobSystem_Destroy(jobSystem);
  41. }
  42. TEST_F(JobSystemTest, ThreadPool_Create_WithConfig) {
  43. JobSystemThreadPoolConfig config = {};
  44. config.maxJobs = JPH_MAX_PHYSICS_JOBS;
  45. config.maxBarriers = JPH_MAX_PHYSICS_BARRIERS;
  46. config.numThreads = 2;
  47. JPH_JobSystem* jobSystem = JPH_JobSystemThreadPool_Create(&config);
  48. ASSERT_NE(jobSystem, nullptr);
  49. JPH_JobSystem_Destroy(jobSystem);
  50. }
  51. // ============================================================================
  52. // TraceHandler Tests
  53. // ============================================================================
  54. static bool g_traceHandlerCalled = false;
  55. static void TestTraceHandler(const char* message) {
  56. g_traceHandlerCalled = true;
  57. }
  58. TEST_F(JobSystemTest, SetTraceHandler) {
  59. g_traceHandlerCalled = false;
  60. JPH_SetTraceHandler(TestTraceHandler);
  61. // Note: We can't easily trigger a trace message, but at least we verify the function doesn't crash
  62. JPH_SetTraceHandler(nullptr);
  63. }
  64. // ============================================================================
  65. // AssertFailureHandler Tests
  66. // ============================================================================
  67. static bool g_assertHandlerCalled = false;
  68. static bool TestAssertHandler(const char* expression, const char* message, const char* file, uint32_t line) {
  69. g_assertHandlerCalled = true;
  70. return true; // Continue execution
  71. }
  72. TEST_F(JobSystemTest, SetAssertFailureHandler) {
  73. g_assertHandlerCalled = false;
  74. JPH_SetAssertFailureHandler(TestAssertHandler);
  75. // Note: We can't easily trigger an assert, but at least we verify the function doesn't crash
  76. JPH_SetAssertFailureHandler(nullptr);
  77. }