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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "sal/config.h"
28 
29 #include <cstddef>
30 
31 #include "cppunit/TestAssert.h"
32 #include "cppunit/TestFixture.h"
33 #include "cppunit/extensions/HelperMacros.h"
34 #include "cppunit/plugin/TestPlugIn.h"
35 #include "rtl/ustring.h"
36 #include "rtl/ustring.hxx"
37 
38 #include "../../source/deployment/inc/dp_version.hxx"
39 
40 namespace {
41 
42 class Test: public ::CppUnit::TestFixture {
43 public:
44     void test();
45 
46     CPPUNIT_TEST_SUITE(Test);
47     CPPUNIT_TEST(test);
48     CPPUNIT_TEST_SUITE_END();
49 };
50 
test()51 void Test::test() {
52     struct Data {
53         rtl::OUString version1;
54         rtl::OUString version2;
55         ::dp_misc::Order order;
56     };
57     static Data const data[] = {
58         { rtl::OUString(),
59           rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0.0000.00.0")),
60           ::dp_misc::EQUAL },
61         { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".01")),
62           rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0.1")),
63           ::dp_misc::EQUAL },
64         { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("10")),
65           rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("2")),
66           ::dp_misc::GREATER },
67         { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("9223372036854775808")),
68               // 2^63
69           rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("9223372036854775807")),
70           ::dp_misc::GREATER }
71     };
72     for (::std::size_t i = 0; i < sizeof data / sizeof (Data); ++i) {
73         CPPUNIT_ASSERT_EQUAL(
74             data[i].order,
75             ::dp_misc::compareVersions(data[i].version1, data[i].version2));
76         static ::dp_misc::Order const reverse[3] = {
77             ::dp_misc::GREATER, ::dp_misc::EQUAL, ::dp_misc::LESS
78         };
79         CPPUNIT_ASSERT_EQUAL(
80             reverse[data[i].order],
81             ::dp_misc::compareVersions(data[i].version2, data[i].version1));
82     }
83 }
84 
85 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
86 
87 }
88 
89 CPPUNIT_PLUGIN_IMPLEMENT();
90