| 293 | } |
| 294 | |
| 295 | bool validate_save(std::string const& goodFilename, std::string const& checkFilename, int v2Lines = -1, bool allowLonger = false) { |
| 296 | std::ifstream good(goodFilename.c_str()); |
| 297 | std::ifstream check(checkFilename.c_str()); |
| 298 | |
| 299 | EXPECT_TRUE(good.good()); |
| 300 | EXPECT_TRUE(check.good()); |
| 301 | |
| 302 | std::string good_header; |
| 303 | std::string check_header; |
| 304 | |
| 305 | std::getline(good, good_header); |
| 306 | std::getline(check, check_header); |
| 307 | |
| 308 | // istream_iterator rather than line_reader because we never write comments |
| 309 | // or empty lines in timecode files |
| 310 | std::istream_iterator<double> good_iter(good); |
| 311 | std::istream_iterator<double> check_iter(check); |
| 312 | std::istream_iterator<double> end; |
| 313 | |
| 314 | int line = 0; |
| 315 | for (; good_iter != end; ++good_iter, ++check_iter, ++line) { |
| 316 | if (check_iter == end) return false; |
| 317 | if (v2Lines < 0 || line < v2Lines) { |
| 318 | if (*good_iter != *check_iter) return false; |
| 319 | } |
| 320 | } |
| 321 | // v1 timecodes with the end of a range past the end of the video are valid, |
| 322 | // and when saving those there will be too many timecodes in the v2 file |
| 323 | if (!allowLonger && check_iter != end) return false; |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | TEST(lagi_vfr, validate_save) { |
| 328 | EXPECT_TRUE(validate_save("data/vfr/in/validate_base.txt", "data/vfr/in/validate_base.txt")); |