Skip to content

Commit 55d3476

Browse files
committed
update tests
1 parent 02cbe49 commit 55d3476

12 files changed

+175
-74
lines changed

CMakeLists.txt

+26-26
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ set(_7BIT_CONF_LIBRARY 7bitConf)
44

55
set(_7BIT_CONF_VERSION_MAJOR 1)
66
set(_7BIT_CONF_VERSION_MINOR 2)
7-
set(_7BIT_CONF_VERSION_PATCH 1)
7+
set(_7BIT_CONF_VERSION_PATCH 0)
88

99
set(_7BIT_CONF_VERSION ${_7BIT_CONF_VERSION_MAJOR}.${_7BIT_CONF_VERSION_MINOR}.${_7BIT_CONF_VERSION_PATCH})
1010

1111
project(${_7BIT_CONF_LIBRARY} LANGUAGES CXX VERSION ${_7BIT_CONF_VERSION})
1212

1313
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Cmake")
1414

15-
if(NOT CMAKE_CXX_STANDARD)
15+
if (NOT CMAKE_CXX_STANDARD)
1616
set(CMAKE_CXX_STANDARD 17)
17-
endif()
17+
endif ()
1818

1919
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020

@@ -26,21 +26,21 @@ include_directories(${_7BIT_CONF_INCLUDE_DIR})
2626

2727
add_subdirectory(Source)
2828

29-
if(_7BIT_CONF_BUILD_UNIT_TESTS OR _7BIT_CONF_BUILD_INTEGRATION_TESTS OR _7BIT_CONF_BUILD_E2E_TESTS)
29+
if (_7BIT_CONF_BUILD_UNIT_TESTS OR _7BIT_CONF_BUILD_INTEGRATION_TESTS OR _7BIT_CONF_BUILD_E2E_TESTS)
3030
enable_testing()
3131

3232
add_subdirectory(Tests)
33-
endif()
33+
endif ()
3434

35-
if(_7BIT_CONF_BUILD_EXAMPLES)
35+
if (_7BIT_CONF_BUILD_EXAMPLES)
3636
add_subdirectory(Examples)
37-
endif()
37+
endif ()
3838

39-
if(_7BIT_CONF_BUILD_SINGLE_HEADER)
39+
if (_7BIT_CONF_BUILD_SINGLE_HEADER)
4040
add_subdirectory(SingleHeader)
41-
endif()
41+
endif ()
4242

43-
if(_7BIT_CONF_INSTALL)
43+
if (_7BIT_CONF_INSTALL)
4444
set(PROJECT_CONFIG_IN ${CMAKE_CURRENT_SOURCE_DIR}/Cmake/7bitConfConfig.cmake.in)
4545
set(PROJECT_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/7bitConfConfig.cmake)
4646
set(CONFIG_TARGETS_FILE 7bitConfConfigTargets.cmake)
@@ -50,29 +50,29 @@ if(_7BIT_CONF_INSTALL)
5050
install(DIRECTORY ${_7BIT_CONF_INCLUDE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
5151

5252
install(
53-
TARGETS 7bitConf
54-
EXPORT 7bitConf
55-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
56-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
57-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
53+
TARGETS 7bitConf
54+
EXPORT 7bitConf
55+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
56+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
57+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
5858

5959
export(
60-
TARGETS 7bitConf
61-
NAMESPACE 7bitConf::
62-
FILE ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_TARGETS_FILE})
60+
TARGETS 7bitConf
61+
NAMESPACE 7bitConf::
62+
FILE ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_TARGETS_FILE})
6363

6464
install(
65-
EXPORT 7bitConf
66-
EXPORT 7bitConf
67-
DESTINATION ${EXPORT_DEST_DIR}
68-
NAMESPACE 7bitConf::
69-
NAMESPACE 7bitConf::
70-
FILE ${CONFIG_TARGETS_FILE})
65+
EXPORT 7bitConf
66+
EXPORT 7bitConf
67+
DESTINATION ${EXPORT_DEST_DIR}
68+
NAMESPACE 7bitConf::
69+
NAMESPACE 7bitConf::
70+
FILE ${CONFIG_TARGETS_FILE})
7171

7272
include(CMakePackageConfigHelpers)
7373

7474
configure_package_config_file(${PROJECT_CONFIG_IN} ${PROJECT_CONFIG_OUT}
75-
INSTALL_DESTINATION ${EXPORT_DEST_DIR})
75+
INSTALL_DESTINATION ${EXPORT_DEST_DIR})
7676

7777
write_basic_package_version_file(${VERSIONS_CONFIG_FILE} COMPATIBILITY SameMajorVersion)
7878

@@ -81,4 +81,4 @@ if(_7BIT_CONF_INSTALL)
8181
export(PACKAGE 7bitConf)
8282

8383
include(CPack)
84-
endif()
84+
endif ()

Include/SevenBit/Conf/Details/DefaultDeserializers.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
#include "SevenBit/Conf/LibraryConfig.hpp"
44

55
#include "SevenBit/Conf/Details/Deserializers.hpp"
6+
#include "SevenBit/Conf/Details/ValueDeserializersMap.hpp"
67

78
namespace sb::cf::details
89
{
910
struct DefaultDeserializers
1011
{
1112
static void add(std::vector<std::pair<std::string_view, IDeserializer::Ptr>> &deserializers);
13+
14+
static void add(ValueDeserializersMap &deserializersMap);
1215
};
13-
} // namespace sb::cf
16+
} // namespace sb::cf::details
1417

1518
#ifdef _7BIT_CONF_ADD_IMPL
1619
#include "SevenBit/Conf/Details/Impl/DefaultDeserializers.hpp"

Include/SevenBit/Conf/Details/Impl/DefaultDeserializers.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ namespace sb::cf::details
1515
deserializers.emplace_back("null", std::make_unique<details::NullDeserializer>());
1616
}
1717

18+
INLINE void DefaultDeserializers::add(ValueDeserializersMap &deserializersMap)
19+
{
20+
std::vector<std::pair<std::string_view, IDeserializer::Ptr>> deserializers;
21+
add(deserializers);
22+
for (auto &[type, deserializer] : deserializers)
23+
{
24+
deserializersMap.set(type, std::move(deserializer));
25+
}
26+
}
27+
1828
} // namespace sb::cf::details

Include/SevenBit/Conf/Details/Impl/StringUtils.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ namespace sb::cf::details
8989
return it - str.begin();
9090
}
9191

92-
INLINE bool StringUtils::isWhiteSpace(std::string_view str) { return startsWithWhiteSpace(str) == str.size(); }
92+
INLINE bool StringUtils::isWhiteSpace(std::string_view str)
93+
{
94+
return !str.empty() && startsWithWhiteSpace(str) == str.size();
95+
}
9396

9497
INLINE std::vector<std::string_view> StringUtils::split(std::string_view str, std::string_view separator)
9598
{

Include/SevenBit/Conf/Details/JsonExt.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ namespace sb::cf::details
7575
} // namespace sb::cf::details
7676

7777
#ifdef _7BIT_CONF_ADD_IMPL
78-
#include "SevenBit/Conf/Details/Impl/JsonObjectExt.hpp"
78+
#include "SevenBit/Conf/Details/Impl/JsonExt.hpp"
7979
#endif

Source/Source.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "SevenBit/Conf/Details/Impl/DefaultDeserializers.hpp"
77
#include "SevenBit/Conf/Details/Impl/Deserializers.hpp"
88
#include "SevenBit/Conf/Details/Impl/EnvironmentVarsParser.hpp"
9-
#include "SevenBit/Conf/Details/Impl/JsonObjectExt.hpp"
9+
#include "SevenBit/Conf/Details/Impl/JsonExt.hpp"
1010
#include "SevenBit/Conf/Details/Impl/SettingSplitter.hpp"
1111
#include "SevenBit/Conf/Details/Impl/StringUtils.hpp"
1212
#include "SevenBit/Conf/Details/Impl/ValueDeserializersMap.hpp"
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <gtest/gtest.h>
2+
#include <iostream>
3+
4+
#include "SevenBit/Conf/Details/ContainerUtils.hpp"
5+
6+
class ContainerUtilsTest : public testing::Test
7+
{
8+
protected:
9+
static void TearUpTestSuite() {}
10+
11+
ContainerUtilsTest() {}
12+
13+
void SetUp() override {}
14+
15+
void TearDown() override {}
16+
17+
~ContainerUtilsTest() {}
18+
19+
static void TearDownTestSuite() {}
20+
};
21+
22+
TEST_F(ContainerUtilsTest, ShouldEraseElements)
23+
{
24+
std::vector vec = {1, 2, 3, 4, 5, 6};
25+
26+
auto removed = sb::cf::details::ContainerUtils::eraseIf(vec, [](int val) { return val % 2; });
27+
28+
EXPECT_EQ(removed, 3);
29+
EXPECT_EQ(vec, (std::vector{2, 4, 6}));
30+
}

Tests/Unit/Details/JsonObjectExtTest.cpp renamed to Tests/Unit/Details/JsonExtTest.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
using namespace sb::cf::json;
99

10-
class JsonObjectExtTest : public testing::Test
10+
class JsonExtTest : public testing::Test
1111
{
1212
protected:
1313
static void TearUpTestSuite() {}
1414

15-
JsonObjectExtTest() {}
15+
JsonExtTest() {}
1616

1717
void SetUp() override {}
1818

@@ -28,7 +28,7 @@ Params<std::string_view, bool, sb::cf::JsonValue> FindData{
2828
{"inner", true, -123},
2929
{"nonExisting", false, tao::json::null},
3030
};
31-
PARAMS_TEST(JsonObjectExtTest, ShouldFing, FindData)
31+
PARAMS_TEST(JsonExtTest, ShouldFing, FindData)
3232
{
3333
sb::cf::JsonValue json = {
3434
{"str", "hello"}, {"number", 123}, {"array", sb::cf::JsonArray{{{"key", "value"}}}}, {"inner", -123}};
@@ -59,7 +59,7 @@ Params<std::string_view, bool, sb::cf::JsonValue> DeepFindData{
5959
{"inner::inner:str", false, tao::json::null},
6060

6161
};
62-
PARAMS_TEST(JsonObjectExtTest, ShouldDeepFing, DeepFindData)
62+
PARAMS_TEST(JsonExtTest, ShouldDeepFing, DeepFindData)
6363
{
6464
sb::cf::JsonValue json = {{"str", "hello"},
6565
{"number", 123},
@@ -82,7 +82,7 @@ PARAMS_TEST(JsonObjectExtTest, ShouldDeepFing, DeepFindData)
8282
}
8383
}
8484

85-
TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverride)
85+
TEST_F(JsonExtTest, ShouldDeepGetOrOverride)
8686
{
8787
sb::cf::JsonObject json = {{"str", "hello"},
8888
{"number", 123},
@@ -114,7 +114,7 @@ TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverride)
114114
EXPECT_EQ(json, expectedJson);
115115
}
116116

117-
TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideArrayElement)
117+
TEST_F(JsonExtTest, ShouldDeepGetOrOverrideArrayElement)
118118
{
119119
sb::cf::JsonObject json = {{"str", "hello"}};
120120

@@ -129,7 +129,7 @@ TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideArrayElement)
129129
EXPECT_EQ(json, expected);
130130
}
131131

132-
TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideExistingArrayElement)
132+
TEST_F(JsonExtTest, ShouldDeepGetOrOverrideExistingArrayElement)
133133
{
134134
sb::cf::JsonObject json = {{"str", "hello"}, {"array", sb::cf::JsonArray{1234, {{"second", "element"}}}}};
135135

@@ -143,7 +143,7 @@ TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideExistingArrayElement)
143143
EXPECT_EQ(json, expected);
144144
}
145145

