mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 03:33:28 +08:00
Merge pull request #15842 from TH3CHARLie:yaml-fix
* fix yaml parse * add test for YAML parse multiple documents * remove trailing whitespace in test
This commit is contained in:
parent
0d7f770996
commit
a165f55579
@ -770,7 +770,7 @@ public:
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
FileNode root_collection(fs->getFS(), 0, 0);
|
FileNode root_collection(fs->getFS(), 0, 0);
|
||||||
|
FileNode root_node = fs->addNode(root_collection, std::string(), FileNode::NONE);
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
// 0. skip leading comments and directives and ...
|
// 0. skip leading comments and directives and ...
|
||||||
@ -821,7 +821,6 @@ public:
|
|||||||
if( memcmp( ptr, "...", 3 ) != 0 )
|
if( memcmp( ptr, "...", 3 ) != 0 )
|
||||||
{
|
{
|
||||||
// 2. parse the collection
|
// 2. parse the collection
|
||||||
FileNode root_node = fs->addNode(root_collection, std::string(), FileNode::NONE);
|
|
||||||
|
|
||||||
ptr = parseValue( ptr, root_node, 0, false );
|
ptr = parseValue( ptr, root_node, 0, false );
|
||||||
if( !root_node.isMap() && !root_node.isSeq() )
|
if( !root_node.isMap() && !root_node.isSeq() )
|
||||||
|
@ -1640,4 +1640,23 @@ TEST(Core_InputOutput, FileStorage_free_file_after_exception)
|
|||||||
ASSERT_EQ(0, std::remove(fileName.c_str()));
|
ASSERT_EQ(0, std::remove(fileName.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
|
||||||
|
{
|
||||||
|
const std::string filename = "FileStorage_YAML_parse_multiple_documents.yml";
|
||||||
|
FileStorage fs;
|
||||||
|
|
||||||
|
fs.open(filename, FileStorage::WRITE);
|
||||||
|
fs << "a" << 42;
|
||||||
|
fs.release();
|
||||||
|
|
||||||
|
fs.open(filename, FileStorage::APPEND);
|
||||||
|
fs << "b" << 1988;
|
||||||
|
fs.release();
|
||||||
|
|
||||||
|
fs.open(filename, FileStorage::READ);
|
||||||
|
ASSERT_EQ(42, (int)fs["a"]);
|
||||||
|
ASSERT_EQ(1988, (int)fs["b"]);
|
||||||
|
fs.release();
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user