From e3dce9b7b82f4dbf73c51066bb87e5df51218120 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Sat, 13 Jun 2026 06:41:10 +0000 Subject: [PATCH 1/3] Enable test_odf gtest suite under CTest Migrate the OdfFile/Test/test_odf GoogleTest suite from its qmake .pro to a CMake target registered with CTest, matching the .pro which builds only test.cpp + common.cpp (entrance/motion/audio/interactions modules stay commented out). - Add OdfFile/Test/test_odf/CMakeLists.txt using the add_core_gtest() helper. The suite owns its main(), so no GTEST_MAIN. Link OdfFormatLib (provides ConvertODF2OOXml) plus kernel/graphics/UnicodeConverter, and compile OfficeFileFormatChecker2.cpp, pole.cpp and unicode_util.cpp into the target (mirroring Test/Applications/x2tTester, which uses the same format-checker sources). Add the core root and X2tConverter/src to the include path. - Stage ExampleFiles/ next to the binary via a POST_BUILD copy_directory and run the test from that directory, since TestEnv loads the fixture through the working-dir-relative path "ExampleFiles/motion.odp". - Fix common.cpp: the committed file used absolute Windows include paths (D:\ONLYOFFICE\core\...), , and a per-platform "#pragma comment(lib, ...)" block, none of which build on Linux. Replace them with repo-relative includes; libraries are linked by CMake. - Register the suite in the top-level CMakeLists.txt EO_BUILD_TESTS block and move it to the Done list in TESTING.md. https: //claude.ai/code/session_01TJrhgZT4PwYaBKWiUCXmGg Signed-off-by: Julius Knorr Assisted-by: Claude Code:Opus 4.8 --- CMakeLists.txt | 1 + OdfFile/Test/test_odf/CMakeLists.txt | 64 ++++++++++++++++++++++++++++ OdfFile/Test/test_odf/common.cpp | 36 ++++------------ TESTING.md | 14 +++++- 4 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 OdfFile/Test/test_odf/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e6662ce8f..ca498cfeab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ else() add_subdirectory( "${CORE_ROOT_DIR}/OOXML/test" ooxml_test ) add_subdirectory( "${CORE_ROOT_DIR}/OfficeUtils/tests" officeutils_test ) add_subdirectory( "${CORE_ROOT_DIR}/OdfFile/Reader/Converter/SMCustomShape2OOXML/TestSMCustomShape" starmath_smcustomshape_test ) + add_subdirectory( "${CORE_ROOT_DIR}/OdfFile/Test/test_odf" test_odf ) endif() endif() diff --git a/OdfFile/Test/test_odf/CMakeLists.txt b/OdfFile/Test/test_odf/CMakeLists.txt new file mode 100644 index 0000000000..21f7c1f611 --- /dev/null +++ b/OdfFile/Test/test_odf/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 3.10) + +project(test_odf) + +# This directory is three levels under the repository root +# (OdfFile/Test/test_odf). +set(CORE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..") + +include(${CORE_ROOT_DIR}/common.cmake) + +# Dependencies. test_odf.pro builds only test.cpp + common.cpp (the +# entrance/motion/audio/interactions modules are commented out) and converts an +# .odp fixture via ConvertODF2OOXml() + COfficeFileFormatChecker. +# +# ConvertODF2OOXml() lives in OdfFormatLib; COfficeFileFormatChecker is compiled +# from OfficeFileFormatChecker2.cpp (+ pole.cpp + unicode_util.cpp) directly into +# the target, mirroring how Test/Applications/x2tTester does it. kernel/graphics/ +# UnicodeConverter satisfy the rest of the chain. +if(NOT TARGET kernel) + add_subdirectory(${CORE_ROOT_DIR}/Common kernel) +endif() +if(NOT TARGET UnicodeConverter) + add_subdirectory(${CORE_ROOT_DIR}/UnicodeConverter UnicodeConverter) +endif() +if(NOT TARGET graphics) + add_subdirectory(${CORE_ROOT_DIR}/DesktopEditor/graphics/cmake graphics) +endif() +if(NOT TARGET OdfFormatLib) + add_subdirectory(${CORE_ROOT_DIR}/OdfFile/Projects/Linux OdfFormatLib) +endif() + +# The test reads its fixture via the working-dir-relative path +# "ExampleFiles/motion.odp" (TestEnv passes it straight to convert_single()). +# Stage the committed ExampleFiles next to the binary and run the test from that +# staging dir so the relative path resolves. +set(_test_odf_run_dir "${CMAKE_CURRENT_BINARY_DIR}/run") + +# test.cpp owns main() (InitGoogleTest + AddGlobalTestEnvironment + RUN_ALL_TESTS) +# -> do NOT pass GTEST_MAIN. +add_core_gtest( + NAME test_odf + SOURCES test.cpp + common.cpp + ${CORE_ROOT_DIR}/Common/3dParty/pole/pole.cpp + ${CORE_ROOT_DIR}/Common/OfficeFileFormatChecker2.cpp + ${CORE_ROOT_DIR}/OOXML/Base/unicode_util.cpp + LIBS OdfFormatLib kernel graphics UnicodeConverter + WORKING_DIRECTORY "${_test_odf_run_dir}" +) + +# test_odf.pro adds the core root (for the rewritten relative includes such as +# "Common/OfficeFileFormatChecker.h") and X2tConverter/src on the include path. +target_include_directories(test_odf PRIVATE + "${CORE_ROOT_DIR}" + "${CORE_ROOT_DIR}/X2tConverter/src" +) + +add_custom_command(TARGET test_odf POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${_test_odf_run_dir}" + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/ExampleFiles" + "${_test_odf_run_dir}/ExampleFiles" + COMMENT "Staging test_odf fixtures" +) diff --git a/OdfFile/Test/test_odf/common.cpp b/OdfFile/Test/test_odf/common.cpp index 7af4f38d47..5743760cec 100644 --- a/OdfFile/Test/test_odf/common.cpp +++ b/OdfFile/Test/test_odf/common.cpp @@ -224,34 +224,16 @@ ////////////////////////////////////////////////////////////////////////// #include -#include -#include "D:\ONLYOFFICE\core\Common\OfficeFileFormatChecker.h" -#include "D:\ONLYOFFICE\core\OfficeUtils\src\OfficeUtils.h" -#include "D:\ONLYOFFICE\core\DesktopEditor\common\Directory.h" -#include "D:\ONLYOFFICE\core\OdfFile\Reader\Converter\ConvertOO2OOX.h" -#include "D:\ONLYOFFICE\core\OdfFile\Common\logging.h" - -#if defined(_WIN64) -#pragma comment(lib, "D:/ONLYOFFICE/core/Common/3dParty/icu/win_64/build/icuuc.lib") -#pragma comment(lib, "D:/ONLYOFFICE/core/build/lib/win_64/DEBUG/graphics.lib") -#pragma comment(lib, "D:/ONLYOFFICE/core/build/lib/win_64/DEBUG/kernel.lib") -#pragma comment(lib, "D:/ONLYOFFICE/core/build/lib/win_64/DEBUG/UnicodeConverter.lib") -#pragma comment(lib, "D:/ONLYOFFICE/core/build/lib/win_64/DEBUG/CryptoPPLib.lib") - -#elif defined (_WIN32) - -#if defined(DEBUG) -#pragma comment(lib, "../../../../build/lib/win_32/DEBUG/graphics.lib") -#pragma comment(lib, "../../../../build/lib/win_32/DEBUG/kernel.lib") -#pragma comment(lib, "../../../../build/lib/win_32/DEBUG/UnicodeConverter.dll") -#else -#pragma comment(lib, "../../../../build/lib/win_32/graphics.lib") -#pragma comment(lib, "../../../../build/lib/win_32/kernel.lib") -#pragma comment(lib, "../../../../build/lib/win_32/UnicodeConverter.dll") -#endif -#pragma comment(lib, "../../../../build/bin/icu/win_32/icuuc.lib") -#endif +// Resolved relative to the repository root (the CMake target adds the core +// root to the include path). The original sources used absolute Windows paths +// and a per-platform "#pragma comment(lib, ...)" block; libraries are now +// linked by CMake (see CMakeLists.txt), so those are gone. +#include "Common/OfficeFileFormatChecker.h" +#include "OfficeUtils/src/OfficeUtils.h" +#include "DesktopEditor/common/Directory.h" +#include "OdfFile/Reader/Converter/ConvertOO2OOX.h" +#include "OdfFile/Common/logging.h" HRESULT convert_single(std::wstring srcFileName) { diff --git a/TESTING.md b/TESTING.md index 59756d60b2..4835b8aff1 100644 --- a/TESTING.md +++ b/TESTING.md @@ -87,13 +87,23 @@ Done: - [x] `OdfFile/Reader/Converter/SMCustomShape2OOXML/TestSMCustomShape` — dep: SMCustomShape2OOXML (new CMake library target created for this suite; itself depends on UnicodeConverter, kernel). No fixtures. +- [x] `OdfFile/Test/test_odf` — deps: OdfFormatLib (for `ConvertODF2OOXml`), kernel, + graphics, UnicodeConverter; `OfficeFileFormatChecker2.cpp`, `pole.cpp` and + `unicode_util.cpp` are compiled into the target (as `x2tTester` does). Owns its + `main()` (so no `GTEST_MAIN`). Builds only `test.cpp` + `common.cpp` — the + entrance/motion/audio/interactions modules are commented out in the `.pro`, so the + suite registers no `TEST()` cases yet; the global `TestEnv` still exercises an + `.odp -> .pptx` conversion in its `SetUp()`. Fixtures under `ExampleFiles/` are + staged next to the binary and the test runs from there (the fixture path + `ExampleFiles/motion.odp` is working-dir-relative). The committed `common.cpp` had + absolute Windows include paths and a `#pragma comment(lib, ...)` block; these were + replaced with repo-relative includes (CMake links the libraries). ### gtest suites to migrate Runnable headless once migrated (no missing fixtures, no JS engine): -- [ ] `OdfFile/Test/test_odf` — OdfFormatLib dependency chain; own `main`. Fixtures - committed under `test_odf/ExampleFiles/`. +_(none — all migrated; see Done above.)_ Blocked / need extra work (build targets intentionally not created yet): From 919f16dcf862a94bcc16c7f946124533790d971f Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Sat, 13 Jun 2026 06:41:11 +0000 Subject: [PATCH 2/3] build: link OdfFormatLib against the OOXML format libraries The standalone test_odf link failed with hundreds of undefined references from libOdfFormatLib.a (XmlUtils::EncodeXmlString, SimpleTypes::*, OOX::WritingElement /CPath, OOX::Logic math classes, PPTX::Namespaces). OdfFormatLib's ODF->OOXML writer depends on the OOXML format code, but its CMake target only linked kernel/UnicodeConverter -- those OOXML symbols were previously satisfied only when everything was linked together inside x2tlib. Declare DocxFormatLib and PPTXFormatLib (the OOXML format library targets that compile that code) as PUBLIC dependencies of OdfFormatLib so it links standalone and any consumer (e.g. the test_odf suite) resolves the symbols transitively. Signed-off-by: Julius Knorr Assisted-by: Claude Code:Opus 4.8 --- OdfFile/Projects/Linux/CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OdfFile/Projects/Linux/CMakeLists.txt b/OdfFile/Projects/Linux/CMakeLists.txt index 29e58ace4a..679e7b0aed 100644 --- a/OdfFile/Projects/Linux/CMakeLists.txt +++ b/OdfFile/Projects/Linux/CMakeLists.txt @@ -18,6 +18,19 @@ if(NOT TARGET UnicodeConverter) add_subdirectory(${CORE_ROOT_DIR}/UnicodeConverter UnicodeConverter) endif() +# The ODF->OOXML writer references OOXML format code (XmlUtils, SimpleTypes, +# OOX::WritingElement/CPath, the math logic classes and PPTX::Namespaces). Those +# symbols live in the OOXML format libraries; declare them as dependencies so +# OdfFormatLib links standalone (previously they were only satisfied when the +# whole x2t library was linked together). +if(NOT TARGET DocxFormatLib) + add_subdirectory(${CORE_ROOT_DIR}/OOXML/Projects/Linux/DocxFormatLib DocxFormatLib) +endif() + +if(NOT TARGET PPTXFormatLib) + add_subdirectory(${CORE_ROOT_DIR}/OOXML/Projects/Linux/PPTXFormatLib PPTXFormatLib) +endif() + add_library(OdfFormatLib STATIC ${CMAKE_CURRENT_LIST_DIR}/odf_converter.cpp ${CMAKE_CURRENT_LIST_DIR}/odf_datatypes.cpp @@ -491,6 +504,8 @@ endif() target_link_libraries(OdfFormatLib PUBLIC UnicodeConverter kernel + DocxFormatLib + PPTXFormatLib Boost::system Boost::filesystem Boost::regex From bb0b262fb6e7c1c159c84fb23d41366e38688731 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Sat, 13 Jun 2026 06:41:11 +0000 Subject: [PATCH 3/3] build: link test_odf against the full converter library group The standalone test_odf link cascaded: OdfFormatLib needs the OOXML format libs, which in turn need the XLS/XLSB libs, etc. Those static archives reference each other and are only ever linked together inside x2tlib (the core libraries are built with -fvisibility=hidden, so linking x2tlib.so cannot resolve the test's direct ConvertODF2OOXml call). Instead of partially wiring shared-library dependencies (reverted from OdfFormatLib), instantiate the same target set via the x2tlib "library" subdirectory and link the OOXML/MS format static archives inside a --start-group, plus the shared converter libs -- mirroring x2tlib's own link. OfficeFileFormatChecker2.cpp is compiled into the test (no format lib provides it); unicode_util.cpp/pole.cpp are dropped since DocxFormatLib supplies them. Signed-off-by: Julius Knorr Assisted-by: Claude Code:Opus 4.8 --- OdfFile/Projects/Linux/CMakeLists.txt | 15 ----- OdfFile/Test/test_odf/CMakeLists.txt | 89 +++++++++++++++++++-------- 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/OdfFile/Projects/Linux/CMakeLists.txt b/OdfFile/Projects/Linux/CMakeLists.txt index 679e7b0aed..29e58ace4a 100644 --- a/OdfFile/Projects/Linux/CMakeLists.txt +++ b/OdfFile/Projects/Linux/CMakeLists.txt @@ -18,19 +18,6 @@ if(NOT TARGET UnicodeConverter) add_subdirectory(${CORE_ROOT_DIR}/UnicodeConverter UnicodeConverter) endif() -# The ODF->OOXML writer references OOXML format code (XmlUtils, SimpleTypes, -# OOX::WritingElement/CPath, the math logic classes and PPTX::Namespaces). Those -# symbols live in the OOXML format libraries; declare them as dependencies so -# OdfFormatLib links standalone (previously they were only satisfied when the -# whole x2t library was linked together). -if(NOT TARGET DocxFormatLib) - add_subdirectory(${CORE_ROOT_DIR}/OOXML/Projects/Linux/DocxFormatLib DocxFormatLib) -endif() - -if(NOT TARGET PPTXFormatLib) - add_subdirectory(${CORE_ROOT_DIR}/OOXML/Projects/Linux/PPTXFormatLib PPTXFormatLib) -endif() - add_library(OdfFormatLib STATIC ${CMAKE_CURRENT_LIST_DIR}/odf_converter.cpp ${CMAKE_CURRENT_LIST_DIR}/odf_datatypes.cpp @@ -504,8 +491,6 @@ endif() target_link_libraries(OdfFormatLib PUBLIC UnicodeConverter kernel - DocxFormatLib - PPTXFormatLib Boost::system Boost::filesystem Boost::regex diff --git a/OdfFile/Test/test_odf/CMakeLists.txt b/OdfFile/Test/test_odf/CMakeLists.txt index 21f7c1f611..5f85043dcc 100644 --- a/OdfFile/Test/test_odf/CMakeLists.txt +++ b/OdfFile/Test/test_odf/CMakeLists.txt @@ -2,53 +2,88 @@ cmake_minimum_required(VERSION 3.10) project(test_odf) -# This directory is three levels under the repository root -# (OdfFile/Test/test_odf). +# OdfFile/Test/test_odf -> three levels under the repository root. set(CORE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..") include(${CORE_ROOT_DIR}/common.cmake) -# Dependencies. test_odf.pro builds only test.cpp + common.cpp (the -# entrance/motion/audio/interactions modules are commented out) and converts an -# .odp fixture via ConvertODF2OOXml() + COfficeFileFormatChecker. +# test_odf.pro builds only test.cpp + common.cpp (the entrance/motion/audio/ +# interactions modules are commented out) and converts an .odp fixture via +# ConvertODF2OOXml() + COfficeFileFormatChecker. # -# ConvertODF2OOXml() lives in OdfFormatLib; COfficeFileFormatChecker is compiled -# from OfficeFileFormatChecker2.cpp (+ pole.cpp + unicode_util.cpp) directly into -# the target, mirroring how Test/Applications/x2tTester does it. kernel/graphics/ -# UnicodeConverter satisfy the rest of the chain. -if(NOT TARGET kernel) - add_subdirectory(${CORE_ROOT_DIR}/Common kernel) -endif() -if(NOT TARGET UnicodeConverter) - add_subdirectory(${CORE_ROOT_DIR}/UnicodeConverter UnicodeConverter) -endif() -if(NOT TARGET graphics) - add_subdirectory(${CORE_ROOT_DIR}/DesktopEditor/graphics/cmake graphics) -endif() -if(NOT TARGET OdfFormatLib) - add_subdirectory(${CORE_ROOT_DIR}/OdfFile/Projects/Linux OdfFormatLib) +# ConvertODF2OOXml() lives in OdfFormatLib, whose ODF->OOXML writer references +# the whole OOXML/MS format-library set (XmlUtils, SimpleTypes, OOX/PPTX/XLS/XLSB +# classes, ...). Those static libraries reference each other and are only ever +# linked together inside x2tlib. Add the x2tlib "library" subdirectory (which +# guard-adds every one of those targets) so they exist, then link the static +# archives below inside a --start-group, mirroring x2tlib's own link. In the +# normal top-level build x2t is configured first, so this is a no-op there. +if(NOT TARGET x2tlib) + add_subdirectory(${CORE_ROOT_DIR}/X2tConverter/build/cmake/library x2tlib) endif() # The test reads its fixture via the working-dir-relative path # "ExampleFiles/motion.odp" (TestEnv passes it straight to convert_single()). -# Stage the committed ExampleFiles next to the binary and run the test from that -# staging dir so the relative path resolves. +# Stage the committed ExampleFiles next to the binary and run from that dir. set(_test_odf_run_dir "${CMAKE_CURRENT_BINARY_DIR}/run") # test.cpp owns main() (InitGoogleTest + AddGlobalTestEnvironment + RUN_ALL_TESTS) -# -> do NOT pass GTEST_MAIN. +# -> do NOT pass GTEST_MAIN. COfficeFileFormatChecker is compiled from +# OfficeFileFormatChecker2.cpp directly into the target (no format library builds +# it; x2tlib compiles it the same way). FILE_FORMAT_CHECKER_WITH_MACRO is left +# undefined to avoid the heavy PPT dependency chain. unicode_util.cpp/pole.cpp are +# NOT compiled here -- DocxFormatLib provides them, so doing so would duplicate. add_core_gtest( NAME test_odf SOURCES test.cpp common.cpp - ${CORE_ROOT_DIR}/Common/3dParty/pole/pole.cpp ${CORE_ROOT_DIR}/Common/OfficeFileFormatChecker2.cpp - ${CORE_ROOT_DIR}/OOXML/Base/unicode_util.cpp - LIBS OdfFormatLib kernel graphics UnicodeConverter WORKING_DIRECTORY "${_test_odf_run_dir}" ) -# test_odf.pro adds the core root (for the rewritten relative includes such as +# The OOXML/MS format static libraries reference one another, so wrap them in a +# linker group; the remaining converter libraries are shared and linked after. +# This mirrors the static + dynamic lib lists of target_link_libraries(x2tlib). +target_link_libraries(test_odf PRIVATE + -Wl,--start-group + OdfFormatLib + DocFormatLib + PptFormatLib + RtfFormatLib + TxtXmlFormatLib + BinDocument + PPTXFormatLib + DocxFormatLib + XlsbFormatLib + XlsFormatLib + VbaFormatLib + CompoundFileLib + CryptoPPLib + -Wl,--end-group + graphics + kernel + UnicodeConverter + kernel_network + Fb2File + PdfFile + HtmlFile2 + EpubFile + XpsFile + OFDFile + DjVuFile + doctrenderer + DocxRenderer + IWorkFile + HWPFile + StarMathConverter + ooxmlsignature + Boost::system + Boost::filesystem + Boost::regex + Boost::date_time +) + +# test_odf.pro adds the core root (for rewritten relative includes such as # "Common/OfficeFileFormatChecker.h") and X2tConverter/src on the include path. target_include_directories(test_odf PRIVATE "${CORE_ROOT_DIR}"