Files
SimpleJson/main.cpp
T

45 lines
1.2 KiB
C++

#include <iostream>
#include "gtest/gtest.h"
#include "src/json.h"
TEST(TestCase, testJsonNodeSetDoule) {
simpleJson::JsonNode node(simpleJson::JSON_TYPE_DOUBLE, "key");
node.set_value(1.0);
EXPECT_EQ(node.as_int(), 1);
}
TEST(TestCase, testJsonNodeSetString) {
simpleJson::JsonNode node(simpleJson::JSON_TYPE_STRING, "key");
node.set_value("1.0");
const char* s = node.as_string().c_str();
EXPECT_STREQ(s,"1.0");
}
TEST(TestCase, testJsonNodeSetError) {
simpleJson::JsonNode node(simpleJson::JSON_TYPE_INT, "key");
EXPECT_THROW(node.set_value("1.0"), std::runtime_error);
}
TEST(TestCase, testJsonNodeSetKey) {
simpleJson::JsonNode node(simpleJson::JSON_TYPE_INT, "key");
node.set_key("key1");
EXPECT_STREQ(node.get_key().c_str(), "key1");
}
TEST(TestCase,testJsonNodeSetBool) {
simpleJson::JsonNode node(simpleJson::JSON_TYPE_BOOL, "key");
node.set_value(true);
EXPECT_EQ(node.as_bool(), true);
}
TEST(TestCase, testParseStr) {
std::string json_str = "{\"key\":\"1\"}";
simpleJson::JsonParser parser(json_str);
EXPECT_EQ(parser.get_root().obj_get("key").as_string(), "1");
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}