Add a test for FileNode::keys()

pull/13125/head
Dmitry Kurtaev 6 years ago
parent 93d1785820
commit 6c76c8f881
  1. 11
      modules/core/src/persistence_cpp.cpp
  2. 6
      modules/core/test/test_io.cpp

@ -271,14 +271,13 @@ FileNode FileNode::operator[](int i) const
std::vector<String> FileNode::keys() const
{
CV_Assert(isMap());
std::vector<String> res;
if (isMap())
res.reserve(size());
for (FileNodeIterator it = begin(); it != end(); ++it)
{
res.reserve(size());
for (FileNodeIterator it = begin(); it != end(); ++it)
{
res.push_back((*it).name());
}
res.push_back((*it).name());
}
return res;
}

@ -1597,6 +1597,12 @@ TEST(Core_InputOutput, FileStorage_json_bool)
ASSERT_EQ((int)fs["map_value"]["bool_true"], 1);
ASSERT_EQ((std::string)fs["map_value"]["str_false"], "false");
ASSERT_EQ((int)fs["bool_false"], 0);
std::vector<String> keys = fs["map_value"].keys();
ASSERT_EQ((int)keys.size(), 3);
ASSERT_EQ(keys[0], "int_value");
ASSERT_EQ(keys[1], "bool_true");
ASSERT_EQ(keys[2], "str_false");
fs.release();
}

Loading…
Cancel
Save