Revert "Replaced hard pointers to shared_ptr in SaveMap"
This reverts commit 4e58512567.
This commit is contained in:
+44
-7
@@ -17,7 +17,7 @@ public:
|
||||
}
|
||||
void load(std::shared_ptr<SaveMap> save) override
|
||||
{
|
||||
num = static_cast<int>(save->GetInteger("num"));
|
||||
num = save->GetInteger("num");
|
||||
str = save->GetString("str");
|
||||
dbl = save->GetDouble("dbl");
|
||||
}
|
||||
@@ -99,6 +99,24 @@ TEST(SaveMapTest, check_load_with_custom_type)
|
||||
std::string json =
|
||||
"{\n"
|
||||
"\t\"Class name\": \"test class\",\n"
|
||||
"\t\"iTestInt\": 123,\n"
|
||||
"\t\"dTestDouble\": 123.56,\n"
|
||||
"\t\"sTestString\": \"string str\",\n"
|
||||
"\t\"viTestVectorInt\": [\n"
|
||||
"\t\t1,\n"
|
||||
"\t\t2,\n"
|
||||
"\t\t3\n"
|
||||
"\t],\n"
|
||||
"\t\"vdTestVectorDouble\": [\n"
|
||||
"\t\t1.2,\n"
|
||||
"\t\t3.4,\n"
|
||||
"\t\t5.6\n"
|
||||
"\t],\n"
|
||||
"\t\t\"vsTestVectorString\": [\n"
|
||||
"\t\t\"str 1\",\n"
|
||||
"\t\t\"2 str\",\n"
|
||||
"\t\t\"str 3 str\"\n"
|
||||
"\t],\n"
|
||||
"\t\"oCustomObject\": {\n"
|
||||
"\t\t\"Class name\": \"CustomObject\",\n"
|
||||
"\t\t\"inum\": 123,\n"
|
||||
@@ -120,17 +138,34 @@ TEST(SaveMapTest, check_load_with_custom_type)
|
||||
"}"
|
||||
"]"
|
||||
"}";
|
||||
SaveMap save_map(json);
|
||||
|
||||
|
||||
std::shared_ptr<CustomObject> obj = reinterpret_cast<std::shared_ptr<CustomObject>&>(save_map.GetObject("CustomObject"));
|
||||
std::vector<int> test_vector_int = { 1, 2, 3 };
|
||||
std::vector<double> test_vector_double = { 1.2, 3.4, 5.6 };
|
||||
std::vector<std::string> test_vector_string = { "str 1", "2 str", "str 3 str" };
|
||||
SaveMap save_map(json);
|
||||
|
||||
EXPECT_EQ(save_map.GetInteger("TestInt"), 123);
|
||||
EXPECT_EQ(save_map.GetDouble("TestDouble"), 123.56);
|
||||
EXPECT_EQ(save_map.GetString("TestString"), "string str");
|
||||
|
||||
EXPECT_EQ(save_map.GetVectorInteger("TestVectorInt").size(), 3);
|
||||
EXPECT_EQ(save_map.GetVectorDouble("TestVectorDouble").size(), 3);
|
||||
EXPECT_EQ(save_map.GetVectorString("TestVectorString").size(), 3);
|
||||
for (auto i = 0; i < 3; i++)
|
||||
{
|
||||
EXPECT_EQ(test_vector_int[i], save_map.GetVectorInteger("TestVectorInt")[i]);
|
||||
EXPECT_EQ(test_vector_double[i], save_map.GetVectorDouble("TestVectorDouble")[i]);
|
||||
EXPECT_EQ(test_vector_string[i], save_map.GetVectorString("TestVectorString")[i]);
|
||||
}
|
||||
|
||||
CustomObject* obj = reinterpret_cast<CustomObject*>(save_map.GetObject("CustomObject"));
|
||||
CustomObject test_obj;
|
||||
test_obj.num = 123;
|
||||
test_obj.str = "str123";
|
||||
test_obj.dbl = 123.45;
|
||||
EXPECT_EQ(*obj.get(), test_obj);
|
||||
EXPECT_EQ(*obj, test_obj);
|
||||
|
||||
std::vector<std::shared_ptr<CustomObject>> vec_obj = reinterpret_cast<std::vector<std::shared_ptr<CustomObject>>&>(save_map.GetVectorObject("CustomObjects"));
|
||||
std::vector<CustomObject*> vec_obj = reinterpret_cast<std::vector<CustomObject*>&>(save_map.GetVectorObject("CustomObjects"));
|
||||
std::vector<CustomObject*> vec_obj_test = {
|
||||
new CustomObject,
|
||||
new CustomObject,
|
||||
@@ -143,6 +178,8 @@ TEST(SaveMapTest, check_load_with_custom_type)
|
||||
vec_obj_test[1]->dbl = 543.21;
|
||||
for (auto i = 0; i < 2; i++)
|
||||
{
|
||||
EXPECT_EQ(*vec_obj[i].get(), *vec_obj_test[i]);
|
||||
EXPECT_EQ(*vec_obj[i], *vec_obj_test[i]);
|
||||
delete vec_obj[i];
|
||||
delete vec_obj_test[i];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user