Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / unotools / qa / unit / configpaths.cxx
blob7d9907d9e34d556b4c762db8ba4a224b38a272c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/config.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
17 #include <unotools/configpaths.hxx>
19 namespace
21 class Test : public CppUnit::TestFixture
23 public:
24 void testSplitLastFromConfigurationPath()
27 OUString path, last;
28 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u"", path, last));
29 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
30 CPPUNIT_ASSERT_EQUAL(OUString(""), last);
33 // Already prior to 5edefc801fb48559c8064003f23d22d838710ee4 "use more string_view in
34 // unotools", and in discordance with the documentation, this returned true (but
35 // "@returns <FALSE/>, if the path was a one-level path or an invalid path"):
36 OUString path, last;
37 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"/", path, last));
38 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
39 CPPUNIT_ASSERT_EQUAL(OUString(""), last);
42 // Already prior to 5edefc801fb48559c8064003f23d22d838710ee4 "use more string_view in
43 // unotools", and in discordance with the documentation, this returned true (but
44 // "@returns <FALSE/>, if the path was a one-level path or an invalid path"):
45 OUString path, last;
46 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"/foo", path, last));
47 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
48 CPPUNIT_ASSERT_EQUAL(OUString("foo"), last);
51 // Already prior to 5edefc801fb48559c8064003f23d22d838710ee4 "use more string_view in
52 // unotools", and in discordance with the documentation, this returned true (but
53 // "@returns <FALSE/>, if the path was a one-level path or an invalid path"):
54 OUString path, last;
55 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"/foo/", path, last));
56 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
57 CPPUNIT_ASSERT_EQUAL(OUString("foo"), last);
60 OUString path, last;
61 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"/foo/bar/baz", path, last));
62 CPPUNIT_ASSERT_EQUAL(OUString("/foo/bar"), path);
63 CPPUNIT_ASSERT_EQUAL(OUString("baz"), last);
66 // Trailing slash accepted for backwards compatibility (cf
67 // . "for backwards compatibility, ignore a final slash" comment in
68 // Data::resolvePathRepresentation, configmgr/source/data.cxx):
69 OUString path, last;
70 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"/foo/bar/baz/", path, last));
71 CPPUNIT_ASSERT_EQUAL(OUString("/foo/bar"), path);
72 CPPUNIT_ASSERT_EQUAL(OUString("baz"), last);
75 OUString path, last;
76 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(
77 u"/foo/bar/baz['abc']/baz['de&amp;f']", path, last));
78 CPPUNIT_ASSERT_EQUAL(OUString("/foo/bar/baz['abc']"), path);
79 CPPUNIT_ASSERT_EQUAL(OUString("de&f"), last);
82 OUString path, last;
83 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u"foo", path, last));
84 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
85 CPPUNIT_ASSERT_EQUAL(OUString("foo"), last);
88 // In accordance with the documentation, this sets last to "foo/" ("If
89 // <var>_sInPath</var> could not be parsed as a valid configuration path, this is set to
90 // <var>_sInPath</var>"):
91 OUString path, last;
92 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u"foo/", path, last));
93 CPPUNIT_ASSERT_EQUAL(OUString(""), path);
94 CPPUNIT_ASSERT_EQUAL(OUString("foo/"), last);
97 // Some broken input missing a leading slash happens to be considered OK:
98 OUString path, last;
99 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u"foo/bar/baz", path, last));
100 CPPUNIT_ASSERT_EQUAL(OUString("foo/bar"), path);
101 CPPUNIT_ASSERT_EQUAL(OUString("baz"), last);
105 CPPUNIT_TEST_SUITE(Test);
106 CPPUNIT_TEST(testSplitLastFromConfigurationPath);
107 CPPUNIT_TEST_SUITE_END();
110 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
113 CPPUNIT_PLUGIN_IMPLEMENT();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */