RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
ChecksumFileTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2018 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; withexpected even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "common/ChecksumFile.h"
23#include <string>
24#include <vector>
25#include <gtest/gtest.h>
26
28
29namespace rawspeed_test {
30
31namespace {
32
33TEST(ParseChecksumFileContentTest, Empty) {
34 const auto Content = ParseChecksumFileContent({}, {});
35 ASSERT_TRUE(Content.empty());
36}
37
38TEST(ParseChecksumFileContentTest, ShortLine) {
39 auto gen = [](int len) {
40 return ParseChecksumFileContent(std::string(len, ' '), {});
41 };
42 EXPECT_THROW(gen(65), rawspeed::RawspeedException);
43 EXPECT_THROW(gen(66), rawspeed::RawspeedException);
44 EXPECT_NO_THROW(gen(67));
45}
46
47TEST(ParseChecksumFileContentTest, Lines) {
48 const auto OneLine = std::string(67, ' ');
49
50 auto Content = ParseChecksumFileContent(OneLine, {});
51 ASSERT_FALSE(Content.empty());
52 ASSERT_EQ(Content.size(), 1);
53
54 Content = ParseChecksumFileContent(OneLine + std::string("\n") + OneLine, {});
55 ASSERT_FALSE(Content.empty());
56 ASSERT_EQ(Content.size(), 2);
57
59 OneLine + std::string("\n") + OneLine + std::string("\n"), {});
60 ASSERT_FALSE(Content.empty());
61 ASSERT_EQ(Content.size(), 2);
62}
63
64TEST(ParseChecksumFileContentTest, TheTest) {
65 const std::string testLine =
66 "0000000000000000000000000000000000000000000000000000000000000000 file";
67
68 auto Content = ParseChecksumFileContent(testLine, "");
69 ASSERT_FALSE(Content.empty());
70 ASSERT_EQ(Content.size(), 1);
71 ASSERT_EQ(Content.front().RelFileName, "file");
72 ASSERT_EQ(Content.front().FullFileName, "/file");
73
74 Content = ParseChecksumFileContent(testLine, "dir");
75 ASSERT_FALSE(Content.empty());
76 ASSERT_EQ(Content.size(), 1);
77 ASSERT_EQ(Content.front().RelFileName, "file");
78 ASSERT_EQ(Content.front().FullFileName, "dir/file");
79}
80
81} // namespace
82
83} // namespace rawspeed_test
std::vector< ChecksumFileEntry > ParseChecksumFileContent(const std::string &ChecksumFileContent, const std::string &RootDir)
std::vector< ChecksumFileEntry > ParseChecksumFileContent(const std::string &ChecksumFileContent, const std::string &RootDir)