Skip to content

Commit 498ea10

Browse files
committed
wire logger in tests
1 parent ee35dd1 commit 498ea10

6 files changed

Lines changed: 41 additions & 14 deletions

File tree

src/odr/odr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ odr::DecoderEngine odr::decoder_engine_by_name(const std::string &name) {
225225
throw UnknownDecoderEngine();
226226
}
227227

228-
std::vector<odr::FileType> odr::list_file_types(const std::string &path) {
229-
return DecodedFile::list_file_types(path);
228+
std::vector<odr::FileType> odr::list_file_types(const std::string &path,
229+
Logger &logger) {
230+
return DecodedFile::list_file_types(path, logger);
230231
}
231232

232233
std::vector<odr::DecoderEngine> odr::list_decoder_engines(const FileType as) {

src/odr/odr.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ file_type_by_file_extension(const std::string &extension) noexcept;
6464
/// @brief Determine the file types by the file path.
6565
/// @param path The file path.
6666
/// @return The file types.
67-
[[nodiscard]] std::vector<FileType> list_file_types(const std::string &path);
67+
[[nodiscard]] std::vector<FileType>
68+
list_file_types(const std::string &path, Logger &logger = Logger::null());
6869
/// @brief Determine the decoder engines for a file path and file type.
6970
/// @param as The file type.
7071
/// @return The decoder engines.

test/src/document_test.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ using namespace odr;
1111
using namespace odr::test;
1212

1313
TEST(Document, odt) {
14+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
15+
1416
DocumentFile document_file(
15-
TestData::test_file_path("odr-public/odt/about.odt"));
17+
TestData::test_file_path("odr-public/odt/about.odt"), *logger);
1618

1719
EXPECT_EQ(document_file.file_type(), FileType::opendocument_text);
1820

@@ -30,8 +32,10 @@ TEST(Document, odt) {
3032
}
3133

3234
TEST(Document, odg) {
35+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
36+
3337
DocumentFile document_file(
34-
TestData::test_file_path("odr-public/odg/sample.odg"));
38+
TestData::test_file_path("odr-public/odg/sample.odg"), *logger);
3539

3640
EXPECT_EQ(document_file.file_type(), FileType::opendocument_graphics);
3741

@@ -51,8 +55,10 @@ TEST(Document, odg) {
5155
}
5256

5357
TEST(Document, edit_odt) {
58+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
59+
5460
DocumentFile document_file(
55-
TestData::test_file_path("odr-public/odt/about.odt"));
61+
TestData::test_file_path("odr-public/odt/about.odt"), *logger);
5662
Document document = document_file.document();
5763

5864
std::function<void(Element)> edit = [&](Element element) {
@@ -70,8 +76,11 @@ TEST(Document, edit_odt) {
7076
}
7177

7278
TEST(Document, edit_docx) {
79+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
80+
7381
DocumentFile document_file(
74-
TestData::test_file_path("odr-public/docx/style-various-1.docx"));
82+
TestData::test_file_path("odr-public/docx/style-various-1.docx"),
83+
*logger);
7584
Document document = document_file.document();
7685

7786
std::function<void(Element)> edit = [&](Element element) {
@@ -89,10 +98,12 @@ TEST(Document, edit_docx) {
8998
}
9099

91100
TEST(Document, edit_odt_diff) {
101+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
102+
92103
auto diff =
93104
R"({"modifiedText":{"/child:16/child:0":"Outasdfsdafdline","/child:24/child:0":"Colorasdfasdfasdfed Line","/child:6/child:0":"Text hello world!"}})";
94105
DocumentFile document_file(
95-
TestData::test_file_path("odr-public/odt/style-various-1.odt"));
106+
TestData::test_file_path("odr-public/odt/style-various-1.odt"), *logger);
96107
Document document = document_file.document();
97108

98109
html::edit(document, diff);
@@ -102,10 +113,12 @@ TEST(Document, edit_odt_diff) {
102113
}
103114

104115
TEST(Document, edit_ods_diff) {
116+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
117+
105118
auto diff =
106119
R"({"modifiedText":{"/child:0/row:0/child:0/child:0/child:0":"Page 1 hi","/child:1/row:0/child:0/child:0/child:0":"Page 2 hihi","/child:2/row:0/child:0/child:0/child:0":"Page 3 hihihi","/child:3/row:0/child:0/child:0/child:0":"Page 4 hihihihi","/child:4/row:0/child:0/child:0/child:0":"Page 5 hihihihihi"}})";
107120
DocumentFile document_file(
108-
TestData::test_file_path("odr-public/ods/pages.ods"));
121+
TestData::test_file_path("odr-public/ods/pages.ods"), *logger);
109122
document_file = document_file.decrypt(
110123
TestData::test_file("odr-public/ods/pages.ods").password.value());
111124
Document document = document_file.document();
@@ -117,10 +130,13 @@ TEST(Document, edit_ods_diff) {
117130
}
118131

119132
TEST(Document, edit_docx_diff) {
133+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
134+
120135
auto diff =
121136
R"({"modifiedText":{"/child:16/child:0/child:0":"Outasdfsdafdline","/child:24/child:0/child:0":"Colorasdfasdfasdfed Line","/child:6/child:0/child:0":"Text hello world!"}})";
122137
DocumentFile document_file(
123-
TestData::test_file_path("odr-public/docx/style-various-1.docx"));
138+
TestData::test_file_path("odr-public/docx/style-various-1.docx"),
139+
*logger);
124140
Document document = document_file.document();
125141

126142
html::edit(document, diff);

test/src/file_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ TEST(File, open) { EXPECT_THROW(File("/"), FileNotFound); }
1212
TEST(DocumentFile, open) { EXPECT_THROW(DocumentFile("/"), FileNotFound); }
1313

1414
TEST(DecodedFile, wpd) {
15+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
16+
1517
auto path = TestData::test_file_path("odr-public/wpd/Sync3 Sample Page.wpd");
1618
try {
17-
DecodedFile file(path);
19+
DecodedFile file(path, *logger);
1820
FAIL();
1921
} catch (const UnsupportedFileType &e) {
2022
EXPECT_EQ(e.file_type, FileType::word_perfect);

test/src/html_output_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct TestParams {
3434
using HtmlOutputTests = ::testing::TestWithParam<TestParams>;
3535

3636
TEST_P(HtmlOutputTests, html_meta) {
37+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
38+
3739
const TestParams &params = GetParam();
3840
const TestFile &test_file = params.test_file;
3941
const DecoderEngine engine = params.engine;
@@ -64,7 +66,8 @@ TEST_P(HtmlOutputTests, html_meta) {
6466
DecodePreference decode_preference;
6567
decode_preference.as_file_type = test_file.type;
6668
decode_preference.with_engine = engine;
67-
DecodedFile file = odr::open(test_file.absolute_path, decode_preference);
69+
DecodedFile file =
70+
odr::open(test_file.absolute_path, decode_preference, *logger);
6871

6972
FileMeta file_meta = file.file_meta();
7073

test/src/odr_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ TEST(odr, version) { EXPECT_TRUE(odr::version().empty()); }
1313
TEST(odr, commit) { EXPECT_FALSE(odr::commit_hash().empty()); }
1414

1515
TEST(odr, types_odt) {
16+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
17+
1618
auto path = TestData::test_file_path("odr-public/odt/about.odt");
17-
auto types = odr::list_file_types(path);
19+
auto types = odr::list_file_types(path, *logger);
1820
EXPECT_EQ(types.size(), 2);
1921
EXPECT_EQ(types[0], FileType::zip);
2022
EXPECT_EQ(types[1], FileType::opendocument_text);
2123
}
2224

2325
TEST(odr, types_wpd) {
26+
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
27+
2428
auto path = TestData::test_file_path("odr-public/wpd/Sync3 Sample Page.wpd");
25-
auto types = odr::list_file_types(path);
29+
auto types = odr::list_file_types(path, *logger);
2630
EXPECT_EQ(types.size(), 1);
2731
EXPECT_EQ(types[0], FileType::word_perfect);
2832
}

0 commit comments

Comments
 (0)