Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
f0d75874
Kaydet (Commit)
f0d75874
authored
Ara 05, 2012
tarafından
Luboš Luňák
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
unittest for fast string operator+ not allowing unwanted combinations
Change-Id: I5891efcec7db373407a661636108fd979839db52
üst
9b7ec761
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
stringconcat.hxx
sal/inc/rtl/stringconcat.hxx
+17
-0
test_ostring_concat.cxx
sal/qa/rtl/strings/test_ostring_concat.cxx
+31
-0
test_oustring_concat.cxx
sal/qa/rtl/strings/test_oustring_concat.cxx
+36
-0
No files found.
sal/inc/rtl/stringconcat.hxx
Dosyayı görüntüle @
f0d75874
...
...
@@ -260,6 +260,23 @@ typename internal::Enable< OUStringConcat< T1, T2 >, ToStringHelper< T1 >::allow
return
OUStringConcat
<
T1
,
T2
>
(
left
,
right
);
}
#ifdef RTL_STRING_UNITTEST_CONCAT
// Special overload to catch the remaining invalid combinations. The helper struct must
// be used to make this operator+ overload a worse choice than all the existing overloads above.
struct
StringConcatInvalid
{
template
<
typename
T
>
StringConcatInvalid
(
const
T
&
)
{}
};
template
<
typename
T
>
inline
int
operator
+
(
const
StringConcatInvalid
&
,
const
T
&
)
{
rtl_string_unittest_invalid_concat
=
true
;
return
0
;
// doesn't matter
}
#endif
}
// namespace
#endif
...
...
sal/qa/rtl/strings/test_ostring_concat.cxx
Dosyayı görüntüle @
f0d75874
...
...
@@ -7,12 +7,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// activate support for detecting errors instead of getting compile errors
#define RTL_STRING_UNITTEST_CONCAT
bool
rtl_string_unittest_invalid_concat
=
false
;
#include <sal/types.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <typeinfo>
...
...
@@ -36,11 +42,13 @@ private:
void
checkConcat
();
void
checkEnsureCapacity
();
void
checkAppend
();
void
checkInvalid
();
CPPUNIT_TEST_SUITE
(
StringConcat
);
CPPUNIT_TEST
(
checkConcat
);
CPPUNIT_TEST
(
checkEnsureCapacity
);
CPPUNIT_TEST
(
checkAppend
);
CPPUNIT_TEST
(
checkInvalid
);
CPPUNIT_TEST_SUITE_END
();
};
...
...
@@ -75,6 +83,8 @@ void test::ostring::StringConcat::checkConcat()
TYPES_ASSERT_EQUAL
((
typeid
(
OStringConcat
<
OString
,
const
char
*
>
)),
typeid
(
OString
(
"foo"
)
+
d3
));
CPPUNIT_ASSERT_EQUAL
(
OString
(
"fooabc"
),
OString
(
OString
(
"foo"
)
+
d4
));
TYPES_ASSERT_EQUAL
((
typeid
(
OStringConcat
<
OString
,
char
*
>
)),
typeid
(
OString
(
"foo"
)
+
d4
));
CPPUNIT_ASSERT_EQUAL
(
OString
(
"foobar"
),
OString
(
OStringBuffer
(
"foo"
)
+
OString
(
"bar"
)));
TYPES_ASSERT_EQUAL
((
typeid
(
OStringConcat
<
OStringBuffer
,
OString
>
)),
typeid
(
OStringBuffer
(
"foo"
)
+
OString
(
"bar"
)));
}
#undef typeid
...
...
@@ -126,6 +136,27 @@ void test::ostring::StringConcat::checkAppend()
CPPUNIT_ASSERT_EQUAL
(
OString
(
"foobarbaz"
),
buf
.
makeStringAndClear
());
}
#define INVALID_CONCAT( expression ) \
( \
rtl_string_unittest_invalid_concat = false, \
( void ) OString( expression ), \
rtl_string_unittest_invalid_concat )
void
test
::
ostring
::
StringConcat
::
checkInvalid
()
{
#ifdef RTL_FAST_STRING
CPPUNIT_ASSERT
(
!
INVALID_CONCAT
(
OString
()
+
OString
()));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OString
(
"a"
)
+
OUString
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OString
(
"a"
)
+
OUStringBuffer
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OString
(
"a"
)
+
OUStringLiteral
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OString
(
"a"
)
+
1
));
rtl_String
*
rs
=
NULL
;
rtl_uString
*
rus
=
NULL
;
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"b"
)
+
rs
));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"b"
)
+
rus
));
#endif
}
}}
// namespace
CPPUNIT_TEST_SUITE_REGISTRATION
(
test
::
ostring
::
StringConcat
);
...
...
sal/qa/rtl/strings/test_oustring_concat.cxx
Dosyayı görüntüle @
f0d75874
...
...
@@ -7,12 +7,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// activate support for detecting errors instead of getting compile errors
#define RTL_STRING_UNITTEST_CONCAT
extern
bool
rtl_string_unittest_invalid_concat
;
#include <sal/types.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <typeinfo>
...
...
@@ -36,11 +42,13 @@ private:
void
checkConcat
();
void
checkEnsureCapacity
();
void
checkAppend
();
void
checkInvalid
();
CPPUNIT_TEST_SUITE
(
StringConcat
);
CPPUNIT_TEST
(
checkConcat
);
CPPUNIT_TEST
(
checkEnsureCapacity
);
CPPUNIT_TEST
(
checkAppend
);
CPPUNIT_TEST
(
checkInvalid
);
CPPUNIT_TEST_SUITE_END
();
};
...
...
@@ -64,6 +72,8 @@ void test::oustring::StringConcat::checkConcat()
const
char
d1
[]
=
"xyz"
;
CPPUNIT_ASSERT_EQUAL
(
OUString
(
"fooxyz"
),
OUString
(
OUString
(
"foo"
)
+
d1
));
TYPES_ASSERT_EQUAL
((
typeid
(
OUStringConcat
<
OUString
,
const
char
[
4
]
>
)),
typeid
(
OUString
(
"foo"
)
+
d1
));
CPPUNIT_ASSERT_EQUAL
(
OUString
(
"foobar"
),
OUString
(
OUStringBuffer
(
"foo"
)
+
OUString
(
"bar"
)));
TYPES_ASSERT_EQUAL
((
typeid
(
OUStringConcat
<
OUStringBuffer
,
OUString
>
)),
typeid
(
OUStringBuffer
(
"foo"
)
+
OUString
(
"bar"
)));
}
void
test
::
oustring
::
StringConcat
::
checkEnsureCapacity
()
...
...
@@ -118,6 +128,32 @@ void test::oustring::StringConcat::checkAppend()
CPPUNIT_ASSERT_EQUAL
(
OUString
(
"foobarbaz"
),
buf
.
makeStringAndClear
());
}
#define INVALID_CONCAT( expression ) \
( \
rtl_string_unittest_invalid_concat = false, \
( void ) OUString( expression ), \
rtl_string_unittest_invalid_concat )
void
test
::
oustring
::
StringConcat
::
checkInvalid
()
{
#ifdef RTL_FAST_STRING
CPPUNIT_ASSERT
(
!
INVALID_CONCAT
(
OUString
()
+
OUString
()));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
OString
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
OStringBuffer
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
(
const
char
*
)
"b"
));
char
d
[]
=
"b"
;
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
d
));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
(
char
*
)
d
));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
OStringLiteral
(
"b"
)));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"a"
)
+
1
));
rtl_String
*
rs
=
NULL
;
rtl_uString
*
rus
=
NULL
;
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"b"
)
+
rs
));
CPPUNIT_ASSERT
(
INVALID_CONCAT
(
OUString
(
"b"
)
+
rus
));
#endif
}
}}
// namespace
CPPUNIT_TEST_SUITE_REGISTRATION
(
test
::
oustring
::
StringConcat
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment