-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathJsonHandlerTest.cpp
More file actions
88 lines (68 loc) · 2.72 KB
/
JsonHandlerTest.cpp
File metadata and controls
88 lines (68 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <gtest/gtest.h>
#include <string>
#include "JsonHandler.h"
namespace JsonParsing
{
class JsonHandlerTest : public ::testing::Test
{
protected:
JsonHandler m_jsonHandler {{}};
protected:
void SetUp() override {}
void TearDown() override {}
};
TEST_F(JsonHandlerTest, TestGetCompressedJson_Success)
{
std::string inputJson = R"({"key": "value"})";
auto result = m_jsonHandler.GetCompressedJson(inputJson);
ASSERT_TRUE(result.success);
ASSERT_EQ(result.response, R"({"key":"value"})");
}
TEST_F(JsonHandlerTest, TestGetCompressedJson_InvalidJson)
{
std::string inputJson = R"({"key": "value")"; // Missing closing brace
auto result = m_jsonHandler.GetCompressedJson(inputJson);
ASSERT_FALSE(result.success);
ASSERT_TRUE(result.response.empty());
}
TEST_F(JsonHandlerTest, TestFormatJson_Success)
{
std::string inputJson = R"({"key": "value"})";
auto result = m_jsonHandler.FormatJson(inputJson, {}, {}, ' ', 4);
ASSERT_TRUE(result.success);
ASSERT_EQ(result.response, "{\n \"key\": \"value\"\n}");
}
TEST_F(JsonHandlerTest, TestFormatJson_InvalidJson)
{
std::string inputJson = R"({"key": "value")"; // Invalid JSON
auto result = m_jsonHandler.FormatJson(inputJson, {}, {}, ' ', 4);
ASSERT_FALSE(result.success);
}
// Test ValidateJson
TEST_F(JsonHandlerTest, TestValidateJson_Success)
{
std::string inputJson = R"({"key": "value"})";
auto result = m_jsonHandler.ValidateJson(inputJson);
ASSERT_TRUE(result.success);
}
TEST_F(JsonHandlerTest, TestValidateJson_InvalidJson)
{
std::string inputJson = R"({"key": "value")"; // Invalid JSON
auto result = m_jsonHandler.ValidateJson(inputJson);
ASSERT_FALSE(result.success);
}
// Test SortJsonByKey
TEST_F(JsonHandlerTest, TestSortJsonByKey_Success)
{
std::string inputJson = R"({"b": "valueB", "a": "valueA"})";
auto result = m_jsonHandler.SortJsonByKey(inputJson, {}, {}, ' ', 4);
ASSERT_TRUE(result.success);
ASSERT_EQ(result.response, "{\n \"a\": \"valueA\",\n \"b\": \"valueB\"\n}");
}
TEST_F(JsonHandlerTest, TestSortJsonByKey_InvalidJson)
{
std::string inputJson = R"({"b": "valueB", "a": "valueA")"; // Invalid JSON
auto result = m_jsonHandler.SortJsonByKey(inputJson, {}, {}, ' ', 4);
ASSERT_FALSE(result.success);
}
} // namespace JsonParsing