1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/string.hxx"
16 #include "rtl/ustring.hxx"
17 #include "sal/types.h"
21 template< typename T
> class Test
: public CppUnit::TestFixture
{
23 CPPUNIT_TEST_SUITE(Test
);
24 CPPUNIT_TEST(testToInt32Overflow
);
25 CPPUNIT_TEST(testToUInt32Overflow
);
26 CPPUNIT_TEST(testToInt64Overflow
);
27 CPPUNIT_TEST(testToUInt64Overflow
);
28 CPPUNIT_TEST_SUITE_END();
30 void testToInt32Overflow() {
31 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("-2147483649").toInt32());
32 CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32
, T("-2147483648").toInt32());
33 CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32
+ 1, T("-2147483647").toInt32());
34 CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32
- 1, T("2147483646").toInt32());
35 CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32
, T("2147483647").toInt32());
36 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("2147483648").toInt32());
39 void testToUInt32Overflow() {
40 CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32
- 1, T("4294967294").toUInt32());
41 CPPUNIT_ASSERT_EQUAL(SAL_MAX_UINT32
, T("4294967295").toUInt32());
42 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), T("4294967296").toUInt32());
45 void testToInt64Overflow() {
46 CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("-9223372036854775809").toInt64());
48 SAL_MIN_INT64
, T("-9223372036854775808").toInt64());
50 SAL_MIN_INT64
+ 1, T("-9223372036854775807").toInt64());
52 SAL_MAX_INT64
- 1, T("9223372036854775806").toInt64());
53 CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT64
, T("9223372036854775807").toInt64());
54 CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("9223372036854775808").toInt64());
57 void testToUInt64Overflow() {
59 SAL_MAX_UINT64
- 1, T("18446744073709551614").toUInt64());
61 SAL_MAX_UINT64
, T("18446744073709551615").toUInt64());
63 sal_uInt64(0), T("18446744073709551616").toUInt64());
67 CPPUNIT_TEST_SUITE_REGISTRATION(Test
< rtl::OString
>);
68 CPPUNIT_TEST_SUITE_REGISTRATION(Test
< rtl::OUString
>);
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */