Skip to content

Commit 087b157

Browse files
committed
fix ods regressions
1 parent c78ebd7 commit 087b157

21 files changed

+235
-125
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ As an alternative to the Conan remote you can also export the package locally vi
3838
## Version
3939

4040
Versions and history are tracked on [GitHub](https://github.com/opendocument-app/OpenDocument.core).
41+
42+
## Testing
43+
44+
### Running the HTML Comparison Server
45+
46+
Scripts and Docker images can be found here https://github.com/opendocument-app/compare-html
47+
48+
```bash
49+
./test/scripts/compare_output_server.sh
50+
```

cli/src/server.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
#include "odr/archive.hpp"
2+
13
#include <odr/exceptions.hpp>
24
#include <odr/file.hpp>
5+
#include <odr/filesystem.hpp>
36
#include <odr/html.hpp>
47
#include <odr/http_server.hpp>
58

@@ -9,7 +12,8 @@
912
using namespace odr;
1013

1114
int main(const int argc, char **argv) {
12-
auto logger = Logger::create_stdio("odr-server", LogLevel::verbose);
15+
std::shared_ptr logger =
16+
Logger::create_stdio("odr-server", LogLevel::verbose);
1317

1418
std::string input{argv[1]};
1519

@@ -48,15 +52,36 @@ int main(const int argc, char **argv) {
4852
html_config.editable = true;
4953

5054
{
51-
std::string prefix = "one_file";
52-
HtmlViews views = server.serve_file(decoded_file, prefix, html_config);
55+
constexpr std::string prefix = "file";
56+
const HtmlViews views =
57+
server.serve_file(decoded_file, prefix, html_config);
5358
ODR_INFO(*logger, "hosted decoded file with id: " << prefix);
5459
for (const auto &view : views) {
5560
ODR_INFO(*logger,
5661
"http://localhost:8080/file/" << prefix << "/" << view.path());
5762
}
5863
}
5964

65+
if (decoded_file.is_document_file() || decoded_file.is_archive_file()) {
66+
std::optional<Filesystem> filesystem;
67+
if (decoded_file.is_document_file()) {
68+
filesystem = decoded_file.as_document_file().document().as_filesystem();
69+
} else if (decoded_file.is_archive_file()) {
70+
filesystem = decoded_file.as_archive_file().archive().as_filesystem();
71+
}
72+
73+
constexpr std::string prefix = "filesystem";
74+
const HtmlService filesystem_service = html::translate(
75+
filesystem.value(), server_config.cache_path + "/" + prefix,
76+
html_config, logger);
77+
server.connect_service(filesystem_service, prefix);
78+
ODR_INFO(*logger, "hosted filesystem with id: " << prefix);
79+
for (const auto &view : filesystem_service.list_views()) {
80+
ODR_INFO(*logger,
81+
"http://localhost:8080/file/" << prefix << "/" << view.path());
82+
}
83+
}
84+
6085
server.listen("localhost", 8080);
6186

6287
return 0;

src/odr/document_element.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ TableRowStyle Sheet::row_style(const std::uint32_t row) const {
276276
: TableRowStyle();
277277
}
278278

279+
TableCellStyle Sheet::cell_style(const std::uint32_t column,
280+
const std::uint32_t row) const {
281+
return exists_() ? m_adapter2->sheet_cell_style(m_identifier, column, row)
282+
: TableCellStyle();
283+
}
284+
279285
TablePosition SheetCell::position() const {
280286
return exists_() ? m_adapter2->sheet_cell_position(m_identifier)
281287
: TablePosition(0, 0);
@@ -295,11 +301,6 @@ ValueType SheetCell::value_type() const {
295301
: ValueType::unknown;
296302
}
297303

298-
TableCellStyle SheetCell::style() const {
299-
return exists_() ? m_adapter2->sheet_cell_style(m_identifier)
300-
: TableCellStyle();
301-
}
302-
303304
std::string Page::name() const {
304305
return exists_() ? m_adapter2->page_name(m_identifier) : "";
305306
}

src/odr/document_element.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ class Sheet final : public ElementBase<internal::abstract::SheetAdapter> {
294294
[[nodiscard]] TableStyle style() const;
295295
[[nodiscard]] TableColumnStyle column_style(std::uint32_t column) const;
296296
[[nodiscard]] TableRowStyle row_style(std::uint32_t row) const;
297+
[[nodiscard]] TableCellStyle cell_style(std::uint32_t column,
298+
std::uint32_t row) const;
297299
};
298300

299301
/// @brief Represents a sheet cell element in a document.
@@ -306,8 +308,6 @@ class SheetCell final
306308
[[nodiscard]] bool is_covered() const;
307309
[[nodiscard]] TableDimensions span() const;
308310
[[nodiscard]] ValueType value_type() const;
309-
310-
[[nodiscard]] TableCellStyle style() const;
311311
};
312312

313313
/// @brief Represents a page element in a document.

src/odr/filesystem.cpp

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace odr {
99

10-
FileWalker::FileWalker() = default;
11-
1210
FileWalker::FileWalker(std::unique_ptr<internal::abstract::FileWalker> impl)
13-
: m_impl{std::move(impl)} {}
11+
: m_impl{std::move(impl)} {
12+
if (m_impl == nullptr) {
13+
throw std::invalid_argument("impl must not be null");
14+
}
15+
}
1416

1517
FileWalker::FileWalker(const FileWalker &other)
1618
: m_impl{other.m_impl->clone()} {}
@@ -29,71 +31,48 @@ FileWalker &FileWalker::operator=(const FileWalker &other) {
2931

3032
FileWalker &FileWalker::operator=(FileWalker &&) noexcept = default;
3133

32-
FileWalker::operator bool() const { return m_impl != nullptr; }
34+
bool FileWalker::end() const { return m_impl->end(); }
3335

34-
bool FileWalker::end() const { return m_impl == nullptr || m_impl->end(); }
36+
std::uint32_t FileWalker::depth() const { return m_impl->depth(); }
3537

36-
std::uint32_t FileWalker::depth() const {
37-
return m_impl != nullptr ? m_impl->depth() : 0;
38-
}
38+
std::string FileWalker::path() const { return m_impl->path().string(); }
3939

40-
std::string FileWalker::path() const {
41-
return m_impl != nullptr ? m_impl->path().string() : std::string("");
42-
}
40+
bool FileWalker::is_file() const { return m_impl->is_file(); }
4341

44-
bool FileWalker::is_file() const {
45-
return m_impl != nullptr && m_impl->is_file();
46-
}
42+
bool FileWalker::is_directory() const { return m_impl->is_directory(); }
4743

48-
bool FileWalker::is_directory() const {
49-
return m_impl != nullptr && m_impl->is_directory();
50-
}
44+
void FileWalker::pop() const { m_impl->pop(); }
5145

52-
void FileWalker::pop() const {
53-
if (m_impl != nullptr) {
54-
m_impl->pop();
55-
}
56-
}
46+
void FileWalker::next() const { m_impl->next(); }
5747

58-
void FileWalker::next() const {
59-
if (m_impl != nullptr) {
60-
m_impl->next();
61-
}
62-
}
63-
64-
void FileWalker::flat_next() const {
65-
if (m_impl != nullptr) {
66-
m_impl->flat_next();
67-
}
68-
}
48+
void FileWalker::flat_next() const { m_impl->flat_next(); }
6949

7050
Filesystem::Filesystem(
7151
std::shared_ptr<internal::abstract::ReadableFilesystem> impl)
72-
: m_impl{std::move(impl)} {}
73-
74-
Filesystem::operator bool() const { return m_impl != nullptr; }
52+
: m_impl{std::move(impl)} {
53+
if (m_impl == nullptr) {
54+
throw std::invalid_argument("impl must not be null");
55+
}
56+
}
7557

7658
bool Filesystem::exists(const std::string &path) const {
77-
return m_impl != nullptr && m_impl->exists(internal::AbsPath(path));
59+
return m_impl->exists(internal::AbsPath(path));
7860
}
7961

8062
bool Filesystem::is_file(const std::string &path) const {
81-
return m_impl != nullptr && m_impl->is_file(internal::AbsPath(path));
63+
return m_impl->is_file(internal::AbsPath(path));
8264
}
8365

8466
bool Filesystem::is_directory(const std::string &path) const {
85-
return m_impl != nullptr && m_impl->is_directory(internal::AbsPath(path));
67+
return m_impl->is_directory(internal::AbsPath(path));
8668
}
8769

8870
FileWalker Filesystem::file_walker(const std::string &path) const {
89-
return m_impl != nullptr
90-
? FileWalker(m_impl->file_walker(internal::AbsPath(path)))
91-
: FileWalker();
71+
return FileWalker(m_impl->file_walker(internal::AbsPath(path)));
9272
}
9373

9474
File Filesystem::open(const std::string &path) const {
95-
return m_impl != nullptr ? File(m_impl->open(internal::AbsPath(path)))
96-
: File();
75+
return File(m_impl->open(internal::AbsPath(path)));
9776
}
9877

9978
} // namespace odr

src/odr/filesystem.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ class File;
1414
/// @brief FileWalker class
1515
class FileWalker {
1616
public:
17-
FileWalker();
1817
explicit FileWalker(std::unique_ptr<internal::abstract::FileWalker>);
1918
FileWalker(const FileWalker &);
2019
FileWalker(FileWalker &&) noexcept;
2120
~FileWalker();
2221

2322
FileWalker &operator=(const FileWalker &);
2423
FileWalker &operator=(FileWalker &&) noexcept;
25-
[[nodiscard]] explicit operator bool() const;
2624

2725
[[nodiscard]] bool end() const;
2826
[[nodiscard]] std::uint32_t depth() const;
@@ -43,8 +41,6 @@ class Filesystem {
4341
public:
4442
explicit Filesystem(std::shared_ptr<internal::abstract::ReadableFilesystem>);
4543

46-
[[nodiscard]] explicit operator bool() const;
47-
4844
[[nodiscard]] bool exists(const std::string &path) const;
4945
[[nodiscard]] bool is_file(const std::string &path) const;
5046
[[nodiscard]] bool is_directory(const std::string &path) const;

src/odr/html.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,21 @@ HtmlService html::translate(const PdfFile &pdf_file,
326326
std::move(logger));
327327
}
328328

329-
HtmlService html::translate(const Archive &archive,
329+
HtmlService html::translate(const Filesystem &filesystem,
330330
const std::string &cache_path,
331331
const HtmlConfig &config,
332332
std::shared_ptr<Logger> logger) {
333333
std::filesystem::create_directories(cache_path);
334-
return internal::html::create_filesystem_service(
335-
archive.as_filesystem(), cache_path, config, std::move(logger));
334+
return internal::html::create_filesystem_service(filesystem, cache_path,
335+
config, std::move(logger));
336+
}
337+
338+
HtmlService html::translate(const Archive &archive,
339+
const std::string &cache_path,
340+
const HtmlConfig &config,
341+
std::shared_ptr<Logger> logger) {
342+
return translate(archive.as_filesystem(), cache_path, config,
343+
std::move(logger));
336344
}
337345

338346
HtmlService html::translate(const Document &document,

src/odr/html.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class HtmlResource;
1919

2020
namespace odr {
2121
class Archive;
22+
class Filesystem;
2223
struct HtmlPage;
2324
class HtmlService;
2425
struct HtmlConfig;
@@ -259,6 +260,16 @@ HtmlService translate(const PdfFile &pdf_file, const std::string &cache_path,
259260
const HtmlConfig &config,
260261
std::shared_ptr<Logger> logger = Logger::create_null());
261262

263+
/// @brief Translates a filesystem to HTML.
264+
///
265+
/// @param filesystem Filesystem to translate.
266+
/// @param cache_path Directory path for temporary output.
267+
/// @param config Configuration for the HTML output.
268+
/// @param logger Logger to use for logging.
269+
/// @return HTML output.
270+
HtmlService translate(const Filesystem &filesystem,
271+
const std::string &cache_path, const HtmlConfig &config,
272+
std::shared_ptr<Logger> logger = Logger::create_null());
262273
/// @brief Translates an archive to HTML.
263274
///
264275
/// @param archive Archive to translate.

src/odr/http_server.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class HttpServer {
1818
constexpr static auto prefix_pattern = R"(([a-zA-Z0-9_-]+))";
1919

2020
struct Config {
21+
// TODO remove
2122
std::string cache_path{"/tmp/odr"};
2223
};
2324

@@ -28,6 +29,7 @@ class HttpServer {
2829

2930
void connect_service(HtmlService service, const std::string &prefix) const;
3031

32+
// TODO remove
3133
[[nodiscard]] HtmlViews serve_file(const DecodedFile &file,
3234
const std::string &prefix,
3335
const HtmlConfig &config) const;

src/odr/internal/abstract/document_element.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class SheetAdapter {
172172
std::uint32_t column) const = 0;
173173
[[nodiscard]] virtual TableRowStyle
174174
sheet_row_style(ElementIdentifier element_id, std::uint32_t row) const = 0;
175+
[[nodiscard]] virtual TableCellStyle
176+
sheet_cell_style(ElementIdentifier element_id, std::uint32_t column,
177+
std::uint32_t row) const = 0;
175178
};
176179

177180
class SheetCellAdapter {
@@ -187,9 +190,6 @@ class SheetCellAdapter {
187190
sheet_cell_span(ElementIdentifier element_id) const = 0;
188191
[[nodiscard]] virtual ValueType
189192
sheet_cell_value_type(ElementIdentifier element_id) const = 0;
190-
191-
[[nodiscard]] virtual TableCellStyle
192-
sheet_cell_style(ElementIdentifier element_id) const = 0;
193193
};
194194

195195
class MasterPageAdapter {

0 commit comments

Comments
 (0)