diff --git a/apps/notes_tk/main-win.cpp b/apps/notes_tk/main-win.cpp index 1dac674..30019cc 100644 --- a/apps/notes_tk/main-win.cpp +++ b/apps/notes_tk/main-win.cpp @@ -16,32 +16,13 @@ #include #include -void initializeCommandLineArgs(CommandLineArgs* args) -{ - int nArgs{ 0 }; - auto szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); - if (szArglist == nullptr) - { - return; - } - - std::vector windowsArgs(nArgs); - for (int idx = 0; idx < nArgs; idx++) - { - windowsArgs[idx] = StringUtils::convert(szArglist[idx]); - } - LocalFree(szArglist); - - args->process(windowsArgs); -} - int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { std::ofstream out("out.txt"); std::cout.rdbuf(out.rdbuf()); auto args = CommandLineArgs::Create(); - initializeCommandLineArgs(args.get()); + CommandLineArgs::initialize(args.get()); args->recordLaunchPath(); // Start the main app diff --git a/apps/website-generator/ContentFile.cpp b/apps/website-generator/ContentFile.cpp index aedd0b1..2d00b80 100644 --- a/apps/website-generator/ContentFile.cpp +++ b/apps/website-generator/ContentFile.cpp @@ -50,7 +50,7 @@ void ContentFile::doLinkTagSubstitution(const Path& basePath) auto full_path = mFilename.parent_path() / Path(replaced_target); auto base_relative_path = PathUtils::getRelativePath(full_path, basePath); auto output_path = PathUtils::getPathDelimited(base_relative_path); - link->setTarget(Path(output_path).replace_extension(".html")); + link->setTarget(Path(output_path).replace_extension(".html").string()); } } } diff --git a/src/core/CommandLineArgs.cpp b/src/core/CommandLineArgs.cpp index 9942b78..ed83f7f 100644 --- a/src/core/CommandLineArgs.cpp +++ b/src/core/CommandLineArgs.cpp @@ -1,5 +1,10 @@ #include "CommandLineArgs.h" +#include "StringUtils.h" +#ifdef _WIN32 +#include "Windows.h" +#endif + CommandLineArgs::CommandLineArgs() : mArugments(), mLaunchPath() @@ -7,6 +12,27 @@ CommandLineArgs::CommandLineArgs() } +void CommandLineArgs::initialize(CommandLineArgs* args) +{ +#ifdef _WIN32 + int nArgs{ 0 }; + auto szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &nArgs); + if (szArglist == nullptr) + { + return; + } + + std::vector windowsArgs(nArgs); + for (int idx = 0; idx < nArgs; idx++) + { + windowsArgs[idx] = StringUtils::convert(szArglist[idx]); + } + ::LocalFree(szArglist); + + args->process(windowsArgs); +#endif +} + std::unique_ptr CommandLineArgs::Create() { return std::make_unique(); diff --git a/src/core/CommandLineArgs.h b/src/core/CommandLineArgs.h index 3549e0b..8bf15a0 100644 --- a/src/core/CommandLineArgs.h +++ b/src/core/CommandLineArgs.h @@ -26,6 +26,7 @@ public: std::vector getUserArgs() const; + static void initialize(CommandLineArgs* args); private: std::vector mArugments; std::filesystem::path mLaunchPath; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3828f1f..3ee2e80 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,10 +26,20 @@ foreach(module ${TEST_MODULES}) list(APPEND INTEGRATION_TEST_FILES ${${MODULE_UPPER}_INTEGRATION_TEST_FILES}) list(APPEND INTEGRATION_TEST_DEPENDENCIES ${${MODULE_UPPER}_INTEGRATION_TEST_DEPENDENCIES}) + + list(APPEND UI_TEST_FILES ${${MODULE_UPPER}_UI_TEST_FILES}) + list(APPEND UI_TEST_DEPENDENCIES ${${MODULE_UPPER}_UI_TEST_DEPENDENCIES}) endforeach() add_executable(unit_tests test_runner.cpp ${UNIT_TEST_FILES}) target_link_libraries(unit_tests PUBLIC test_utils ${UNIT_TEST_DEPENDENCIES}) +set_property(TARGET unit_tests PROPERTY FOLDER test) add_executable(integration_tests test_runner.cpp ${INTEGRATION_TEST_FILES}) target_link_libraries(integration_tests PUBLIC test_utils ${INTEGRATION_TEST_DEPENDENCIES}) +set_property(TARGET integration_tests PROPERTY FOLDER test) + +add_executable(ui_tests WIN32 ui_test_runner.cpp ${UI_TEST_FILES}) +target_link_libraries(ui_tests PUBLIC test_utils ${UI_TEST_DEPENDENCIES}) +set_property(TARGET ui_tests PROPERTY FOLDER test) + diff --git a/test/audio/integration/TestWasapiInterface.cpp b/test/audio/integration/TestWasapiInterface.cpp index cdd3f3f..cc505b5 100644 --- a/test/audio/integration/TestWasapiInterface.cpp +++ b/test/audio/integration/TestWasapiInterface.cpp @@ -3,11 +3,16 @@ #include "AudioSample.h" #include "AudioSynth.h" +#include "AudioDevice.h" #include "WasapiInterface.h" TEST_CASE(TestWasapiInterface, "audio") { WasapiInterface audio_interface; auto device = AudioDevice::Create(); - audio_interface.Play(device); + + AudioSynth synth; + const auto sample = synth.getSineWave(240, 5); + + audio_interface.play(device.get(), sample.get(), 1000); }; diff --git a/test/graphics/CMakeLists.txt b/test/graphics/CMakeLists.txt index 9b82d05..6fe0826 100644 --- a/test/graphics/CMakeLists.txt +++ b/test/graphics/CMakeLists.txt @@ -13,8 +13,20 @@ set(GRAPHICS_UNIT_TEST_FILES ${PLATFORM_UNIT_TEST_FILES} PARENT_SCOPE ) + +if(WIN32) +set(GRAPHICS_UI_TEST_FILES + graphics/TestDirectXRendering.cpp + PARENT_SCOPE + ) +endif() set(GRAPHICS_UNIT_TEST_DEPENDENCIES graphics client - PARENT_SCOPE + PARENT_SCOPE + ) + +set(GRAPHICS_UI_TEST_DEPENDENCIES + graphics client + PARENT_SCOPE ) \ No newline at end of file diff --git a/test/graphics/TestDirectXRendering.cpp b/test/graphics/TestDirectXRendering.cpp new file mode 100644 index 0000000..dce3a6c --- /dev/null +++ b/test/graphics/TestDirectXRendering.cpp @@ -0,0 +1,18 @@ +#include "TestCase.h" +#include "TestCaseRunner.h" + +#include "MainApplication.h" +#include "GuiApplication.h" + +#include "TestFramework.h" + +#include +#include +#include + +TEST_CASE(TestDirectXRendering, "graphics") +{ + auto gui_app = TestCaseRunner::getInstance().getTestApplication(); + + gui_app->run(); +}; \ No newline at end of file diff --git a/test/graphics/TestOpenGlRendering.cpp b/test/graphics/TestOpenGlRendering.cpp index 2ec2c11..e71c63c 100644 --- a/test/graphics/TestOpenGlRendering.cpp +++ b/test/graphics/TestOpenGlRendering.cpp @@ -1,6 +1,7 @@ #include "TestCase.h" #include "TestCaseRunner.h" +#include "MainApplication.h" #include "GuiApplication.h" #include "TestFramework.h" diff --git a/test/test_utils/CMakeLists.txt b/test/test_utils/CMakeLists.txt index 7d26da5..57110bb 100644 --- a/test/test_utils/CMakeLists.txt +++ b/test/test_utils/CMakeLists.txt @@ -1,9 +1,13 @@ add_library(test_utils STATIC TestCase.h + TestUtils.h + TestCaseRunner.h + TestFramework.h TestCaseRunner.cpp ) -target_include_directories(test_utils PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - ) -target_link_libraries(test_utils core) \ No newline at end of file +target_include_directories(test_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(test_utils core) +set_property(TARGET test_utils PROPERTY FOLDER test) + +configure_file(TestDataLocations.h.in TestDataLocations.h) \ No newline at end of file diff --git a/test/test_utils/TestCaseRunner.cpp b/test/test_utils/TestCaseRunner.cpp index 8042865..1519b00 100644 --- a/test/test_utils/TestCaseRunner.cpp +++ b/test/test_utils/TestCaseRunner.cpp @@ -18,6 +18,16 @@ TestCaseRunner::~TestCaseRunner() } +GuiApplication* TestCaseRunner::getTestApplication() +{ + return mTestApplication; +} + +void TestCaseRunner::setTestApplication(GuiApplication* app) +{ + mTestApplication = app; +} + TestCaseRunner& TestCaseRunner::getInstance() { static TestCaseRunner instance; diff --git a/test/test_utils/TestCaseRunner.h b/test/test_utils/TestCaseRunner.h index 029aa51..05802ab 100644 --- a/test/test_utils/TestCaseRunner.h +++ b/test/test_utils/TestCaseRunner.h @@ -5,6 +5,8 @@ #include #include +class GuiApplication; + class TestCaseRunner { public: @@ -14,13 +16,18 @@ public: ~TestCaseRunner(); + GuiApplication* getTestApplication(); + void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func); void markTestFailure(const std::string& line); bool run(const std::vector& args); + void setTestApplication(GuiApplication* app); private: + + GuiApplication* mTestApplication{ nullptr }; std::vector mFailingTests; static bool sLastTestFailed; static std::string sFailureLine; diff --git a/test/test_utils/TestDataLocations.h.in b/test/test_utils/TestDataLocations.h.in new file mode 100644 index 0000000..427aa13 --- /dev/null +++ b/test/test_utils/TestDataLocations.h.in @@ -0,0 +1,13 @@ +#pragma once + +#include + +using Path = std::filesystem::path; + +namespace TestDataLocations +{ + static Path getTestDataDir() + { + return std::filesystem::path("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") / "test_data"; + } +} \ No newline at end of file diff --git a/test/test_utils/TestUtils.h b/test/test_utils/TestUtils.h index fc3d946..43e0ab8 100644 --- a/test/test_utils/TestUtils.h +++ b/test/test_utils/TestUtils.h @@ -1,5 +1,7 @@ #pragma once +#include "TestDataLocations.h" + #include using Path = std::filesystem::path; @@ -22,6 +24,6 @@ public: static Path getTestDataDir() { - return std::filesystem::current_path() / "test_data"; + return TestDataLocations::getTestDataDir(); } }; diff --git a/test/ui_test_runner.cpp b/test/ui_test_runner.cpp new file mode 100644 index 0000000..5714422 --- /dev/null +++ b/test/ui_test_runner.cpp @@ -0,0 +1,60 @@ +#include "TestFramework.h" + +#include "CommandLineArgs.h" +#include "MainApplication.h" +#include "GuiApplication.h" +#include "Widget.h" + +#ifdef _WIN32 +#include "Win32WindowInterface.h" +#include +#endif + +#include + +class TestApp : public GuiApplication +{ +public: + TestApp(std::unique_ptr args = nullptr, std::unique_ptr mainApp = nullptr) + : GuiApplication(std::move(args), std::move(mainApp)) + { + + } +}; + +#ifdef _WIN32 +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) +{ + std::ofstream out("out.txt"); + std::cout.rdbuf(out.rdbuf()); + + CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + auto args = CommandLineArgs::Create(); + CommandLineArgs::initialize(args.get()); + + auto main_app = MainApplication::Create(); + + auto applicationContext = std::make_unique(); + applicationContext->hInstance = reinterpret_cast(hInstance); + applicationContext->nCmdShow = nCmdShow; + + main_app->initialize(std::move(args), std::move(applicationContext)); + + auto gui_app = std::make_unique(nullptr, std::move(main_app)); + +#else +int main(int argc, char *argv[]) +{ + auto args = CommandLineArgs::Create(); + args->process(argc, argv); +#endif + + TestCaseRunner::getInstance().setTestApplication(gui_app.get()); + auto result = TestCaseRunner::getInstance().run({}); + +#ifdef _WIN32 + CoUninitialize(); +#endif + return 0; +}