Bump version to 24.04.3.4
[LibreOffice.git] / test / qa / cppunit / test_xpath.cxx
blob8d105dd4eae668a07d11ed99594c79c8a2917d8f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/types.h>
11 #include <test/xmltesttools.hxx>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
17 class TestXPath : public CppUnit::TestFixture, public XmlTestTools
21 CPPUNIT_TEST_FIXTURE(TestXPath, test_getXPath)
23 const xmlChar s_xml[] = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
24 "<xml><item attrib='val'>text</item></xml>";
25 xmlDocUniquePtr pTable(xmlParseDoc(s_xml));
26 CPPUNIT_ASSERT(pTable);
27 // Must get existing element content without errors
28 CPPUNIT_ASSERT_ASSERTION_PASS(assertXPath(pTable, "/xml/item"_ostr));
29 // Must error out when getting non-existing element
30 CPPUNIT_ASSERT_ASSERTION_FAIL(assertXPath(pTable, "/xml/no_item"_ostr));
31 // Must get existing attribute value correctly
32 CPPUNIT_ASSERT_ASSERTION_PASS(getXPath(pTable, "/xml/item"_ostr, "attrib"_ostr));
33 // Must fail when requested non-empty attribute doesn't exist
34 CPPUNIT_ASSERT_ASSERTION_FAIL(getXPath(pTable, "/xml/item"_ostr, "no_attrib"_ostr));
35 // Must properly return attribute content
36 CPPUNIT_ASSERT_EQUAL(OUString("val"), getXPath(pTable, "/xml/item"_ostr, "attrib"_ostr));
37 // Trying to get position of missing child of a node must fail assertion
38 CPPUNIT_ASSERT_ASSERTION_FAIL(getXPathPosition(pTable, "/xml/item"_ostr, "absent"));
39 // Asserting that an attribute is absent
40 CPPUNIT_ASSERT_ASSERTION_FAIL(assertXPathNoAttribute(pTable, "/xml/item"_ostr, "attrib"_ostr));
41 CPPUNIT_ASSERT_ASSERTION_PASS(assertXPathNoAttribute(pTable, "/xml/item"_ostr, "foo"_ostr));
44 CPPUNIT_PLUGIN_IMPLEMENT();
46 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */