1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/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>
21 class Test
: public CppUnit::TestFixture
24 void testSplitLastFromConfigurationPath()
28 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u
"", path
, last
));
29 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
30 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, 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"):
37 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"/", path
, last
));
38 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
39 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, 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"):
46 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"/foo", path
, last
));
47 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
48 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, 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"):
55 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"/foo/", path
, last
));
56 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
57 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, last
);
61 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"/foo/bar/baz", path
, last
));
62 CPPUNIT_ASSERT_EQUAL(u
"/foo/bar"_ustr
, path
);
63 CPPUNIT_ASSERT_EQUAL(u
"baz"_ustr
, 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):
70 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"/foo/bar/baz/", path
, last
));
71 CPPUNIT_ASSERT_EQUAL(u
"/foo/bar"_ustr
, path
);
72 CPPUNIT_ASSERT_EQUAL(u
"baz"_ustr
, last
);
76 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(
77 u
"/foo/bar/baz['abc']/baz['de&f']", path
, last
));
78 CPPUNIT_ASSERT_EQUAL(u
"/foo/bar/baz['abc']"_ustr
, path
);
79 CPPUNIT_ASSERT_EQUAL(u
"de&f"_ustr
, last
);
83 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u
"foo", path
, last
));
84 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
85 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, 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>"):
92 CPPUNIT_ASSERT(!utl::splitLastFromConfigurationPath(u
"foo/", path
, last
));
93 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, path
);
94 CPPUNIT_ASSERT_EQUAL(u
"foo/"_ustr
, last
);
97 // Some broken input missing a leading slash happens to be considered OK:
99 CPPUNIT_ASSERT(utl::splitLastFromConfigurationPath(u
"foo/bar/baz", path
, last
));
100 CPPUNIT_ASSERT_EQUAL(u
"foo/bar"_ustr
, path
);
101 CPPUNIT_ASSERT_EQUAL(u
"baz"_ustr
, 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: */