From 47f2e618ee956a0b1dfbf87f3a24f41194d2cab6 Mon Sep 17 00:00:00 2001 From: MYLS Date: Wed, 24 Aug 2016 17:01:57 +0800 Subject: [PATCH] Add two tests. - one test for type_id; - another for comments in JSON; --- modules/core/src/persistence.cpp | 3 +++ modules/core/test/test_io.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index d699077..d5b9067 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -3286,7 +3286,10 @@ icvJSONSkipSpaces( CvFileStorage* fs, char* ptr ) if ( !ptr ) { is_eof = true; break; } } if ( *ptr == '/' ) + { + ptr++; break; + } } else { diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 5ba4fd1..a43356f 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -643,6 +643,8 @@ TEST(Core_InputOutput, filestorage_base64_basic) cv::Mat _nd_out, _nd_in; cv::Mat _rd_out(64, 64, CV_64FC1), _rd_in; + bool no_type_id = true; + { /* init */ /* a normal mat */ @@ -703,6 +705,12 @@ TEST(Core_InputOutput, filestorage_base64_basic) fs["normal_nd_mat"] >> _nd_in; fs["random_mat"] >> _rd_in; + if ( !fs["empty_2d_mat"]["type_id"].empty() || + !fs["normal_2d_mat"]["type_id"].empty() || + !fs["normal_nd_mat"]["type_id"].empty() || + !fs[ "random_mat"]["type_id"].empty() ) + no_type_id = false; + /* raw data */ std::vector(1000).swap(rawdata); cvReadRawData(*fs, fs["rawdata"].node, rawdata.data(), data_t::signature()); @@ -722,6 +730,8 @@ TEST(Core_InputOutput, filestorage_base64_basic) //EXPECT_EQ(rawdata[i].i4, i); } + EXPECT_TRUE(no_type_id); + EXPECT_EQ(_em_in.rows , _em_out.rows); EXPECT_EQ(_em_in.cols , _em_out.cols); EXPECT_EQ(_em_in.depth(), _em_out.depth()); @@ -893,3 +903,28 @@ TEST(Core_InputOutput, filestorage_yml_vec2i) remove(file_name.c_str()); } + +TEST(Core_InputOutput, filestorage_json_comment) +{ + String mem_str = + "{ /* comment */\n" + " \"key\": \"value\"\n" + " /************\n" + " * multiline comment\n" + " ************/\n" + " // 233\n" + " // \n" + "}\n" + ; + + String str; + + EXPECT_NO_THROW( + { + cv::FileStorage fs(mem_str, cv::FileStorage::READ | cv::FileStorage::MEMORY); + fs["key"] >> str; + fs.release(); + }); + + EXPECT_EQ(str, String("value")); +} -- 2.7.4