Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sal / qa / rtl / strings / test_oustring_compare.cxx
blob5e9bc0f73a5deaeba53c56135af43be3d75175d0
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <rtl/string.h>
24 #include <rtl/ustring.hxx>
26 namespace test { namespace oustring {
28 class Compare: public CppUnit::TestFixture
30 private:
31 void equalsIgnoreAsciiCaseAscii();
32 void compareToIgnoreAsciiCase();
33 void compareTo();
35 CPPUNIT_TEST_SUITE(Compare);
36 CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii);
37 CPPUNIT_TEST(compareToIgnoreAsciiCase);
38 CPPUNIT_TEST(compareTo);
39 CPPUNIT_TEST_SUITE_END();
42 } }
44 CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare);
46 void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
48 const char* const abc = "abc";
49 const char* const abcd = "abcd";
50 const char* const empty = "";
51 CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii(abc));
52 CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL(abc,3));
53 CPPUNIT_ASSERT(!rtl::OUString("abc").
54 equalsIgnoreAsciiCaseAscii(empty));
55 CPPUNIT_ASSERT(!rtl::OUString("abc").
56 equalsIgnoreAsciiCaseAsciiL(empty,0));
58 CPPUNIT_ASSERT(rtl::OUString("abc").
59 equalsIgnoreAsciiCaseAscii(abc));
60 CPPUNIT_ASSERT(!rtl::OUString("abcd").
61 equalsIgnoreAsciiCaseAscii(abc));
62 CPPUNIT_ASSERT(!rtl::OUString("abc").
63 equalsIgnoreAsciiCaseAscii(abcd));
66 void test::oustring::Compare::compareToIgnoreAsciiCase()
68 CPPUNIT_ASSERT_EQUAL(
69 sal_Int32(0),
70 rtl::OUString("abc").compareToIgnoreAsciiCase("ABC"));
71 CPPUNIT_ASSERT(
72 rtl::OUString("ABC").compareToIgnoreAsciiCase("abcdef")
73 < 0);
74 CPPUNIT_ASSERT(
75 rtl::OUString("A").compareToIgnoreAsciiCase("_") > 0);
78 void test::oustring::Compare::compareTo()
80 // test that embedded NUL does not stop the compare
81 // this sort of thing is how we assign shape ids in oox
82 sal_Unicode str1[2] = { '\0', 'x' };
83 sal_Unicode str2[2] = { '\0', 'y' };
85 OUString s1(str1, 2);
86 OUString s2(str2, 2);
87 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s1.compareTo(s1));
88 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2));
89 CPPUNIT_ASSERT(s1.compareTo(s2) < 0);
90 CPPUNIT_ASSERT(s2.compareTo(s1) > 0);
91 CPPUNIT_ASSERT(s1.compareTo(OUString(s2 + "y")) < 0);
92 CPPUNIT_ASSERT(s2.compareTo(OUString(s1 + "x")) > 0);
93 CPPUNIT_ASSERT(OUString(s1 + "x").compareTo(s2) < 0);
94 CPPUNIT_ASSERT(OUString(s2 + "y").compareTo(s1) > 0);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */