* Solves #11156 * Check file size for all file format. Disable APPEND if file is empty * Add test for APPEND mode
This commit is contained in:
parent
75b5e3fa64
commit
03eb463f1c
@ -207,7 +207,11 @@ cvOpenFileStorage( const char* query, CvMemStorage* dststorage, int flags, const
|
|||||||
int buf_size = CV_FS_MAX_LEN*(fs->fmt == CV_STORAGE_FORMAT_XML ? 6 : 4) + 1024;
|
int buf_size = CV_FS_MAX_LEN*(fs->fmt == CV_STORAGE_FORMAT_XML ? 6 : 4) + 1024;
|
||||||
|
|
||||||
if (append)
|
if (append)
|
||||||
|
{
|
||||||
fseek( fs->file, 0, SEEK_END );
|
fseek( fs->file, 0, SEEK_END );
|
||||||
|
if (ftell(fs->file) == 0)
|
||||||
|
append = false;
|
||||||
|
}
|
||||||
|
|
||||||
fs->write_stack = cvCreateSeq( 0, sizeof(CvSeq), fs->fmt == CV_STORAGE_FORMAT_XML ?
|
fs->write_stack = cvCreateSeq( 0, sizeof(CvSeq), fs->fmt == CV_STORAGE_FORMAT_XML ?
|
||||||
sizeof(CvXMLStackRecord) : sizeof(int), fs->memstorage );
|
sizeof(CvXMLStackRecord) : sizeof(int), fs->memstorage );
|
||||||
|
|||||||
@ -602,6 +602,24 @@ TEST(Core_InputOutput, FileStorageSpaces)
|
|||||||
EXPECT_NO_THROW(f2[cv::format("key%d", i)] >> valuesRead[i]);
|
EXPECT_NO_THROW(f2[cv::format("key%d", i)] >> valuesRead[i]);
|
||||||
ASSERT_STREQ(values[i].c_str(), valuesRead[i].c_str());
|
ASSERT_STREQ(values[i].c_str(), valuesRead[i].c_str());
|
||||||
}
|
}
|
||||||
|
std::string fileName = cv::tempfile(".xml");
|
||||||
|
cv::FileStorage g1(fileName, cv::FileStorage::WRITE);
|
||||||
|
for (size_t i = 0; i < 2; i++) {
|
||||||
|
EXPECT_NO_THROW(g1 << cv::format("key%d", i) << values[i]);
|
||||||
|
}
|
||||||
|
g1.release();
|
||||||
|
cv::FileStorage g2(fileName, cv::FileStorage::APPEND);
|
||||||
|
for (size_t i = 2; i < valueCount; i++) {
|
||||||
|
EXPECT_NO_THROW(g2 << cv::format("key%d", i) << values[i]);
|
||||||
|
}
|
||||||
|
g2.release();
|
||||||
|
cv::FileStorage g3(fileName, cv::FileStorage::READ);
|
||||||
|
std::string valuesReadAppend[valueCount];
|
||||||
|
for (size_t i = 0; i < valueCount; i++) {
|
||||||
|
EXPECT_NO_THROW(g3[cv::format("key%d", i)] >> valuesReadAppend[i]);
|
||||||
|
ASSERT_STREQ(values[i].c_str(), valuesReadAppend[i].c_str());
|
||||||
|
}
|
||||||
|
g3.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct data_t
|
struct data_t
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user