This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +91
-0
lines changed Expand file tree Collapse file tree 4 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 2121 run : cmake --build build --config=Debug
2222 - name : build release
2323 run : cmake --build build --config=Release
24+ - name : test debug
25+ run : cd build; ctest -C Debug
26+ - name : test release
27+ run : cd build; ctest -C Release
2428 linux-clang :
2529 runs-on : ubuntu-latest
2630 steps :
3337 run : cmake --build build --config=Debug
3438 - name : build release
3539 run : cmake --build build --config=Release
40+ - name : test debug
41+ run : cd build; ctest -C Debug
42+ - name : test release
43+ run : cd build; ctest -C Release
3644 windows-vs22 :
3745 runs-on : windows-latest
3846 steps :
4351 run : cmake --build build --config=Debug
4452 - name : build release
4553 run : cmake --build build --config=Release
54+ - name : test debug
55+ run : cd build; ctest -C Debug
56+ - name : test release
57+ run : cd build; ctest -C Release
4658 windows-clang :
4759 runs-on : windows-latest
4860 steps :
5567 run : cmake --build build --config=Debug
5668 - name : build release
5769 run : cmake --build build --config=Release
70+ - name : test debug
71+ run : cd build; ctest -C Debug
72+ - name : test release
73+ run : cd build; ctest -C Release
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.24)
33set (project_name Tkge)
44project (${project_name} )
55
6+ option (TKGE_BUILD_TESTS "Build Tkge unit tests" ${PROJECT_IS_TOP_LEVEL} )
7+
68set (CMAKE_CXX_STANDARD 23)
79set (CMAKE_CXX_STANDARD_REQUIRED ON )
810set (CMAKE_CXX_EXTENSIONS OFF )
@@ -12,3 +14,8 @@ add_subdirectory(Ext)
1214
1315add_subdirectory (Lib)
1416add_subdirectory (App)
17+
18+ if (TKGE_BUILD_TESTS)
19+ enable_testing ()
20+ add_subdirectory (Tests)
21+ endif ()
Original file line number Diff line number Diff line change 1+ project (${project_name} -Tests)
2+
3+ file (GLOB_RECURSE sources LIST_DIRECTORIES false "*.cpp" )
4+
5+ if (NOT "${sources} " STREQUAL "" )
6+ add_executable (${PROJECT_NAME} )
7+
8+ target_link_libraries (${PROJECT_NAME} PRIVATE
9+ ${project_name} ::Lib
10+ klib::klib-test -main
11+ )
12+
13+ target_include_directories (${PROJECT_NAME} PRIVATE
14+ "${CMAKE_CURRENT_SOURCE_DIR} " ,
15+ ../Lib/Src
16+ )
17+
18+ target_sources (${PROJECT_NAME} PRIVATE ${sources} )
19+
20+ add_test (NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} )
21+ endif ()
Original file line number Diff line number Diff line change 1+ #include < Tkge/Assets/TextAsset.hpp>
2+ #include < klib/unit_test.hpp>
3+ #include < filesystem>
4+ #include < fstream>
5+
6+ namespace
7+ {
8+ using namespace Tkge ;
9+
10+ struct TempFile
11+ {
12+ TempFile (const TempFile&) = delete ;
13+ TempFile (TempFile&&) = delete ;
14+ TempFile& operator =(const TempFile&) = delete ;
15+ TempFile& operator =(TempFile&&) = delete ;
16+
17+ explicit TempFile (std::string path, const std::string_view text) : _path(std::move(path))
18+ {
19+ auto file = std::ofstream{_path};
20+ ASSERT (file.is_open ());
21+ file << text;
22+ }
23+
24+ ~TempFile () { std::filesystem::remove (_path); }
25+
26+ [[nodiscard]] const std::string& GetPath () const { return _path; }
27+
28+ private:
29+ std::string _path;
30+ };
31+
32+ TEST (TextAsset_Load)
33+ {
34+ static constexpr std::string_view Text{" Hello World" };
35+
36+ const auto file = TempFile{" Test.txt" , Text};
37+
38+ auto stream = Assets::ReadonlyByteStream{file.GetPath ()};
39+ EXPECT (stream.GetStreamSize () > 0 );
40+
41+ auto asset = Assets::TextAsset{};
42+ EXPECT (asset.Load (std::move (stream)));
43+
44+ const auto & text = asset.Text ();
45+ EXPECT (text == Text);
46+ }
47+ } // namespace
You can’t perform that action at this time.
0 commit comments