@@ -25,11 +25,11 @@ TEST(Document, odt) {
2525 EXPECT_EQ (document.document_type (), DocumentType::text);
2626
2727 const auto page_layout = document.root_element ().as_text_root ().page_layout ();
28- EXPECT_TRUE (page_layout.width );
28+ EXPECT_TRUE (page_layout.width . has_value () );
2929 EXPECT_EQ (Measure (" 8.2673in" ), page_layout.width );
30- EXPECT_TRUE (page_layout.height );
30+ EXPECT_TRUE (page_layout.height . has_value () );
3131 EXPECT_EQ (Measure (" 11.6925in" ), page_layout.height );
32- EXPECT_TRUE (page_layout.margin .top );
32+ EXPECT_TRUE (page_layout.margin .top . has_value () );
3333 EXPECT_EQ (Measure (" 0.7874in" ), page_layout.margin .top );
3434}
3535
@@ -91,11 +91,11 @@ TEST(Document, odg) {
9191
9292 for (auto child : document.root_element ().children ()) {
9393 auto page_layout = child.as_page ().page_layout ();
94- EXPECT_TRUE (page_layout.width );
94+ EXPECT_TRUE (page_layout.width . has_value () );
9595 EXPECT_EQ (Measure (" 21cm" ), page_layout.width );
96- EXPECT_TRUE (page_layout.height );
96+ EXPECT_TRUE (page_layout.height . has_value () );
9797 EXPECT_EQ (Measure (" 29.7cm" ), page_layout.height );
98- EXPECT_TRUE (page_layout.margin .top );
98+ EXPECT_TRUE (page_layout.margin .top . has_value () );
9999 EXPECT_EQ (Measure (" 1cm" ), page_layout.margin .top );
100100 }
101101}
@@ -107,7 +107,7 @@ TEST(Document, edit_odt) {
107107 TestData::test_file_path (" odr-public/odt/about.odt" ), *logger);
108108 const Document document = document_file.document ();
109109
110- std::function<void (Element)> edit = [&](const Element element) {
110+ std::function<void (Element)> edit = [&](const Element & element) {
111111 for (const Element child : element.children ()) {
112112 edit (child);
113113 }
@@ -124,7 +124,7 @@ TEST(Document, edit_odt) {
124124
125125 const DocumentFile validate_file (output_path);
126126 const Document validate_document = validate_file.document ();
127- std::function<void (Element)> validate = [&](const Element element) {
127+ std::function<void (Element)> validate = [&](const Element & element) {
128128 for (const Element child : element.children ()) {
129129 validate (child);
130130 }
@@ -144,7 +144,7 @@ TEST(Document, edit_docx) {
144144 *logger);
145145 const Document document = document_file.document ();
146146
147- std::function<void (Element)> edit = [&](const Element element) {
147+ std::function<void (Element)> edit = [&](const Element & element) {
148148 for (const Element child : element.children ()) {
149149 edit (child);
150150 }
@@ -161,7 +161,7 @@ TEST(Document, edit_docx) {
161161
162162 const DocumentFile validate_file (output_path);
163163 const Document validate_document = validate_file.document ();
164- std::function<void (Element)> validate = [&](const Element element) {
164+ std::function<void (Element)> validate = [&](const Element & element) {
165165 for (const Element child : element.children ()) {
166166 validate (child);
167167 }
@@ -208,62 +208,61 @@ TEST(Document, edit_odt_diff) {
208208 .content ());
209209}
210210
211- // TODO make sheet editing work by implementing table addressing
212- // TEST(Document, edit_ods_diff) {
213- // auto logger = Logger::create_stdio("odr-test", LogLevel::verbose);
214- //
215- // auto diff =
216- // R"({"modifiedText":{"/child:0/row:0/child:0/child:0/child:0":"Page 1
217- // hi","/child:1/row:0/child:0/child:0/child:0":"Page 2
218- // hihi","/child:2/row:0/child:0/child:0/child:0":"Page 3
219- // hihihi","/child:3/row:0/child:0/child:0/child:0":"Page 4
220- // hihihihi","/child:4/row:0/child:0/child:0/child:0":"Page 5
221- // hihihihihi"}})";
222- // DocumentFile document_file(
223- // TestData::test_file_path("odr-public/ods/pages.ods"), *logger);
224- // document_file = document_file.decrypt(
225- // TestData::test_file("odr-public/ods/pages.ods").password.value());
226- // Document document = document_file.document();
227- //
228- // html::edit(document, diff);
229- //
230- // std::string output_path =
231- // (std::filesystem::current_path() / "pages_edit_diff.ods").string();
232- // document.save(output_path);
233- //
234- // DocumentFile validate_file(output_path);
235- // Document validate_document = validate_file.document();
236- // EXPECT_EQ(
237- // "Page 1 hi",
238- // DocumentPath::find(validate_document.root_element(),
239- // DocumentPath("/child:0/row:0/child:0/child:0/child:0"))
240- // .as_text()
241- // .content());
242- // EXPECT_EQ(
243- // "Page 2 hihi",
244- // DocumentPath::find(validate_document.root_element(),
245- // DocumentPath("/child:1/row:0/child:0/child:0/child:0"))
246- // .as_text()
247- // .content());
248- // EXPECT_EQ(
249- // "Page 3 hihihi",
250- // DocumentPath::find(validate_document.root_element(),
251- // DocumentPath("/child:2/row:0/child:0/child:0/child:0"))
252- // .as_text()
253- // .content());
254- // EXPECT_EQ(
255- // "Page 4 hihihihi",
256- // DocumentPath::find(validate_document.root_element(),
257- // DocumentPath("/child:3/row:0/child:0/child:0/child:0"))
258- // .as_text()
259- // .content());
260- // EXPECT_EQ(
261- // "Page 5 hihihihihi",
262- // DocumentPath::find(validate_document.root_element(),
263- // DocumentPath("/child:4/row:0/child:0/child:0/child:0"))
264- // .as_text()
265- // .content());
266- // }
211+ TEST (Document, edit_ods_diff) {
212+ const auto logger = Logger::create_stdio (" odr-test" , LogLevel::verbose);
213+
214+ const auto diff =
215+ R"( {"modifiedText":{"/child:0/row:0/child:0/child:0/child:0":"Page 1
216+ hi","/child:1/row:0/child:0/child:0/child:0":"Page 2
217+ hihi","/child:2/row:0/child:0/child:0/child:0":"Page 3
218+ hihihi","/child:3/row:0/child:0/child:0/child:0":"Page 4
219+ hihihihi","/child:4/row:0/child:0/child:0/child:0":"Page 5
220+ hihihihihi"}})" ;
221+ DocumentFile document_file (
222+ TestData::test_file_path (" odr-public/ods/pages.ods" ), *logger);
223+ document_file = document_file.decrypt (
224+ TestData::test_file (" odr-public/ods/pages.ods" ).password .value ());
225+ const Document document = document_file.document ();
226+
227+ html::edit (document, diff);
228+
229+ const std::string output_path =
230+ (std::filesystem::current_path () / " pages_edit_diff.ods" ).string ();
231+ document.save (output_path);
232+
233+ const DocumentFile validate_file (output_path);
234+ const Document validate_document = validate_file.document ();
235+ EXPECT_EQ (
236+ " Page 1 hi" ,
237+ DocumentPath::find (validate_document.root_element (),
238+ DocumentPath (" /child:0/row:0/child:0/child:0/child:0" ))
239+ .as_text ()
240+ .content ());
241+ EXPECT_EQ (
242+ " Page 2 hihi" ,
243+ DocumentPath::find (validate_document.root_element (),
244+ DocumentPath (" /child:1/row:0/child:0/child:0/child:0" ))
245+ .as_text ()
246+ .content ());
247+ EXPECT_EQ (
248+ " Page 3 hihihi" ,
249+ DocumentPath::find (validate_document.root_element (),
250+ DocumentPath (" /child:2/row:0/child:0/child:0/child:0" ))
251+ .as_text ()
252+ .content ());
253+ EXPECT_EQ (
254+ " Page 4 hihihihi" ,
255+ DocumentPath::find (validate_document.root_element (),
256+ DocumentPath (" /child:3/row:0/child:0/child:0/child:0" ))
257+ .as_text ()
258+ .content ());
259+ EXPECT_EQ (
260+ " Page 5 hihihihihi" ,
261+ DocumentPath::find (validate_document.root_element (),
262+ DocumentPath (" /child:4/row:0/child:0/child:0/child:0" ))
263+ .as_text ()
264+ .content ());
265+ }
267266
268267TEST (Document, edit_docx_diff) {
269268 const auto logger = Logger::create_stdio (" odr-test" , LogLevel::verbose);
0 commit comments