diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-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-- | src/support/filesystem_context.cc | 3 | ||||
-rw-r--r-- | src/support/filesystem_context.h | 1 | ||||
-rw-r--r-- | test.cc | 10 | ||||
-rw-r--r-- | tests/function_read_file.cc | 43 |
8 files changed, 57 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 565b3cb..3333c26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable( src/support/filesystem_context.cc src/support/dom/document_cache.cc src/support/dom/document_cache_item.cc + tests/function_read_file.cc ) target_link_libraries( @@ -29,4 +30,5 @@ target_link_libraries( xerces-c boost_system boost_filesystem + gtest ) diff --git a/src/function/read_directory.h b/src/function/read_directory.h index 2c28642..d34a80a 100644 --- a/src/function/read_directory.h +++ b/src/function/read_directory.h @@ -9,9 +9,6 @@ class FunctionReadDirectory : public FunctionBase<FunctionReadDirectory> { public: using FunctionBase<FunctionReadDirectory>::FunctionBase; - protected: - friend FunctionBase<FunctionReadDirectory>; - xercesc::DOMDocument* constructDocument( const FilesystemContext&, const boost::filesystem::path& diff --git a/src/function/read_file.h b/src/function/read_file.h index fd36847..b89263e 100644 --- a/src/function/read_file.h +++ b/src/function/read_file.h @@ -9,9 +9,6 @@ class FunctionReadFile : public FunctionBase<FunctionReadFile> { public: using FunctionBase<FunctionReadFile>::FunctionBase; - protected: - friend FunctionBase<FunctionReadFile>; - 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 5314b4a..b1d165d 100644 --- a/src/function/read_xml_file.h +++ b/src/function/read_xml_file.h @@ -9,9 +9,6 @@ class FunctionReadXmlFile : public FunctionBase<FunctionReadXmlFile> { public: using FunctionBase<FunctionReadXmlFile>::FunctionBase; - protected: - friend FunctionBase<FunctionReadXmlFile>; - xercesc::DOMDocument* constructDocument( const FilesystemContext&, const boost::filesystem::path& diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc index 418d159..6ddbf7a 100644 --- a/src/support/filesystem_context.cc +++ b/src/support/filesystem_context.cc @@ -25,6 +25,9 @@ FilesystemContext::FilesystemContext(const xalan::Locator* locator): ).parent_path().string() )) { } +FilesystemContext::FilesystemContext(const std::string& path): + path_(boost::filesystem::canonical(path)) { } + boost::filesystem::path FilesystemContext::resolve( const std::string& path) const { return absolute(this->path_ / path); diff --git a/src/support/filesystem_context.h b/src/support/filesystem_context.h index 05d5862..6322da6 100644 --- a/src/support/filesystem_context.h +++ b/src/support/filesystem_context.h @@ -16,6 +16,7 @@ namespace InputXSLT { class FilesystemContext { public: explicit FilesystemContext(const xalan::Locator*); + explicit FilesystemContext(const std::string&); boost::filesystem::path resolve(const std::string&) const; boost::filesystem::path resolve(const xalan::XalanDOMString&) const; @@ -1,11 +1,17 @@ #include "plattform_guard.h" #include "transformation_facade.h" -int main() { +#include "gtest/gtest.h" + +int main(int argc, char **argv) { InputXSLT::PlattformGuard plattform; InputXSLT::TransformationFacade transformation("../dummy/transform.xsl"); - return transformation.generate("out.xml", { + transformation.generate("out.xml", { {"test", "42"} }); + + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); } diff --git a/tests/function_read_file.cc b/tests/function_read_file.cc new file mode 100644 index 0000000..e0bb8da --- /dev/null +++ b/tests/function_read_file.cc @@ -0,0 +1,43 @@ +#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")) + ); +} |