xpathselect-1.4+14.04.20140303/ 0000755 0000152 0177776 00000000000 12305004473 016271 5 ustar pbuser nogroup 0000000 0000000 xpathselect-1.4+14.04.20140303/test/ 0000755 0000152 0177776 00000000000 12305004473 017250 5 ustar pbuser nogroup 0000000 0000000 xpathselect-1.4+14.04.20140303/test/test_xpath_tree.cpp 0000644 0000152 0177776 00000014711 12305004311 023151 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "gtest/gtest.h"
#include "xpathselect.h"
#include "node.h"
#include "dummynode.h"
#include
class TestTreeFixture: public ::testing::Test
{
public:
void SetUp() override
{
root_ = std::make_shared("Root");
child_l1_ = std::make_shared("ChildLeft1");
child_r1_ = std::make_shared("ChildRight1");
leaf_1_ = std::make_shared("Leaf");
leaf_2_ = std::make_shared("Leaf");
root_->AddChild(child_l1_);
root_->AddChild(child_r1_);
child_l1_->AddChild(leaf_1_);
child_l1_->AddChild(leaf_2_);
}
typedef std::shared_ptr NodePtr;
NodePtr root_;
NodePtr child_l1_;
NodePtr child_r1_;
NodePtr leaf_1_;
NodePtr leaf_2_;
};
TEST_F(TestTreeFixture, test_simple)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/");
ASSERT_EQ(1, result.size());
}
TEST_F(TestTreeFixture, test_simple_absolute)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1");
ASSERT_EQ(1, result.size());
auto expected = child_l1_;
auto actual = result.front();
ASSERT_EQ(expected, actual);
}
TEST_F(TestTreeFixture, test_simple_relative)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "//ChildRight1");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_r1_, result.front());
}
TEST_F(TestTreeFixture, test_complex_relative)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "//Root/ChildRight1");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_r1_, result.front());
}
TEST_F(TestTreeFixture, test_relative_multiple_return)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "//Leaf");
ASSERT_EQ(2, result.size());
for(xpathselect::Node::Ptr n : result)
{
ASSERT_TRUE(n == leaf_1_ || n == leaf_2_ );
}
}
TEST_F(TestTreeFixture, test_relative_wildcard)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "//ChildLeft1/*");
ASSERT_EQ(2, result.size());
for(xpathselect::Node::Ptr n : result)
{
ASSERT_TRUE(n == leaf_1_ || n == leaf_2_ );
}
}
TEST_F(TestTreeFixture, test_absolute_wildcard)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1/*");
ASSERT_EQ(2, result.size());
for(xpathselect::Node::Ptr n : result)
{
ASSERT_TRUE(n == leaf_1_ || n == leaf_2_ );
}
}
TEST_F(TestTreeFixture, test_simple_absolute_property_match)
{
child_l1_->AddProperty("visible", "True");
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1[visible=True]");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_simple_relative_property_match)
{
child_l1_->AddProperty("visible", true);
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "//ChildLeft1[visible=True]");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_absolute_multiple_property_match)
{
root_->AddProperty("number", 45);
child_l1_->AddProperty("visible", true);
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root[number=45]/ChildLeft1[visible=True]");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_mixed_query_simple)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root//Leaf");
ASSERT_EQ(2, result.size());
for(auto n : result)
{
ASSERT_TRUE(n == leaf_1_ || n == leaf_2_ );
}
}
TEST_F(TestTreeFixture, test_mixed_query_property_match)
{
leaf_1_->AddProperty("visible", true);
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root//Leaf[visible=True]");
ASSERT_EQ(1, result.size());
ASSERT_EQ(leaf_1_, result.front());
}
TEST_F(TestTreeFixture, test_search_node_with_wildcard_and_property)
{
child_l1_->AddProperty("visible", true);
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root//*[visible=True]");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_wildcard)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/*");
ASSERT_EQ(2, result.size());
for(auto n : result)
{
ASSERT_TRUE(n == child_l1_ || n == child_r1_ );
}
}
TEST_F(TestTreeFixture, test_parent)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1/..");
ASSERT_EQ(1, result.size());
ASSERT_EQ(root_, result.front());
}
TEST_F(TestTreeFixture, test_parent_on_root)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/..");
ASSERT_EQ(1, result.size());
ASSERT_EQ(root_, result.front());
}
TEST_F(TestTreeFixture, test_parent_on_leaf)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1/Leaf/..");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_double_parent_on_leaf)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1/Leaf/../..");
ASSERT_EQ(1, result.size());
ASSERT_EQ(root_, result.front());
}
TEST_F(TestTreeFixture, test_parent_and_child)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root/ChildLeft1/../ChildLeft1/../ChildLeft1");
ASSERT_EQ(1, result.size());
ASSERT_EQ(child_l1_, result.front());
}
TEST_F(TestTreeFixture, test_invalid_query_search)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root///Leaf");
ASSERT_EQ(0, result.size());
}
TEST_F(TestTreeFixture, test_invalid_query_multiple_searches)
{
xpathselect::NodeVector result = xpathselect::SelectNodes(root_, "/Root////");
ASSERT_EQ(0, result.size());
}
xpathselect-1.4+14.04.20140303/test/test_xpath_simple.cpp 0000644 0000152 0177776 00000004534 12305004311 023505 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "gtest/gtest.h"
#include "node.h"
#include "xpathselect.h"
#include "dummynode.h"
// empty query must select tree root.
TEST(TestXPath, test_select_empty_tree)
{
xpathselect::Node::Ptr tree_root = std::make_shared();
xpathselect::NodeVector result = xpathselect::SelectNodes(tree_root, "");
ASSERT_EQ(1, result.size());
}
// test explicitly selecting tree root without node name
TEST(TestXPath, test_select_tree_root)
{
xpathselect::Node::Ptr tree_root = std::make_shared("RootNode");
xpathselect::NodeVector result = xpathselect::SelectNodes(tree_root, "/");
ASSERT_EQ(result.size(), 1);
ASSERT_EQ(result.front(), tree_root);
}
// test explicitly selecting tree root without node name
TEST(TestXPath, test_select_tree_root_with_name)
{
xpathselect::Node::Ptr tree_root = std::make_shared("RootNode");
xpathselect::NodeVector result = xpathselect::SelectNodes(tree_root, "/RootNode");
ASSERT_EQ(result.size(), 1);
ASSERT_EQ(result.front(), tree_root);
}
// test explicitly selecting tree root with relative query
TEST(TestXPath, test_select_tree_root_with_relative_query)
{
xpathselect::Node::Ptr tree_root = std::make_shared("RootNode");
xpathselect::NodeVector result = xpathselect::SelectNodes(tree_root, "//RootNode");
ASSERT_EQ(result.size(), 1);
ASSERT_EQ(result.front(), tree_root);
}
// test explicitly selecting tree root with relative query
TEST(TestXPath, test_select_tree_root_with_empty_relative_query)
{
xpathselect::Node::Ptr tree_root = std::make_shared("RootNode");
xpathselect::NodeVector result = xpathselect::SelectNodes(tree_root, "//");
ASSERT_EQ(result.size(), 1);
ASSERT_EQ(result.front(), tree_root);
}
xpathselect-1.4+14.04.20140303/test/CMakeLists.txt 0000644 0000152 0177776 00000003507 12305004311 022004 0 ustar pbuser nogroup 0000000 0000000
include_directories(../lib)
find_path(GTEST_SRC_DIR gtest.cc PATHS /usr/src/gtest/src)
set(CMAKE_CXX_FLAGS "-ggdb -O0 -Wall")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG" )
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Detect if C++11 support is available, and attempt fallback to C++0x support
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "C++11 activated.")
add_definitions("-std=c++11")
#run all tests
set(SOURCES test_main.cpp test_xpath_simple.cpp test_xpath_tree.cpp dummynode.h test_parser.cpp)
add_executable(test-runner ${SOURCES})
add_dependencies (test-runner gtest)
add_dependencies (test-runner ../lib)
target_link_libraries(test-runner gtest xpathselect)
elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
message(WARNING "C++0x activated. Tests have been disabled")
add_definitions("-std=c++0x")
else ()
message(FATAL_ERROR "C++11 needed. Therefore a gcc compiler with a version higher than 4.3 is needed.")
endif()
else(CMAKE_COMPILER_IS_GNUCXX)
add_definitions("-std=c++11") #turn on and hope non-gnu compiler supports it
endif(CMAKE_COMPILER_IS_GNUCXX)
# Check for google test and build it locally
set(
GTEST_ROOT_DIR
"/usr/src/gtest" # Default value, adjustable by user with e.g., ccmake
CACHE
PATH
"Path to Google test srcs"
)
find_path(GTEST_INCLUDE_DIR gtest/gtest.h)
if (GTEST_INCLUDE_DIR)
#FIXME - hardcoded is bad!
add_subdirectory(
${GTEST_ROOT_DIR}
gtest
)
endif(GTEST_INCLUDE_DIR)
enable_testing()
add_test(TestSuite test-runner)
add_custom_target (test COMMAND ./test-runner)
xpathselect-1.4+14.04.20140303/test/dummynode.h 0000644 0000152 0177776 00000005770 12305004311 021422 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#ifndef _DUMMYNODE_H
#define _DUMMYNODE_H
#include "node.h"
#include