xref: /aoo42x/main/tools/qa/test_pathutils.cxx (revision 89b56da7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_tools.hxx"
25 #include "sal/config.h"
26 
27 #include <cwchar>
28 
29 #include "testshl/simpleheader.hxx"
30 #include "tools/pathutils.hxx"
31 
32 namespace {
33 
34 void buildPath(
35     wchar_t const * front, wchar_t const * back, wchar_t const * path)
36 {
37 #if defined WNT
38     wchar_t p[MAX_PATH];
39     wchar_t * e = tools::buildPath(
40         p, front, front + std::wcslen(front), back, std::wcslen(back));
41     CPPUNIT_ASSERT_EQUAL(p + std::wcslen(path), e);
42     CPPUNIT_ASSERT_EQUAL(0, std::wcscmp(path, p));
43 #else
44     (void) front;
45     (void) back;
46     (void) path;
47 #endif
48 }
49 
50 class Test: public CppUnit::TestFixture {
51 public:
52     void testBuildPath();
53 
54     CPPUNIT_TEST_SUITE(Test);
55     CPPUNIT_TEST(testBuildPath);
56     CPPUNIT_TEST_SUITE_END();
57 };
58 
59 void Test::testBuildPath() {
60     buildPath(L"a:\\b\\", L"..", L"a:\\");
61     buildPath(L"a:\\b\\", L"..\\", L"a:\\");
62     buildPath(L"a:\\b\\c\\", L"..\\..\\..\\d", L"a:\\..\\d");
63     buildPath(L"\\\\a\\b\\", L"..\\..\\..\\c", L"\\\\..\\c");
64     buildPath(L"\\", L"..\\a", L"\\..\\a");
65     buildPath(L"", L"..\\a", L"..\\a");
66 }
67 
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
69 
70 }
71 
72 NOADDITIONAL;
73