bump product version to 5.0.4.1
[LibreOffice.git] / sal / qa / rtl / strings / test_strings_toint.cxx
blobcf5de4a3b2bf6c1b1c02b471d3dd8553da592acd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/string.hxx"
16 #include "rtl/ustring.hxx"
17 #include "sal/types.h"
19 namespace {
21 template< typename T > class Test: public CppUnit::TestFixture {
22 private:
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());
47 CPPUNIT_ASSERT_EQUAL(
48 SAL_MIN_INT64, T("-9223372036854775808").toInt64());
49 CPPUNIT_ASSERT_EQUAL(
50 SAL_MIN_INT64 + 1, T("-9223372036854775807").toInt64());
51 CPPUNIT_ASSERT_EQUAL(
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() {
58 CPPUNIT_ASSERT_EQUAL(
59 SAL_MAX_UINT64 - 1, T("18446744073709551614").toUInt64());
60 CPPUNIT_ASSERT_EQUAL(
61 SAL_MAX_UINT64, T("18446744073709551615").toUInt64());
62 CPPUNIT_ASSERT_EQUAL(
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: */