android: Update app-specific/MIME type icons
[LibreOffice.git] / sal / qa / rtl / oustringbuffer / test_oustringbuffer_assign.cxx
blob3c3f436ee5c045f3ab0785fdd6b8d87d0a61e1fa
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/.
8 */
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>
22 namespace
24 class Test : public CppUnit::TestFixture
26 private:
27 void test()
29 OUStringBuffer b1;
30 OUString s1("123456789012345");
31 b1 = s1;
32 CPPUNIT_ASSERT_EQUAL(s1, b1.toString());
33 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1.getCapacity());
34 OUString s2("abc");
35 b1 = s2;
36 CPPUNIT_ASSERT_EQUAL(s2, b1.toString());
37 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b1.getCapacity());
38 OUString s3("1234567890123456");
39 b1 = s3;
40 CPPUNIT_ASSERT_EQUAL(s3, b1.toString());
41 CPPUNIT_ASSERT_EQUAL(sal_Int32(32), b1.getCapacity());
42 OUStringBuffer b2;
43 b2 = "123456789012345";
44 CPPUNIT_ASSERT_EQUAL(s1, b2.toString());
45 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b2.getCapacity());
46 b2 = "abc";
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());
52 OUStringBuffer b3;
53 b3 = u"123456789012345";
54 CPPUNIT_ASSERT_EQUAL(s1, b3.toString());
55 CPPUNIT_ASSERT_EQUAL(sal_Int32(16), b3.getCapacity());
56 b3 = u"abc";
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());
62 OUStringBuffer b4;
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);
85 CPPUNIT_TEST(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: */