Skip to content

Commit cdaee1a

Browse files
committed
fix
1 parent 57dadb9 commit cdaee1a

20 files changed

Lines changed: 168 additions & 170 deletions

test/src/document_test.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ using namespace odr;
1313
using namespace odr::test;
1414

1515
TEST(Document, odt) {
16-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
16+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
1717

18-
DocumentFile document_file(
18+
const DocumentFile document_file(
1919
TestData::test_file_path("odr-public/odt/about.odt"), *logger);
2020

2121
EXPECT_EQ(document_file.file_type(), FileType::opendocument_text);
2222

23-
Document document = document_file.document();
23+
const Document document = document_file.document();
2424

2525
EXPECT_EQ(document.document_type(), DocumentType::text);
2626

27-
auto page_layout = document.root_element().as_text_root().page_layout();
27+
const auto page_layout = document.root_element().as_text_root().page_layout();
2828
EXPECT_TRUE(page_layout.width);
2929
EXPECT_EQ(Measure("8.2673in"), page_layout.width);
3030
EXPECT_TRUE(page_layout.height);
@@ -57,96 +57,96 @@ TEST(Document, odg) {
5757
}
5858

5959
TEST(Document, edit_odt) {
60-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
60+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
6161

62-
DocumentFile document_file(
62+
const DocumentFile document_file(
6363
TestData::test_file_path("odr-public/odt/about.odt"), *logger);
64-
Document document = document_file.document();
64+
const Document document = document_file.document();
6565

66-
std::function<void(Element)> edit = [&](Element element) {
67-
for (Element child : element.children()) {
66+
std::function<void(Element)> edit = [&](const Element element) {
67+
for (const Element child : element.children()) {
6868
edit(child);
6969
}
7070
// TODO make editing empty text possible
71-
if (auto text = element.as_text(); text && !text.content().empty()) {
71+
if (const auto text = element.as_text(); text && !text.content().empty()) {
7272
text.set_content("hello world!");
7373
}
7474
};
7575
edit(document.root_element());
7676

77-
std::string output_path =
77+
const std::string output_path =
7878
(std::filesystem::current_path() / "about_edit.odt").string();
7979
document.save(output_path);
8080

81-
DocumentFile validate_file(output_path);
82-
Document validate_document = validate_file.document();
83-
std::function<void(Element)> validate = [&](Element element) {
84-
for (Element child : element.children()) {
81+
const DocumentFile validate_file(output_path);
82+
const Document validate_document = validate_file.document();
83+
std::function<void(Element)> validate = [&](const Element element) {
84+
for (const Element child : element.children()) {
8585
validate(child);
8686
}
8787
// TODO make editing empty text possible
88-
if (auto text = element.as_text(); text && !text.content().empty()) {
88+
if (const auto text = element.as_text(); text && !text.content().empty()) {
8989
EXPECT_EQ("hello world!", text.content());
9090
}
9191
};
9292
validate(validate_document.root_element());
9393
}
9494

9595
TEST(Document, edit_docx) {
96-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
96+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
9797

98-
DocumentFile document_file(
98+
const DocumentFile document_file(
9999
TestData::test_file_path("odr-public/docx/style-various-1.docx"),
100100
*logger);
101-
Document document = document_file.document();
101+
const Document document = document_file.document();
102102

103-
std::function<void(Element)> edit = [&](Element element) {
104-
for (Element child : element.children()) {
103+
std::function<void(Element)> edit = [&](const Element element) {
104+
for (const Element child : element.children()) {
105105
edit(child);
106106
}
107107
// TODO make editing empty text possible
108-
if (auto text = element.as_text(); text && !text.content().empty()) {
108+
if (const auto text = element.as_text(); text && !text.content().empty()) {
109109
text.set_content("hello world!");
110110
}
111111
};
112112
edit(document.root_element());
113113

114-
std::string output_path =
114+
const std::string output_path =
115115
(std::filesystem::current_path() / "style-various-1_edit.docx").string();
116116
document.save(output_path);
117117

118-
DocumentFile validate_file(output_path);
119-
Document validate_document = validate_file.document();
120-
std::function<void(Element)> validate = [&](Element element) {
121-
for (Element child : element.children()) {
118+
const DocumentFile validate_file(output_path);
119+
const Document validate_document = validate_file.document();
120+
std::function<void(Element)> validate = [&](const Element element) {
121+
for (const Element child : element.children()) {
122122
validate(child);
123123
}
124124
// TODO make editing empty text possible
125-
if (auto text = element.as_text(); text && !text.content().empty()) {
125+
if (const auto text = element.as_text(); text && !text.content().empty()) {
126126
EXPECT_EQ("hello world!", text.content());
127127
}
128128
};
129129
validate(validate_document.root_element());
130130
}
131131

132132
TEST(Document, edit_odt_diff) {
133-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
133+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
134134

135-
auto diff =
135+
const auto diff =
136136
R"({"modifiedText":{"/child:16/child:0":"Outasdfsdafdline","/child:24/child:0":"Colorasdfasdfasdfed Line","/child:6/child:0":"Text hello world!"}})";
137-
DocumentFile document_file(
137+
const DocumentFile document_file(
138138
TestData::test_file_path("odr-public/odt/style-various-1.odt"), *logger);
139-
Document document = document_file.document();
139+
const Document document = document_file.document();
140140

141141
html::edit(document, diff);
142142

143-
std::string output_path =
143+
const std::string output_path =
144144
(std::filesystem::current_path() / "style-various-1_edit_diff.odt")
145145
.string();
146146
document.save(output_path);
147147

148-
DocumentFile validate_file(output_path);
149-
Document validate_document = validate_file.document();
148+
const DocumentFile validate_file(output_path);
149+
const Document validate_document = validate_file.document();
150150
EXPECT_EQ("Outasdfsdafdline",
151151
DocumentPath::find(validate_document.root_element(),
152152
DocumentPath("/child:16/child:0"))
@@ -222,24 +222,24 @@ TEST(Document, edit_odt_diff) {
222222
// }
223223

224224
TEST(Document, edit_docx_diff) {
225-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
225+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
226226

227-
auto diff =
227+
const auto diff =
228228
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!"}})";
229-
DocumentFile document_file(
229+
const DocumentFile document_file(
230230
TestData::test_file_path("odr-public/docx/style-various-1.docx"),
231231
*logger);
232-
Document document = document_file.document();
232+
const Document document = document_file.document();
233233

234234
html::edit(document, diff);
235235

236-
std::string output_path =
236+
const std::string output_path =
237237
(std::filesystem::current_path() / "style-various-1_edit_diff.docx")
238238
.string();
239239
document.save(output_path);
240240

241-
DocumentFile validate_file(output_path);
242-
Document validate_document = validate_file.document();
241+
const DocumentFile validate_file(output_path);
242+
const Document validate_document = validate_file.document();
243243
EXPECT_EQ("Outasdfsdafdline",
244244
DocumentPath::find(validate_document.root_element(),
245245
DocumentPath("/child:16/child:0/child:0"))

test/src/file_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ 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);
15+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
1616

17-
auto path = TestData::test_file_path("odr-public/wpd/Sync3 Sample Page.wpd");
17+
const auto path =
18+
TestData::test_file_path("odr-public/wpd/Sync3 Sample Page.wpd");
1819
try {
1920
DecodedFile file(path, *logger);
2021
FAIL();

test/src/html_output_test.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ struct TestParams {
4646
std::string output_path_prefix;
4747
};
4848

49-
using HtmlOutputTests = ::testing::TestWithParam<TestParams>;
49+
using HtmlOutputTests = testing::TestWithParam<TestParams>;
5050

5151
TEST_P(HtmlOutputTests, html_meta) {
52-
auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
52+
const auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
5353

5454
const TestParams &params = GetParam();
5555
const TestFile &test_file = params.test_file;
@@ -66,25 +66,24 @@ TEST_P(HtmlOutputTests, html_meta) {
6666

6767
// these files cannot be opened
6868
if (util::string::ends_with(test_file.short_path, ".sxw") ||
69-
(test_file.type == FileType::legacy_powerpoint_presentation) ||
70-
(test_file.type == FileType::legacy_excel_worksheets) ||
71-
(test_file.type == FileType::word_perfect) ||
72-
(test_file.type == FileType::starview_metafile)) {
69+
test_file.type == FileType::legacy_powerpoint_presentation ||
70+
test_file.type == FileType::legacy_excel_worksheets ||
71+
test_file.type == FileType::word_perfect ||
72+
test_file.type == FileType::starview_metafile) {
7373
GTEST_SKIP();
7474
}
7575

7676
// TODO fix pdf implementation
77-
if ((engine == DecoderEngine::odr) &&
78-
(test_file.type == FileType::portable_document_format) &&
79-
(test_repo != "odr-public")) {
77+
if (engine == DecoderEngine::odr &&
78+
test_file.type == FileType::portable_document_format &&
79+
test_repo != "odr-public") {
8080
GTEST_SKIP();
8181
}
8282

8383
DecodePreference decode_preference;
8484
decode_preference.as_file_type = test_file.type;
8585
decode_preference.with_engine = engine;
86-
DecodedFile file =
87-
odr::open(test_file.absolute_path, decode_preference, *logger);
86+
DecodedFile file = open(test_file.absolute_path, decode_preference, *logger);
8887

8988
FileMeta file_meta = file.file_meta();
9089

@@ -100,30 +99,29 @@ TEST_P(HtmlOutputTests, html_meta) {
10099

101100
{
102101
const std::string meta_output = output_path + "/meta.json";
103-
const nlohmann::json json =
104-
odr::internal::util::meta::meta_to_json(file_meta);
102+
const nlohmann::json json = util::meta::meta_to_json(file_meta);
105103
std::ofstream o(meta_output);
106104
o << std::setw(4) << json << std::endl;
107105
EXPECT_TRUE(fs::is_regular_file(meta_output));
108106
EXPECT_LT(0, fs::file_size(meta_output));
109107
}
110108

111109
// encrypted ooxml type cannot be inspected
112-
if ((file.file_type() != FileType::office_open_xml_encrypted)) {
110+
if (file.file_type() != FileType::office_open_xml_encrypted) {
113111
EXPECT_EQ(test_file.type, file.file_type());
114112
}
115113

116114
// TODO enable zip, csv, json
117-
if ((test_file.type == FileType::zip) ||
118-
(test_file.type == FileType::comma_separated_values) ||
119-
(test_file.type == FileType::javascript_object_notation)) {
115+
if (test_file.type == FileType::zip ||
116+
test_file.type == FileType::comma_separated_values ||
117+
test_file.type == FileType::javascript_object_notation) {
120118
GTEST_SKIP();
121119
}
122120

123121
// TODO wvware decryption
124122
if (test_file.password.has_value() &&
125-
(test_file.type == FileType::legacy_word_document) &&
126-
(engine == DecoderEngine::wvware)) {
123+
test_file.type == FileType::legacy_word_document &&
124+
engine == DecoderEngine::wvware) {
127125
GTEST_SKIP();
128126
}
129127

@@ -145,8 +143,7 @@ TEST_P(HtmlOutputTests, html_meta) {
145143

146144
{
147145
const std::string meta_output = output_path + "/meta-decrypted.json";
148-
const nlohmann::json json =
149-
odr::internal::util::meta::meta_to_json(file_meta);
146+
const nlohmann::json json = util::meta::meta_to_json(file_meta);
150147
std::ofstream o(meta_output);
151148
o << std::setw(4) << json << std::endl;
152149
EXPECT_TRUE(fs::is_regular_file(meta_output));
@@ -178,7 +175,7 @@ TEST_P(HtmlOutputTests, html_meta) {
178175

179176
std::string output_path_tmp = output_path + "/tmp";
180177
std::filesystem::create_directories(output_path_tmp);
181-
HtmlService service = odr::html::translate(file, output_path_tmp, config);
178+
HtmlService service = html::translate(file, output_path_tmp, config);
182179
Html html = service.bring_offline(output_path);
183180
std::filesystem::remove_all(output_path_tmp);
184181

@@ -191,19 +188,18 @@ TEST_P(HtmlOutputTests, html_meta) {
191188
namespace {
192189

193190
std::string engine_suffix(const DecoderEngine engine) {
194-
return engine == DecoderEngine::odr
195-
? ""
196-
: "-" + odr::decoder_engine_to_string(engine);
191+
return engine == DecoderEngine::odr ? ""
192+
: "-" + decoder_engine_to_string(engine);
197193
}
198194

199195
std::string test_params_to_name(const TestParams &params) {
200196
std::string path = params.path + engine_suffix(params.engine);
201-
internal::util::string::replace_all(path, "/", "_");
202-
internal::util::string::replace_all(path, "-", "_");
203-
internal::util::string::replace_all(path, "+", "_");
204-
internal::util::string::replace_all(path, ".", "_");
205-
internal::util::string::replace_all(path, " ", "_");
206-
internal::util::string::replace_all(path, "$", "");
197+
util::string::replace_all(path, "/", "_");
198+
util::string::replace_all(path, "-", "_");
199+
util::string::replace_all(path, "+", "_");
200+
util::string::replace_all(path, ".", "_");
201+
util::string::replace_all(path, " ", "_");
202+
util::string::replace_all(path, "$", "");
207203
return path;
208204
}
209205

@@ -237,7 +233,7 @@ TestParams create_test_params(const TestFile &test_file,
237233
std::vector<TestParams> list_test_params() {
238234
std::vector<TestParams> params;
239235
for (const TestFile &test_file : TestData::test_files()) {
240-
std::vector<DecoderEngine> engines = {DecoderEngine::odr};
236+
std::vector engines = {DecoderEngine::odr};
241237
if (test_file.type == FileType::portable_document_format) {
242238
engines.push_back(DecoderEngine::poppler);
243239
}

test/src/internal/cfb/cfb_archive_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <odr/internal/cfb/cfb_archive.hpp>
44
#include <odr/internal/cfb/cfb_file.hpp>
55
#include <odr/internal/cfb/cfb_util.hpp>
6+
#include <odr/internal/common/file.hpp>
67

78
#include <test_util.hpp>
89

test/src/internal/common/table_position_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,46 @@
77
using namespace odr::internal;
88

99
TEST(TablePosition, default) {
10-
TablePosition tp;
10+
const TablePosition tp;
1111
EXPECT_EQ(0, tp.row());
1212
EXPECT_EQ(0, tp.column());
1313
EXPECT_EQ("A1", tp.to_string());
1414
}
1515

1616
TEST(TablePosition, direct) {
17-
TablePosition tp(2, 1);
17+
const TablePosition tp(2, 1);
1818
EXPECT_EQ(2, tp.column());
1919
EXPECT_EQ(1, tp.row());
2020
EXPECT_EQ("C2", tp.to_string());
2121
}
2222

2323
TEST(TablePosition, string1) {
2424
const std::string input = "A1";
25-
TablePosition tp(input);
25+
const TablePosition tp(input);
2626
EXPECT_EQ(0, tp.column());
2727
EXPECT_EQ(0, tp.row());
2828
EXPECT_EQ(input, tp.to_string());
2929
}
3030

3131
TEST(TablePosition, string2) {
3232
const std::string input = "AA11";
33-
TablePosition tp(input);
33+
const TablePosition tp(input);
3434
EXPECT_EQ(26, tp.column());
3535
EXPECT_EQ(10, tp.row());
3636
EXPECT_EQ(input, tp.to_string());
3737
}
3838

3939
TEST(TablePosition, string3) {
4040
const std::string input = "ZZ1";
41-
TablePosition tp(input);
41+
const TablePosition tp(input);
4242
EXPECT_EQ(701, tp.column());
4343
EXPECT_EQ(0, tp.row());
4444
EXPECT_EQ(input, tp.to_string());
4545
}
4646

4747
TEST(TablePosition, string4) {
4848
const std::string input = "AAA1";
49-
TablePosition tp(input);
49+
const TablePosition tp(input);
5050
EXPECT_EQ(702, tp.column());
5151
EXPECT_EQ(0, tp.row());
5252
EXPECT_EQ(input, tp.to_string());

0 commit comments

Comments
 (0)