146-
TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideWrongArrayElement)
146+
TEST_F(JsonExtTest, ShouldDeepGetOrOverrideWrongArrayElement)
147147
{
148148
sb::cf::JsonObject json = {{"str", "hello"}};
149149

@@ -154,7 +154,7 @@ TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideWrongArrayElement)
154154
EXPECT_EQ(json, expected);
155155
}
156156

157-
TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideDestroy)
157+
TEST_F(JsonExtTest, ShouldDeepGetOrOverrideDestroy)
158158
{
159159
sb::cf::JsonObject json = {{"str", "hello"},
160160
{"number", 123},
@@ -183,14 +183,14 @@ TEST_F(JsonObjectExtTest, ShouldDeepGetOrOverrideDestroy)
183183
EXPECT_EQ(json, expected);
184184
}
185185

186-
TEST_F(JsonObjectExtTest, ShouldFaildDeepGetOrOverrideEmpty)
186+
TEST_F(JsonExtTest, ShouldFaildDeepGetOrOverrideEmpty)
187187
{
188188
sb::cf::JsonObject json = {{"str", "hello"}};
189189

190190
EXPECT_ANY_THROW(sb::cf::details::JsonExt::deepGetOrOverride(json, std::vector<std::string_view>{}));
191191
}
192192

193-
TEST_F(JsonObjectExtTest, SouldDeepMergeEmptyJsonValue)
193+
TEST_F(JsonExtTest, SouldDeepMergeEmptyJsonValue)
194194
{
195195
sb::cf::JsonValue json;
196196

@@ -203,7 +203,7 @@ TEST_F(JsonObjectExtTest, SouldDeepMergeEmptyJsonValue)
203203
EXPECT_EQ(json, expected);
204204
}
205205

206-
TEST_F(JsonObjectExtTest, SouldDeepMergeJsonValue)
206+
TEST_F(JsonExtTest, SouldDeepMergeJsonValue)
207207
{
208208

209209
sb::cf::JsonValue json = {{"str", "hello"},
@@ -246,7 +246,7 @@ TEST_F(JsonObjectExtTest, SouldDeepMergeJsonValue)
246246
EXPECT_EQ(json, expectedJson);
247247
}
248248

249-
TEST_F(JsonObjectExtTest, SouldDeepMergeJsonArray)
249+
TEST_F(JsonExtTest, SouldDeepMergeJsonArray)
250250
{
251251

252252
sb::cf::JsonArray json{{{"str", "hello"}},

Tests/Unit/Details/RequireTest.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <gtest/gtest.h>
2+
#include <iostream>
3+
4+
#include "SevenBit/Conf/Details/Require.hpp"
5+
6+
class RequireTest : public testing::Test
7+
{
8+
protected:
9+
static void TearUpTestSuite() {}
10+
11+
RequireTest() {}
12+
13+
void SetUp() override {}
14+
15+
void TearDown() override {}
16+
17+
~RequireTest() {}
18+
19+
static void TearDownTestSuite() {}
20+
};
21+
22+
TEST_F(RequireTest, ShouldRequireNotNull)
23+
{
24+
int test = 123;
25+
EXPECT_THROW(sb::cf::details::Require::notNull<int>(nullptr), sb::cf::NullPointerException);
26+
EXPECT_THROW(sb::cf::details::Require::notNull<int>(std::unique_ptr<int>{}), sb::cf::NullPointerException);
27+
EXPECT_THROW(sb::cf::details::Require::notNull<int>(std::shared_ptr<int>{}), sb::cf::NullPointerException);
28+
EXPECT_NO_THROW(sb::cf::details::Require::notNull<int>(&test));
29+
EXPECT_NO_THROW(sb::cf::details::Require::notNull<int>(std::shared_ptr<int>{new int}));
30+
EXPECT_NO_THROW(sb::cf::details::Require::notNull<int>(std::unique_ptr<int>{new int}));
31+
}

0 commit comments

Comments
 (0)