1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <string_view>
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/extensions/HelperMacros.h>
18 #include <o3tl/cppunittraitshelper.hxx>
19 #include <rtl/ustrbuf.hxx>
20 #include <rtl/ustring.hxx>
24 class Test
: public CppUnit::TestFixture
30 OUString
s1("123456789012345");
32 CPPUNIT_ASSERT_EQUAL(s1
, b1
.toString());
33 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1
.getCapacity());
36 CPPUNIT_ASSERT_EQUAL(s2
, b1
.toString());
37 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1
.getCapacity());
38 OUString
s3("1234567890123456");
40 CPPUNIT_ASSERT_EQUAL(s3
, b1
.toString());
41 CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b1
.getCapacity());
43 b2
= "123456789012345";
44 CPPUNIT_ASSERT_EQUAL(s1
, b2
.toString());
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b2
.getCapacity());
47 CPPUNIT_ASSERT_EQUAL(s2
, b2
.toString());
48 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b2
.getCapacity());
49 b2
= "1234567890123456";
50 CPPUNIT_ASSERT_EQUAL(s3
, b2
.toString());
51 CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b2
.getCapacity());
53 b3
= u
"123456789012345";
54 CPPUNIT_ASSERT_EQUAL(s1
, b3
.toString());
55 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b3
.getCapacity());
57 CPPUNIT_ASSERT_EQUAL(s2
, b3
.toString());
58 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b3
.getCapacity());
59 b3
= u
"1234567890123456";
60 CPPUNIT_ASSERT_EQUAL(s3
, b3
.toString());
61 CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b3
.getCapacity());
63 b4
= OUStringLiteral(u
"1") + "23456789012345";
64 CPPUNIT_ASSERT_EQUAL(s1
, b4
.toString());
65 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b4
.getCapacity());
66 b4
= OUStringLiteral(u
"a") + "bc";
67 CPPUNIT_ASSERT_EQUAL(s2
, b4
.toString());
68 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b4
.getCapacity());
69 b4
= OUStringLiteral(u
"1") + "234567890123456";
70 CPPUNIT_ASSERT_EQUAL(s3
, b4
.toString());
71 CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b4
.getCapacity());
72 b4
= OUStringChar('a');
73 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), b4
.getLength());
74 CPPUNIT_ASSERT_EQUAL(u
'a', b4
.getStr()[0]);
75 CPPUNIT_ASSERT_EQUAL(u
'\0', b4
.getStr()[1]);
76 b4
= std::u16string_view(u
"abc").substr(
77 0, 2); // avoid the string_view accidentally being NUL-terminated
78 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), b4
.getLength());
79 CPPUNIT_ASSERT_EQUAL(u
'a', b4
.getStr()[0]);
80 CPPUNIT_ASSERT_EQUAL(u
'b', b4
.getStr()[1]);
81 CPPUNIT_ASSERT_EQUAL(u
'\0', b4
.getStr()[2]);
84 CPPUNIT_TEST_SUITE(Test
);
86 CPPUNIT_TEST_SUITE_END();
90 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */