summaryrefslogtreecommitdiff
path: root/sal/qa
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-03-07 15:07:07 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-03-12 13:35:56 +0100
commit53fb5f774e262e6dbe364c9da06ae5e0db11b5d7 (patch)
tree45a625f1a34774dbd03668c78516588a7d48a22a /sal/qa
parent2f5f802bcf197c5c65aa4453ad2097d5642b80aa (diff)
OString ctor for string literals without RTL_CONSTASCII stuff
Diffstat (limited to 'sal/qa')
-rw-r--r--sal/qa/OStringBuffer/rtl_OStringBuffer.cxx50
-rw-r--r--sal/qa/rtl/strings/test_ostring_stringliterals.cxx112
-rw-r--r--sal/qa/rtl/strings/test_oustring_stringliterals.cxx1
3 files changed, 138 insertions, 25 deletions
diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
index 85705bea85a1..e05c29358179 100644
--- a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
+++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
@@ -458,11 +458,11 @@ namespace rtl_OStringBuffer
void getLength_005()
{
::rtl::OStringBuffer aStrBuf( *arrOUS[4] );
- sal_Int32 expVal = 0;
+ sal_Int32 expVal = 1;
CPPUNIT_ASSERT_MESSAGE
(
- "length of empty string (string arg = '\\0')",
+ "length of string with \\0 embedded",
aStrBuf.getLength() == expVal
);
}
@@ -591,11 +591,11 @@ namespace rtl_OStringBuffer
void getCapacity_005()
{
::rtl::OStringBuffer aStrBuf( *arrOUS[4] );
- sal_Int32 expVal = 0+16;
+ sal_Int32 expVal = 1+16;
CPPUNIT_ASSERT_MESSAGE
(
- "capacity of empty string (string arg = '\\0')",
+ "capacity of string with \\0 embedded",
aStrBuf.getCapacity() == expVal
);
}
@@ -1308,7 +1308,7 @@ namespace rtl_OStringBuffer
::rtl::OStringBuffer aStrBuf( *arrOUS[4] );
sal_Int32 expVal1 = 5;
::rtl::OString expVal2;
- sal_Int32 expVal3 = 16;
+ sal_Int32 expVal3 = 17;
sal_Int32 input = 5;
aStrBuf.setLength( input );
@@ -1328,7 +1328,7 @@ namespace rtl_OStringBuffer
::rtl::OStringBuffer aStrBuf( *arrOUS[4] );
sal_Int32 expVal1 = 0;
::rtl::OString expVal2;
- sal_Int32 expVal3 = 16;
+ sal_Int32 expVal3 = 17;
sal_Int32 input = 0;
aStrBuf.setLength( input );
@@ -1573,7 +1573,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -2004,7 +2004,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -2391,7 +2391,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -2777,7 +2777,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -3012,7 +3012,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -3245,7 +3245,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -5231,7 +5231,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -6242,7 +6242,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -8295,7 +8295,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
intVal = 11;
@@ -8420,7 +8420,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -8994,7 +8994,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -10980,7 +10980,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -11991,7 +11991,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -14044,7 +14044,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
intVal = 11;
@@ -14169,7 +14169,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -14752,7 +14752,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -15488,7 +15488,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -16239,7 +16239,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
@@ -16301,7 +16301,7 @@ namespace rtl_OStringBuffer
arrOUS[0] = new OString( kTestStr7 );
arrOUS[1] = new OString( );
arrOUS[2] = new OString( kTestStr25 );
- arrOUS[3] = new OString( "\0" );
+ arrOUS[3] = new OString( "" );
arrOUS[4] = new OString( kTestStr28 );
}
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
new file mode 100644
index 000000000000..46da8c817e33
--- /dev/null
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Lubos Lunak <l.lunak@suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// activate the extra needed ctor
+#define RTL_STRING_UNITTEST
+bool rtl_string_unittest_const_literal;
+
+#include "sal/config.h"
+#include "sal/precppunit.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include "rtl/string.h"
+#include "rtl/string.hxx"
+
+namespace test { namespace ostring {
+
+class StringLiterals: public CppUnit::TestFixture
+{
+private:
+ void checkCtors();
+
+ void testcall( const char str[] );
+
+CPPUNIT_TEST_SUITE(StringLiterals);
+CPPUNIT_TEST(checkCtors);
+CPPUNIT_TEST_SUITE_END();
+};
+
+// reset the flag, call OString ctor with the given argument and return
+// whether the string literal ctor was used
+#define CONST_CTOR_USED( argument ) \
+ ( \
+ rtl_string_unittest_const_literal = false, \
+ ( void ) rtl::OString( argument ), \
+ rtl_string_unittest_const_literal )
+
+void test::ostring::StringLiterals::checkCtors()
+{
+ CPPUNIT_ASSERT( CONST_CTOR_USED( "test" ));
+ const char good1[] = "test";
+ CPPUNIT_ASSERT( CONST_CTOR_USED( good1 ));
+
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( (const char*) "test" ));
+ const char* bad1 = good1;
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad1 ));
+ char bad2[] = "test";
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad2 ));
+ char* bad3 = bad2;
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad3 ));
+ const char* bad4[] = { "test1" };
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( bad4[ 0 ] ));
+ testcall( good1 );
+
+// This one is technically broken, since the first element is 6 characters test\0\0,
+// but there does not appear a way to detect this by compile time (runtime will complain).
+// RTL_CONSTASCII_USTRINGPARAM() has the same flaw.
+ const char bad5[][ 6 ] = { "test", "test2" };
+ CPPUNIT_ASSERT( CONST_CTOR_USED( bad5[ 0 ] ));
+ CPPUNIT_ASSERT( CONST_CTOR_USED( bad5[ 1 ] ));
+
+// Check that contents are correct and equal to the case when const char* ctor is used.
+ CPPUNIT_ASSERT( rtl::OString( (const char*)"" ) == rtl::OString( "" ));
+ CPPUNIT_ASSERT( rtl::OString( (const char*)"ab" ) == rtl::OString( "ab" ));
+
+// Check that contents are correct and equal to the case when RTL_CONSTASCII_STRINGPARAM is used.
+// Check also that embedded \0 is included (RTL_CONSTASCII_STRINGPARAM does the same,
+// const char* ctor does not, but it seems to make more sense to include it when
+// it's explicitly mentioned in the string literal).
+ CPPUNIT_ASSERT( rtl::OString( RTL_CONSTASCII_STRINGPARAM( "" )) == rtl::OString( "" ));
+ CPPUNIT_ASSERT( rtl::OString( RTL_CONSTASCII_STRINGPARAM( "\0" )) == rtl::OString( "\0" ));
+ CPPUNIT_ASSERT( rtl::OString( RTL_CONSTASCII_STRINGPARAM( "ab" )) == rtl::OString( "ab" ));
+ CPPUNIT_ASSERT( rtl::OString( RTL_CONSTASCII_STRINGPARAM( "a\0b" )) == rtl::OString( "a\0b" ));
+}
+
+void test::ostring::StringLiterals::testcall( const char str[] )
+{
+ CPPUNIT_ASSERT( !CONST_CTOR_USED( str ));
+}
+
+#undef CONST_CTOR_USED
+
+}} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::ostring::StringLiterals);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index 1170ff7e2ed8..5a1d987edc62 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -28,6 +28,7 @@
// activate the extra needed ctor
#define RTL_STRING_UNITTEST
+extern bool rtl_string_unittest_const_literal; // actually unused here
#include "sal/config.h"
#include "sal/precppunit.hxx"