diff options
author | Dawid Wróbel <me@dawidwrobel.com> | 2022-07-12 14:39:58 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-08-30 17:55:07 (GMT) |
commit | e706da5f7ebbdab98098825ff8f7bad89ce06277 (patch) | |
tree | 8724f87cd420c871edae87a2e1904e9d050727e6 /Tests | |
parent | 4bcdf1b992804467bc39710c2670f828df479dff (diff) | |
download | CMake-e706da5f7ebbdab98098825ff8f7bad89ce06277.zip CMake-e706da5f7ebbdab98098825ff8f7bad89ce06277.tar.gz CMake-e706da5f7ebbdab98098825ff8f7bad89ce06277.tar.bz2 |
FindOpenSP: Add module to find the OpenSP library
OpenSP has not seen a release in seventeen years, so is unlikely to ever
provide a CMake package configuration file. Add a find module instead.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FindOpenSP/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindOpenSP/Test/CMakeLists.txt | 16 | ||||
-rw-r--r-- | Tests/FindOpenSP/Test/main.cxx | 55 | ||||
-rw-r--r-- | Tests/FindOpenSP/Test/test.sgml | 7 |
5 files changed, 89 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b7de021..b6fec4d 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1476,6 +1476,7 @@ if(BUILD_TESTING) OpenCL OpenGL OpenMP + OpenSP OpenSSL MPI PNG diff --git a/Tests/FindOpenSP/CMakeLists.txt b/Tests/FindOpenSP/CMakeLists.txt new file mode 100644 index 0000000..26826d3 --- /dev/null +++ b/Tests/FindOpenSP/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindOpenSP.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindOpenSP/Test" + "${CMake_BINARY_DIR}/Tests/FindOpenSP/Test" + ${build_generator_args} + --build-project TestFindOpenSP + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindOpenSP/Test/CMakeLists.txt b/Tests/FindOpenSP/Test/CMakeLists.txt new file mode 100644 index 0000000..d8992d9 --- /dev/null +++ b/Tests/FindOpenSP/Test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.4) +project(TestFindOpenSP CXX) +include(CTest) + +find_package(OpenSP REQUIRED) + +add_definitions(-DSP_MULTI_BYTE="${OpenSP_MULTI_BYTE}") + +add_executable(test_tgt main.cxx) +target_link_libraries(test_tgt OpenSP::OpenSP) +add_test(NAME test_tgt COMMAND test_tgt) + +add_executable(test_var main.cxx) +target_include_directories(test_var PRIVATE ${OpenSP_INCLUDE_DIRS}) +target_link_libraries(test_var PRIVATE ${OpenSP_LIBRARIES}) +add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindOpenSP/Test/main.cxx b/Tests/FindOpenSP/Test/main.cxx new file mode 100644 index 0000000..ef8aa2c --- /dev/null +++ b/Tests/FindOpenSP/Test/main.cxx @@ -0,0 +1,55 @@ +#include <cassert> +#include <string> + +#include "ParserEventGeneratorKit.h" + +std::string CharStringtostring(const SGMLApplication::CharString source) +{ + // The CharString type might have multi-byte characters if SP_MULTI_BYTE was + // defined + std::string result; + result.resize(source.len); + for (size_t i = 0; i < source.len; i++) { + result[i] = static_cast<char>(source.ptr[i]); + } + return result; +} + +class OutlineApplication : public SGMLApplication +{ +public: + OutlineApplication() + : depth_(0) + { + } + void startElement(const StartElementEvent& event) + { + for (unsigned i = 0; i < depth_; i++) + parsedOutput += "\t"; + parsedOutput += CharStringtostring(event.gi); + depth_++; + } + void endElement(const EndElementEvent&) { depth_--; } + std::string parsedOutput; + +private: + unsigned depth_; +}; + +int main() +{ + std::string expectedOutput = "TESTDOC\tTESTELEMENT"; + char file_name[] = "test.sgml"; + char* files[] = { file_name, 0 }; + + ParserEventGeneratorKit parserKit; + EventGenerator* egp = parserKit.makeEventGenerator(1, files); + OutlineApplication app; + unsigned nErrors = egp->run(app); + + assert(nErrors == 0); + assert(app.parsedOutput.compare(expectedOutput) == 0); + + delete egp; + return 0; +} diff --git a/Tests/FindOpenSP/Test/test.sgml b/Tests/FindOpenSP/Test/test.sgml new file mode 100644 index 0000000..bbf0da6 --- /dev/null +++ b/Tests/FindOpenSP/Test/test.sgml @@ -0,0 +1,7 @@ + <!DOCTYPE TESTDOC [ +<!ELEMENT TESTDOC - - (TESTELEMENT)+> +<!ELEMENT TESTELEMENT - - (#PCDATA)> +]> +<TESTDOC> +<TESTELEMENT>Hello</TESTELEMENT> +</TESTDOC> |