tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / qa / rtl / strings / nonconstarray.cxx
blobd759049582d065d67ddf284be11a1d0c03b43134
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.
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 <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>
19 namespace
21 OString returnOString()
23 char buf[] = "foo\0bar";
24 return buf;
27 OStringBuffer returnOStringBuffer()
29 char buf[] = "foo\0bar";
30 return buf;
33 class Test : public CppUnit::TestFixture
35 private:
36 void testOString()
38 struct S
40 char a[4];
42 S s{ "x\0y" };
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):
48 if ((false))
50 S const& r = s;
51 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OString(r.a).getLength());
55 void testOUStringChar()
57 struct S
59 char a[4];
61 S s{ "x\0y" };
62 // This would fail to compile, as there is no OUString ctor taking a
63 // NonConstCharArrayDetector char array:
64 #if 0
65 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(s.a).getLength());
66 #endif
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):
71 if ((false))
73 S const& r = s;
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(r.a).getLength());
78 void testOUStringChar16t()
80 struct S
82 char16_t a[4];
84 S s{ u"x\0y" };
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)::
90 if ((false))
92 S const& r = s;
93 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), OUString(r.a).getLength());
97 void testP2266R3()
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: */