Initial ui test.

This commit is contained in:
jmsgrogan 2023-01-05 13:16:52 +00:00
parent 7fcc8e43ae
commit 36515556b8
15 changed files with 178 additions and 28 deletions

View file

@ -16,32 +16,13 @@
#include <vector>
#include <string>
void initializeCommandLineArgs(CommandLineArgs* args)
{
int nArgs{ 0 };
auto szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (szArglist == nullptr)
{
return;
}
std::vector<std::string> 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

View file

@ -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());
}
}
}

View file

@ -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<std::string> 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> CommandLineArgs::Create()
{
return std::make_unique<CommandLineArgs>();

View file

@ -26,6 +26,7 @@ public:
std::vector<std::string> getUserArgs() const;
static void initialize(CommandLineArgs* args);
private:
std::vector<std::string> mArugments;
std::filesystem::path mLaunchPath;

View file

@ -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)

View file

@ -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);
};

View file

@ -14,7 +14,19 @@ set(GRAPHICS_UNIT_TEST_FILES
PARENT_SCOPE
)
set(GRAPHICS_UNIT_TEST_DEPENDENCIES
graphics client
if(WIN32)
set(GRAPHICS_UI_TEST_FILES
graphics/TestDirectXRendering.cpp
PARENT_SCOPE
)
endif()
set(GRAPHICS_UNIT_TEST_DEPENDENCIES
graphics client
PARENT_SCOPE
)
set(GRAPHICS_UI_TEST_DEPENDENCIES
graphics client
PARENT_SCOPE
)

View file

@ -0,0 +1,18 @@
#include "TestCase.h"
#include "TestCaseRunner.h"
#include "MainApplication.h"
#include "GuiApplication.h"
#include "TestFramework.h"
#include <memory>
#include <string>
#include <iostream>
TEST_CASE(TestDirectXRendering, "graphics")
{
auto gui_app = TestCaseRunner::getInstance().getTestApplication();
gui_app->run();
};

View file

@ -1,6 +1,7 @@
#include "TestCase.h"
#include "TestCaseRunner.h"
#include "MainApplication.h"
#include "GuiApplication.h"
#include "TestFramework.h"

View file

@ -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_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)

View file

@ -18,6 +18,16 @@ TestCaseRunner::~TestCaseRunner()
}
GuiApplication* TestCaseRunner::getTestApplication()
{
return mTestApplication;
}
void TestCaseRunner::setTestApplication(GuiApplication* app)
{
mTestApplication = app;
}
TestCaseRunner& TestCaseRunner::getInstance()
{
static TestCaseRunner instance;

View file

@ -5,6 +5,8 @@
#include <vector>
#include <string>
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<std::string>& args);
void setTestApplication(GuiApplication* app);
private:
GuiApplication* mTestApplication{ nullptr };
std::vector<std::string> mFailingTests;
static bool sLastTestFailed;
static std::string sFailureLine;

View file

@ -0,0 +1,13 @@
#pragma once
#include <filesystem>
using Path = std::filesystem::path;
namespace TestDataLocations
{
static Path getTestDataDir()
{
return std::filesystem::path("${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") / "test_data";
}
}

View file

@ -1,5 +1,7 @@
#pragma once
#include "TestDataLocations.h"
#include <filesystem>
using Path = std::filesystem::path;
@ -22,6 +24,6 @@ public:
static Path getTestDataDir()
{
return std::filesystem::current_path() / "test_data";
return TestDataLocations::getTestDataDir();
}
};

60
test/ui_test_runner.cpp Normal file
View file

@ -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 <windows.h>
#endif
#include <iostream>
class TestApp : public GuiApplication
{
public:
TestApp(std::unique_ptr<CommandLineArgs> args = nullptr, std::unique_ptr<MainApplication> 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<Win32ApplicationContext>();
applicationContext->hInstance = reinterpret_cast<void*>(hInstance);
applicationContext->nCmdShow = nCmdShow;
main_app->initialize(std::move(args), std::move(applicationContext));
auto gui_app = std::make_unique<TestApp>(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;
}