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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <rtl/math.hxx>
26 #include <tools/bigint.hxx>
31 class BigIntTest
: public CppUnit::TestFixture
34 #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
35 void testConstructionFromLongLong();
38 CPPUNIT_TEST_SUITE(BigIntTest
);
39 #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
40 CPPUNIT_TEST(testConstructionFromLongLong
);
42 CPPUNIT_TEST_SUITE_END();
45 #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
46 void BigIntTest::testConstructionFromLongLong()
48 // small positive number
50 BigInt
bi(static_cast<sal_Int64
>(42));
51 CPPUNIT_ASSERT(bi
.IsSet());
52 CPPUNIT_ASSERT(!bi
.IsZero());
53 CPPUNIT_ASSERT(!bi
.IsNeg());
54 CPPUNIT_ASSERT(bi
.IsLong());
55 CPPUNIT_ASSERT_EQUAL(42L, static_cast<long>(bi
));
58 // small negative number
60 BigInt
bi(static_cast<sal_Int64
>(-42));
61 CPPUNIT_ASSERT(bi
.IsSet());
62 CPPUNIT_ASSERT(!bi
.IsZero());
63 CPPUNIT_ASSERT(bi
.IsNeg());
64 CPPUNIT_ASSERT(bi
.IsLong());
65 CPPUNIT_ASSERT_EQUAL(-42L, static_cast<long>(bi
));
68 // positive number just fitting to long
70 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::max()));
71 CPPUNIT_ASSERT(bi
.IsSet());
72 CPPUNIT_ASSERT(!bi
.IsZero());
73 CPPUNIT_ASSERT(!bi
.IsNeg());
74 CPPUNIT_ASSERT(bi
.IsLong());
75 CPPUNIT_ASSERT_EQUAL(std::numeric_limits
<long>::max(), static_cast<long>(bi
));
78 // negative number just fitting to long
80 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::min()));
81 CPPUNIT_ASSERT(bi
.IsSet());
82 CPPUNIT_ASSERT(!bi
.IsZero());
83 CPPUNIT_ASSERT(bi
.IsNeg());
84 CPPUNIT_ASSERT(bi
.IsLong());
85 CPPUNIT_ASSERT_EQUAL(std::numeric_limits
<long>::min(), static_cast<long>(bi
));
88 // positive number not fitting to long
90 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::max()) + static_cast<sal_Int64
>(1));
91 CPPUNIT_ASSERT(bi
.IsSet());
92 CPPUNIT_ASSERT(!bi
.IsZero());
93 CPPUNIT_ASSERT(!bi
.IsNeg());
94 CPPUNIT_ASSERT(!bi
.IsLong());
97 // negative number not fitting to long
99 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::min()) - static_cast<sal_Int64
>(1));
100 CPPUNIT_ASSERT(bi
.IsSet());
101 CPPUNIT_ASSERT(!bi
.IsZero());
102 CPPUNIT_ASSERT(bi
.IsNeg());
103 CPPUNIT_ASSERT(!bi
.IsLong());
108 CPPUNIT_TEST_SUITE_REGISTRATION(BigIntTest
);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */