diff options
-rw-r--r-- | CMakeLists.txt | 34 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | example.cc | 11 | ||||
-rw-r--r-- | src/function/read_directory.h | 3 | ||||
-rw-r--r-- | src/function/read_file.h | 3 | ||||
-rw-r--r-- | src/function/read_xml_file.h | 3 | ||||
-rw-r--r-- | test.cc | 52 | ||||
-rw-r--r-- | tests/function_read_file.cc | 43 |
8 files changed, 71 insertions, 79 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 53fa29c..b6229ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,18 @@ include_directories( src/ ) -add_library( +set( + Libraries InputXSLT - STATIC + xalan-c + xerces-c + boost_system + boost_filesystem + boost_program_options +) + +set( + Sources src/plattform_guard.cc src/transformation_facade.cc src/function/read_file.cc @@ -24,32 +33,17 @@ add_library( ) add_executable( - example - example.cc -) - -add_executable( test test.cc - tests/function_read_file.cc ) -set( - Libraries +add_library( InputXSLT - xalan-c - xerces-c - boost_system - boost_filesystem -) - -target_link_libraries( - example - ${Libraries} + STATIC + ${Sources} ) target_link_libraries( test - gtest ${Libraries} ) @@ -19,3 +19,4 @@ Contrary to popular opinion I actually like XSLT as a content transformation lan - Apache [Xalan](https://xalan.apache.org/) XSLT Processor - Apache [Xerces](https://xerces.apache.org/) XML Library - Boost [Filesystem](http://www.boost.org/doc/libs/1_55_0/libs/filesystem/doc/index.htm) +- Boost [Program Options](http://www.boost.org/doc/libs/1_55_0/doc/html/program_options.html) diff --git a/example.cc b/example.cc deleted file mode 100644 index a0c122d..0000000 --- a/example.cc +++ /dev/null @@ -1,11 +0,0 @@ -#include "plattform_guard.h" -#include "transformation_facade.h" - -int main(int, char**) { - InputXSLT::PlattformGuard plattform; - InputXSLT::TransformationFacade transformation("../dummy/transform.xsl"); - - return transformation.generate("out.xml", { - {"test", "42"} - }); -} diff --git a/src/function/read_directory.h b/src/function/read_directory.h index d34a80a..85e7f1b 100644 --- a/src/function/read_directory.h +++ b/src/function/read_directory.h @@ -9,6 +9,9 @@ class FunctionReadDirectory : public FunctionBase<FunctionReadDirectory> { public: using FunctionBase<FunctionReadDirectory>::FunctionBase; + protected: + friend FunctionBase; + xercesc::DOMDocument* constructDocument( const FilesystemContext&, const boost::filesystem::path& diff --git a/src/function/read_file.h b/src/function/read_file.h index b89263e..b581ee5 100644 --- a/src/function/read_file.h +++ b/src/function/read_file.h @@ -9,6 +9,9 @@ class FunctionReadFile : public FunctionBase<FunctionReadFile> { public: using FunctionBase<FunctionReadFile>::FunctionBase; + protected: + friend FunctionBase; + xercesc::DOMDocument* constructDocument( const FilesystemContext&, const boost::filesystem::path& diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h index b1d165d..4aebe56 100644 --- a/src/function/read_xml_file.h +++ b/src/function/read_xml_file.h @@ -9,6 +9,9 @@ class FunctionReadXmlFile : public FunctionBase<FunctionReadXmlFile> { public: using FunctionBase<FunctionReadXmlFile>::FunctionBase; + protected: + friend FunctionBase; + xercesc::DOMDocument* constructDocument( const FilesystemContext&, const boost::filesystem::path& @@ -1,12 +1,54 @@ #include "plattform_guard.h" #include "transformation_facade.h" -#include "gtest/gtest.h" +#include "boost/program_options.hpp" -int main(int argc, char** argv) { - InputXSLT::PlattformGuard plattform; +#include <iostream> - testing::InitGoogleTest(&argc, argv); +int main(int ac, char** av) { + boost::program_options::options_description optionDescription( + "Supported options" + ); + + optionDescription.add_options() + ("transformation", boost::program_options::value<std::string>()->required(), "transformation file") + ("target", boost::program_options::value<std::string>()->required(), "target file") + ; + + boost::program_options::variables_map variables; + + boost::program_options::store( + boost::program_options::parse_command_line( + ac, av, optionDescription + ), + variables + ); + + try { + boost::program_options::notify(variables); + } + catch ( std::exception& exception ) { + std::cerr << exception.what() << std::endl; + } + + if ( variables.count("transformation") && + variables.count("target") ) { + InputXSLT::PlattformGuard plattform; + + InputXSLT::TransformationFacade transformation( + variables["transformation"].as<std::string>() + ); + + return transformation.generate( + variables["target"].as<std::string>(), + { + {"test", "42"} + } + ); + } else { + std::cout << optionDescription << std::endl; + + return 1; + } - return RUN_ALL_TESTS(); } diff --git a/tests/function_read_file.cc b/tests/function_read_file.cc deleted file mode 100644 index e0bb8da..0000000 --- a/tests/function_read_file.cc +++ /dev/null @@ -1,43 +0,0 @@ -#include "gtest/gtest.h" - -#include <xercesc/dom/DOMDocument.hpp> -#include <xercesc/dom/DOMImplementation.hpp> -#include <xercesc/dom/DOMElement.hpp> -#include <xercesc/dom/DOMText.hpp> - -#include <string> - -#include "function/base.h" -#include "function/read_file.h" - -typedef std::basic_string<XMLCh> XmlString; - -class FunctionReadFileTest : public ::testing::Test { - friend InputXSLT::FunctionReadFile; -}; - -TEST_F(FunctionReadFileTest, constructDocumentTest) { - const InputXSLT::FilesystemContext fsContext("../tests"); - const boost::filesystem::path filePath( - fsContext.resolve("./function_read_file.cc") - ); - - InputXSLT::FunctionReadFile function; - - xercesc::DOMDocument* const domDocument = function.constructDocument( - fsContext, - filePath - ); - - EXPECT_NE(domDocument, nullptr); - - EXPECT_EQ( - XmlString(domDocument->getDocumentElement()->getNodeName()), - XmlString(reinterpret_cast<const XMLCh*>(u"content")) - ); - - EXPECT_EQ( - XmlString(domDocument->getDocumentElement()->getFirstChild()->getNodeName()), - XmlString(reinterpret_cast<const XMLCh*>(u"result")) - ); -} |