mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
Merge pull request #9232 from dkurt:json_named_nodes
This commit is contained in:
commit
c512bf6c66
@ -3781,6 +3781,7 @@ static char* icvJSONParseMap( CvFileStorage* fs, char* ptr, CvFileNode* node )
|
||||
ptr = icvJSONParseMap( fs, ptr, child );
|
||||
else
|
||||
ptr = icvJSONParseValue( fs, ptr, child );
|
||||
child->tag |= CV_NODE_NAMED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1292,3 +1292,29 @@ TEST(Core_InputOutput, FileStorage_format_yml_gz)
|
||||
fs.open("opencv_storage.yml.gz", FileStorage::WRITE | FileStorage::MEMORY);
|
||||
EXPECT_EQ(FileStorage::FORMAT_YAML, fs.getFormat());
|
||||
}
|
||||
|
||||
TEST(Core_InputOutput, FileStorage_json_named_nodes)
|
||||
{
|
||||
std::string test =
|
||||
"{ "
|
||||
"\"int_value\": -324,"
|
||||
"\"map_value\": {"
|
||||
"\"str_value\": \"mystring\""
|
||||
"},"
|
||||
"\"array\": [0.2, 0.1]"
|
||||
"}";
|
||||
FileStorage fs(test, FileStorage::READ | FileStorage::MEMORY);
|
||||
|
||||
ASSERT_TRUE(fs["int_value"].isNamed());
|
||||
ASSERT_TRUE(fs["map_value"].isNamed());
|
||||
ASSERT_TRUE(fs["map_value"]["str_value"].isNamed());
|
||||
ASSERT_TRUE(fs["array"].isNamed());
|
||||
ASSERT_FALSE(fs["array"][0].isNamed());
|
||||
ASSERT_FALSE(fs["array"][1].isNamed());
|
||||
|
||||
ASSERT_EQ(fs["int_value"].name(), "int_value");
|
||||
ASSERT_EQ(fs["map_value"].name(), "map_value");
|
||||
ASSERT_EQ(fs["map_value"]["str_value"].name(), "str_value");
|
||||
ASSERT_EQ(fs["array"].name(), "array");
|
||||
fs.release();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user