1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/types.h>
11 #include <test/xmltesttools.hxx>
12 #include <unotest/bootstrapfixturebase.hxx>
14 class TestXPath
: public CppUnit::TestFixture
, public XmlTestTools
18 CPPUNIT_TEST_FIXTURE(TestXPath
, test_getXPath
)
20 const xmlChar s_xml
[] = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
21 "<xml><item attrib='val'>text</item></xml>";
22 xmlDocPtr pTable
= xmlParseDoc(s_xml
);
23 CPPUNIT_ASSERT(pTable
);
24 // Must get existing element content without errors
25 CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable
, "/xml/item", ""));
26 // Must error out when getting non-existing element
27 CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable
, "/xml/no_item", ""));
28 // Must get existing attribute value correctly
29 CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable
, "/xml/item", "attrib"));
30 // Must fail when requested non-empty attribute doesn't exist
31 CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable
, "/xml/item", "no_attrib"));
32 // Must return empty string if not asking an attribute, regardless what is its content
33 CPPUNIT_ASSERT_EQUAL(OUString(), getXPath(pTable
, "/xml/item", ""));
34 // Must properly return attribute content
35 CPPUNIT_ASSERT_EQUAL(OUString("val"), getXPath(pTable
, "/xml/item", "attrib"));
36 // Trying to get position of missing child of a node must fail assertion
37 CPPUNIT_ASSERT_ASSERTION_FAIL(getXPathPosition(pTable
, "/xml/item", "absent"));
40 CPPUNIT_PLUGIN_IMPLEMENT();
42 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */