1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <rtl/strbuf.hxx>
16 #include <rtl/string.hxx>
17 #include <rtl/ustring.hxx>
21 OString
returnOString()
23 char buf
[] = "foo\0bar";
27 OStringBuffer
returnOStringBuffer()
29 char buf
[] = "foo\0bar";
33 class Test
: public CppUnit::TestFixture
43 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OString(s
.a
).getLength());
44 // Ideally, the below would work the same as the above. However, the const reference makes
45 // the ConstCharArrayDetector instead of the NonConstCharArrayDetector kick in, so that the
46 // call to OString(r.a) would fire the ConstCharArrayDetector<T>::isValid assert (and in
47 // NDEBUG builds the CPPUNIT_ASSERT_EQUAL would fail with 3 != 1):
51 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OString(r
.a
).getLength());
55 void testOUStringChar()
62 // This would fail to compile, as there is no OUString ctor taking a
63 // NonConstCharArrayDetector char array:
65 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(s
.a
).getLength());
67 // Ideally, the below would fail to compile the same as the above. However, the const
68 // reference makes the ConstCharArrayDetector instead of the NonConstCharArrayDetector kick
69 // in, so that the call to OUString(r.a) would fire the ConstCharArrayDetector<T>::isValid
70 // assert (and in NDEBUG builds the CPPUNIT_ASSERT_EQUAL would fail with 3 != 1):
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(r
.a
).getLength());
78 void testOUStringChar16t()
85 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(s
.a
).getLength());
86 // Ideally, the below would work the same as the above. However, the const reference makes
87 // the ConstCharArrayDetector instead of the NonConstCharArrayDetector kick in, so that the
88 // call to OUString(r.a) would fire the ConstCharArrayDetector<T>::isValid assert (and in
89 // NDEBUG builds the CPPUNIT_ASSERT_EQUAL would fail with 3 != 1)::
93 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(r
.a
).getLength());
99 CPPUNIT_ASSERT_EQUAL(OString("foo"), returnOString());
100 CPPUNIT_ASSERT_EQUAL(OString("foo"), returnOStringBuffer().makeStringAndClear());
103 CPPUNIT_TEST_SUITE(Test
);
104 CPPUNIT_TEST(testOString
);
105 CPPUNIT_TEST(testOUStringChar
);
106 CPPUNIT_TEST(testOUStringChar16t
);
107 CPPUNIT_TEST(testP2266R3
);
108 CPPUNIT_TEST_SUITE_END();
111 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */