From e17ba6dde7588f717bc5e79b3cb64cddd73d6173 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Tue, 6 May 2014 20:12:11 +0200 Subject: Added basic external read file function test case * ... as a test of how well we are able to test DOM structures * required change of constructDocument visibility --- CMakeLists.txt | 2 ++ src/function/read_directory.h | 3 --- src/function/read_file.h | 3 --- src/function/read_xml_file.h | 3 --- src/support/filesystem_context.cc | 3 +++ src/support/filesystem_context.h | 1 + test.cc | 10 +++++++-- tests/function_read_file.cc | 43 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 tests/function_read_file.cc 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 { public: using FunctionBase::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 fd36847..b89263e 100644 --- a/src/function/read_file.h +++ b/src/function/read_file.h @@ -9,9 +9,6 @@ class FunctionReadFile : public FunctionBase { public: using FunctionBase::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 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 { public: using FunctionBase::FunctionBase; - protected: - friend FunctionBase; - 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; diff --git a/test.cc b/test.cc index 2a6f886..c024048 100644 --- a/test.cc +++ b/test.cc @@ -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 +#include +#include +#include + +#include + +#include "function/base.h" +#include "function/read_file.h" + +typedef std::basic_string 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(u"content")) + ); + + EXPECT_EQ( + XmlString(domDocument->getDocumentElement()->getFirstChild()->getNodeName()), + XmlString(reinterpret_cast(u"result")) + ); +} -- cgit v1.2.3