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
40dcf2d7
Kaydet (Commit)
40dcf2d7
authored
Mar 25, 2013
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add test case for toInt overflow detection
Change-Id: I1c5b66888baac8aa1bc99c06579e0ef3638a4877
üst
bd60d411
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
6 deletions
+78
-6
CppunitTest_sal_rtl_strings.mk
sal/CppunitTest_sal_rtl_strings.mk
+1
-0
string.hxx
sal/inc/rtl/string.hxx
+6
-3
ustring.hxx
sal/inc/rtl/ustring.hxx
+6
-3
test_strings_toint.cxx
sal/qa/rtl/strings/test_strings_toint.cxx
+65
-0
No files found.
sal/CppunitTest_sal_rtl_strings.mk
Dosyayı görüntüle @
40dcf2d7
...
...
@@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl_strings,\
sal/qa/rtl/strings/test_oustring_noadditional
\
sal/qa/rtl/strings/test_oustring_startswith
\
sal/qa/rtl/strings/test_oustring_stringliterals
\
sal/qa/rtl/strings/test_strings_toint
\
sal/qa/rtl/strings/test_strings_valuex
\
))
...
...
sal/inc/rtl/string.hxx
Dosyayı görüntüle @
40dcf2d7
...
...
@@ -1349,7 +1349,8 @@ public:
@param radix the radix (between 2 and 36)
@return the int32 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
*/
sal_Int32
toInt32
(
sal_Int16
radix
=
10
)
const
SAL_THROW
(())
{
...
...
@@ -1363,7 +1364,8 @@ public:
@param radix the radix (between 2 and 36)
@return the int64 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
*/
sal_Int64
toInt64
(
sal_Int16
radix
=
10
)
const
SAL_THROW
(())
{
...
...
@@ -1377,7 +1379,8 @@ public:
@param radix the radix (between 2 and 36)
@return the uint64 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
@since LibreOffice 4.1
*/
...
...
sal/inc/rtl/ustring.hxx
Dosyayı görüntüle @
40dcf2d7
...
...
@@ -1828,7 +1828,8 @@ public:
@param radix the radix (between 2 and 36)
@return the int32 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
*/
sal_Int32
toInt32
(
sal_Int16
radix
=
10
)
const
SAL_THROW
(())
{
...
...
@@ -1842,7 +1843,8 @@ public:
@param radix the radix (between 2 and 36)
@return the int64 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
*/
sal_Int64
toInt64
(
sal_Int16
radix
=
10
)
const
SAL_THROW
(())
{
...
...
@@ -1856,7 +1858,8 @@ public:
@param radix the radix (between 2 and 36)
@return the uint64 represented from this string.
0 if this string represents no number.
0 if this string represents no number or one of too large
magnitude.
@since LibreOffice 4.1
*/
...
...
sal/qa/rtl/strings/test_strings_toint.cxx
0 → 100644
Dosyayı görüntüle @
40dcf2d7
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "sal/config.h"
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "rtl/string.hxx"
#include "rtl/ustring.hxx"
#include "sal/types.h"
namespace
{
template
<
typename
T
>
class
Test
:
public
CppUnit
::
TestFixture
{
private
:
CPPUNIT_TEST_SUITE
(
Test
);
CPPUNIT_TEST
(
testToInt32Overflow
);
CPPUNIT_TEST
(
testToInt64Overflow
);
CPPUNIT_TEST
(
testToUInt64Overflow
);
CPPUNIT_TEST_SUITE_END
();
void
testToInt32Overflow
()
{
CPPUNIT_ASSERT_EQUAL
(
sal_Int32
(
0
),
T
(
"-2147483649"
).
toInt32
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MIN_INT32
,
T
(
"-2147483648"
).
toInt32
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MIN_INT32
+
1
,
T
(
"-2147483647"
).
toInt32
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_INT32
-
1
,
T
(
"2147483646"
).
toInt32
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_INT32
,
T
(
"2147483647"
).
toInt32
());
CPPUNIT_ASSERT_EQUAL
(
sal_Int32
(
0
),
T
(
"2147483648"
).
toInt32
());
}
void
testToInt64Overflow
()
{
CPPUNIT_ASSERT_EQUAL
(
sal_Int64
(
0
),
T
(
"-9223372036854775809"
).
toInt64
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MIN_INT64
,
T
(
"-9223372036854775808"
).
toInt64
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MIN_INT64
+
1
,
T
(
"-9223372036854775807"
).
toInt64
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_INT64
-
1
,
T
(
"9223372036854775806"
).
toInt64
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_INT64
,
T
(
"9223372036854775807"
).
toInt64
());
CPPUNIT_ASSERT_EQUAL
(
sal_Int64
(
0
),
T
(
"9223372036854775808"
).
toInt64
());
}
void
testToUInt64Overflow
()
{
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_UINT64
-
1
,
T
(
"18446744073709551614"
).
toUInt64
());
CPPUNIT_ASSERT_EQUAL
(
SAL_MAX_UINT64
,
T
(
"18446744073709551615"
).
toUInt64
());
CPPUNIT_ASSERT_EQUAL
(
sal_uInt64
(
0
),
T
(
"18446744073709551616"
).
toUInt64
());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION
(
Test
<
rtl
::
OString
>
);
CPPUNIT_TEST_SUITE_REGISTRATION
(
Test
<
rtl
::
OUString
>
);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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