Skip to content

Commit

Permalink
add wvWare wrapper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusSutkus89 committed Aug 28, 2024
1 parent 04fd03d commit 7a3e1e9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ if(WITH_PDF2HTMLEX)
"src/pdf2htmlEX_wrapper_test.cpp"
)
endif(WITH_PDF2HTMLEX)
if(WITH_WVWARE)
LIST(APPEND ODR_TEST_SOURCE_FILES
"src/wvWare_wrapper_test.cpp"
)
endif(WITH_WVWARE)
add_executable(odr_test
"src/test_util.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/src/test_constants.cpp"
Expand Down Expand Up @@ -74,4 +79,8 @@ target_link_libraries(odr_test
if(WITH_PDF2HTMLEX)
target_link_libraries(odr_test PRIVATE pdf2htmlex::pdf2htmlex)
endif(WITH_PDF2HTMLEX)
if(WITH_WVWARE)
target_link_libraries(odr_test PRIVATE wvware::wvware)
endif(WITH_WVWARE)

gtest_add_tests(TARGET odr_test)
67 changes: 67 additions & 0 deletions test/src/wvWare_wrapper_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <filesystem>
#include <iostream>
#include <optional>
#include <string>

#include <gtest/gtest.h>
#include <test_util.hpp>

#include <odr/html.hpp>
#include <odr/internal/common/path.hpp>
#include <odr/internal/html/wvWare_wrapper.hpp>
#include <odr/internal/util/string_util.hpp>

using namespace odr;
using namespace odr::test;
using namespace odr::internal;
using namespace odr::test;
namespace fs = std::filesystem;

using wvWareWrapperTests = ::testing::TestWithParam<std::string>;

TEST_P(wvWareWrapperTests, html) {
const std::string test_file_path = GetParam();
const TestFile test_file = TestData::test_file(test_file_path);

const std::string test_repo = *common::Path(test_file_path).begin();
const std::string output_path_prefix = common::Path("output")
.join(test_repo)
.join("output")
.join("wvWare")
.string();
const std::string output_path =
common::Path(output_path_prefix)
.join(common::Path(test_file_path).rebase(test_repo))
.string();

std::cout << test_file.path << " to " << output_path << std::endl;

if (!util::string::ends_with(test_file.path, ".doc") &&
test_file.type != FileType::legacy_word_document) {
GTEST_SKIP();
}

fs::create_directories(output_path);
HtmlConfig config;
std::optional<std::string> password;
Html html = odr::internal::html::wvWare_wrapper(
test_file.path, output_path, config, password);

for (const HtmlPage &html_page : html.pages()) {
EXPECT_TRUE(fs::is_regular_file(html_page.path));
EXPECT_LT(0, fs::file_size(html_page.path));
}
}

INSTANTIATE_TEST_SUITE_P(all_test_files, wvWareWrapperTests,
testing::ValuesIn(TestData::test_file_paths()),
[](const ::testing::TestParamInfo<std::string> &info) {
std::string path = info.param;
internal::util::string::replace_all(path, "/", "_");
internal::util::string::replace_all(path, "-", "_");
internal::util::string::replace_all(path, "+", "_");
internal::util::string::replace_all(path, ".", "_");
internal::util::string::replace_all(path, " ", "_");
internal::util::string::replace_all(path, "$", "");
return path;
});

0 comments on commit 7a3e1e9

Please sign in to comment.