Debian Codegraph @

sal/qa/rtl/strings/test_ostringbuffer.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10 #include <sal/config.h>
11
12 #include <string_view>
13
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/extensions/HelperMacros.h>
17
18 #include <rtl/strbuf.hxx>
19 #include <rtl/stringutils.hxx>
20 #include <sal/types.h>
21
22 namespace
23 {
24 class Test : public CppUnit::TestFixture
25 {
26 private:
27 void testStringView()
28 {
29 OStringBuffer b("foobar");
30 b = std::string_view("abc").substr(
31 0, 2); // avoid the string_view accidentally being NUL-terminated
32 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), b.getLength());
33 CPPUNIT_ASSERT_EQUAL('a', b.getStr()[0]);
34 CPPUNIT_ASSERT_EQUAL('b', b.getStr()[1]);
35 CPPUNIT_ASSERT_EQUAL('\0', b.getStr()[2]);
36 }
37
38 void testOStringChar()
39 {
40 OStringBuffer b("foobar");
41 b = OStringChar('a');
42 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), b.getLength());
43 CPPUNIT_ASSERT_EQUAL('a', b.getStr()[0]);
44 CPPUNIT_ASSERT_EQUAL('\0', b.getStr()[1]);
45 }
46
47 CPPUNIT_TEST_SUITE(Test);
48 CPPUNIT_TEST(testStringView);
49 CPPUNIT_TEST(testOStringChar);
50 CPPUNIT_TEST_SUITE_END();
51 };
52 }
53
54 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
55
56 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */