| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sal/types.h> |
| 21 |
#include <cppunit/TestFixture.h> |
| 22 |
#include <cppunit/extensions/HelperMacros.h> |
| 23 |
#include <rtl/ustring.hxx> |
| 24 |
|
| 25 |
namespace test::oustring { |
| 26 |
|
| 27 |
class Compare: public CppUnit::TestFixture |
| 28 |
{ |
| 29 |
private: |
| 30 |
void equalsIgnoreAsciiCaseAscii(); |
| 31 |
void compareToIgnoreAsciiCase(); |
| 32 |
void compareTo(); |
| 33 |
|
| 34 |
CPPUNIT_TEST_SUITE(Compare); |
| 35 |
CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii); |
| 36 |
CPPUNIT_TEST(compareToIgnoreAsciiCase); |
| 37 |
CPPUNIT_TEST(compareTo); |
| 38 |
CPPUNIT_TEST_SUITE_END(); |
| 39 |
}; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare); |
| 44 |
|
| 45 |
void test::oustring::Compare::equalsIgnoreAsciiCaseAscii() |
| 46 |
{ |
| 47 |
const char* const abc = "abc"; |
| 48 |
const char* const abcd = "abcd"; |
| 49 |
const char* const empty = ""; |
| 50 |
CPPUNIT_ASSERT(!OUString().equalsIgnoreAsciiCaseAscii(abc)); |
| 51 |
CPPUNIT_ASSERT(!OUString().equalsIgnoreAsciiCaseAsciiL(abc,3)); |
| 52 |
CPPUNIT_ASSERT(!u"abc"_ustr. |
| 53 |
equalsIgnoreAsciiCaseAscii(empty)); |
| 54 |
CPPUNIT_ASSERT(!u"abc"_ustr. |
| 55 |
equalsIgnoreAsciiCaseAsciiL(empty,0)); |
| 56 |
|
| 57 |
CPPUNIT_ASSERT(u"abc"_ustr. |
| 58 |
equalsIgnoreAsciiCaseAscii(abc)); |
| 59 |
CPPUNIT_ASSERT(!u"abcd"_ustr. |
| 60 |
equalsIgnoreAsciiCaseAscii(abc)); |
| 61 |
CPPUNIT_ASSERT(!u"abc"_ustr. |
| 62 |
equalsIgnoreAsciiCaseAscii(abcd)); |
| 63 |
} |
| 64 |
|
| 65 |
void test::oustring::Compare::compareToIgnoreAsciiCase() |
| 66 |
{ |
| 67 |
CPPUNIT_ASSERT_EQUAL( |
| 68 |
sal_Int32(0), |
| 69 |
u"abc"_ustr.compareToIgnoreAsciiCase(u"ABC")); |
| 70 |
CPPUNIT_ASSERT( |
| 71 |
u"ABC"_ustr.compareToIgnoreAsciiCase(u"abcdef") |
| 72 |
< 0); |
| 73 |
CPPUNIT_ASSERT( |
| 74 |
u"A"_ustr.compareToIgnoreAsciiCase(u"_") > 0); |
| 75 |
} |
| 76 |
|
| 77 |
void test::oustring::Compare::compareTo() |
| 78 |
{ |
| 79 |
// test that embedded NUL does not stop the compare |
| 80 |
// this sort of thing is how we assign shape ids in oox |
| 81 |
sal_Unicode str1[2] = { '\0', 'x' }; |
| 82 |
sal_Unicode str2[2] = { '\0', 'y' }; |
| 83 |
|
| 84 |
OUString s1(str1, 2); |
| 85 |
OUString s2(str2, 2); |
| 86 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s1.compareTo(s1)); |
| 87 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2)); |
| 88 |
CPPUNIT_ASSERT(s1.compareTo(s2) < 0); |
| 89 |
CPPUNIT_ASSERT(s2.compareTo(s1) > 0); |
| 90 |
CPPUNIT_ASSERT(s1.compareTo(Concat2View(s2 + "y")) < 0); |
| 91 |
CPPUNIT_ASSERT(s2.compareTo(Concat2View(s1 + "x")) > 0); |
| 92 |
CPPUNIT_ASSERT(OUString(s1 + "x").compareTo(s2) < 0); |
| 93 |
CPPUNIT_ASSERT(OUString(s2 + "y").compareTo(s1) > 0); |
| 94 |
} |
| 95 |
|
| 96 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |