This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree 5 files changed +92
-0
lines changed
5 files changed +92
-0
lines changed Original file line number Diff line number Diff line change 21
21
run : cmake --build build --config=Debug
22
22
- name : build release
23
23
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
24
28
linux-clang :
25
29
runs-on : ubuntu-latest
26
30
steps :
33
37
run : cmake --build build --config=Debug
34
38
- name : build release
35
39
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
36
44
windows-vs22 :
37
45
runs-on : windows-latest
38
46
steps :
43
51
run : cmake --build build --config=Debug
44
52
- name : build release
45
53
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
46
58
windows-clang :
47
59
runs-on : windows-latest
48
60
steps :
55
67
run : cmake --build build --config=Debug
56
68
- name : build release
57
69
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)
3
3
set (project_name Tkge)
4
4
project (${project_name} )
5
5
6
+ option (TKGE_BUILD_TESTS "Build Tkge unit tests" ${PROJECT_IS_TOP_LEVEL} )
7
+
6
8
set (CMAKE_CXX_STANDARD 23)
7
9
set (CMAKE_CXX_STANDARD_REQUIRED ON )
8
10
set (CMAKE_CXX_EXTENSIONS OFF )
@@ -12,3 +14,8 @@ add_subdirectory(Ext)
12
14
13
15
add_subdirectory (Lib)
14
16
add_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 4
4
#include < cstddef>
5
5
#include < memory>
6
6
#include < span>
7
+ #include < stdexcept>
7
8
#include < string>
8
9
9
10
namespace Tkge ::Assets
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