-
-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Add basic unittests for
CInifile
- Loading branch information
Showing
9 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(xrCore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_executable( | ||
xrCoreTests | ||
main.cpp | ||
xr_ini_test.cpp) | ||
|
||
target_link_libraries(xrCoreTests xrCore doctest::doctest) | ||
target_include_directories(xrCoreTests PRIVATE "${CMAKE_SOURCE_DIR}/src") | ||
add_test(NAME xrCoreTests COMMAND xrCoreTests) | ||
# https://github.com/doctest/doctest/blob/master/doc/markdown/configuration.md | ||
target_compile_definitions(xrCoreTests PRIVATE | ||
DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING | ||
DOCTEST_CONFIG_SUPER_FAST_ASSERTS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT | ||
#include <doctest/doctest.h> | ||
|
||
#include <Common/Platform.hpp> | ||
#include <xrCore/xrCore.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
doctest::Context context; | ||
context.applyCommandLine(argc, argv); | ||
|
||
Memory._initialize(); | ||
|
||
return context.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <doctest/doctest.h> | ||
|
||
#include <Common/Platform.hpp> | ||
#include <xrCore/xrCore.h> | ||
#include <xrCore/xr_types.h> | ||
|
||
#include <xrCore/xr_ini.h> | ||
|
||
CInifile read_from_string(pcstr str, CInifile::allow_include_func_t allow_include = nullptr) | ||
{ | ||
IReader reader = IReader(const_cast<pstr>(str), xr_strlen(str)); | ||
return CInifile(&reader, "test.ini", allow_include); | ||
} | ||
|
||
TEST_CASE("parse empty file") | ||
{ | ||
CInifile ini = read_from_string(""); | ||
|
||
CHECK_EQ(ini.section_count(), 0); | ||
} | ||
|
||
TEST_CASE("parse empty section") | ||
{ | ||
CInifile ini = read_from_string("[a]"); | ||
|
||
CHECK_EQ(ini.section_count(), 1); | ||
CHECK_UNARY(ini.section_exist("a")); | ||
} | ||
|
||
TEST_CASE("parse simple section") | ||
{ | ||
CInifile ini = read_from_string( | ||
R"ini( | ||
[a] | ||
key = value | ||
)ini"); | ||
|
||
CHECK_UNARY(ini.section_exist("a")); | ||
CHECK_UNARY(ini.line_exist("a", "key")); | ||
CHECK_EQ(ini.read<pcstr>("a", "key"), "value"); | ||
} | ||
|
||
TEST_CASE("parse integer value") | ||
{ | ||
CInifile ini = read_from_string( | ||
R"ini( | ||
[a] | ||
key = 123 | ||
)ini"); | ||
|
||
CHECK_UNARY(ini.section_exist("a")); | ||
CHECK_UNARY(ini.line_exist("a", "key")); | ||
CHECK_EQ(ini.read<u32>("a", "key"), 123); | ||
} | ||
|
||
TEST_CASE("Parse float value") | ||
{ | ||
CInifile ini = read_from_string( | ||
R"ini( | ||
[a] | ||
key = 123.456 | ||
)ini"); | ||
|
||
CHECK_UNARY(ini.section_exist("a")); | ||
CHECK_UNARY(ini.line_exist("a", "key")); | ||
CHECK_EQ(ini.read<f32>("a", "key"), 123.456f); | ||
} | ||
|
||
TEST_CASE("Parse quoted value") | ||
{ | ||
CInifile ini = read_from_string( | ||
R"ini( | ||
[a] | ||
key = "value" | ||
)ini"); | ||
|
||
CHECK_UNARY(ini.section_exist("a")); | ||
CHECK_UNARY(ini.line_exist("a", "key")); | ||
CHECK_EQ(ini.read<pcstr>("a", "key"), "\"value\""); | ||
} | ||
|
||
TEST_CASE("Parse multiline value") | ||
{ | ||
CInifile ini = read_from_string( | ||
R"ini( | ||
[a] | ||
key = "multiline | ||
value" | ||
)ini"); | ||
|
||
CHECK_UNARY(ini.section_exist("a")); | ||
CHECK_UNARY(ini.line_exist("a", "key")); | ||
CHECK_EQ(ini.read<pcstr>("a", "key"), "\"multiline\r\nvalue\""); | ||
} |