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 .
20 #include <cppunit/TestFixture.h>
21 #include <cppunit/extensions/HelperMacros.h>
23 #include <tools/bigint.hxx>
28 class BigIntTest
: public CppUnit::TestFixture
31 void testConstructionFromLongLong();
33 CPPUNIT_TEST_SUITE(BigIntTest
);
34 CPPUNIT_TEST(testConstructionFromLongLong
);
35 CPPUNIT_TEST_SUITE_END();
38 void BigIntTest::testConstructionFromLongLong()
40 // small positive number
42 BigInt
bi(static_cast<sal_Int64
>(42));
43 CPPUNIT_ASSERT(bi
.IsSet());
44 CPPUNIT_ASSERT(!bi
.IsZero());
45 CPPUNIT_ASSERT(!bi
.IsNeg());
46 CPPUNIT_ASSERT(bi
.IsLong());
47 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(42), static_cast<sal_Int32
>(bi
));
50 // small negative number
52 BigInt
bi(static_cast<sal_Int64
>(-42));
53 CPPUNIT_ASSERT(bi
.IsSet());
54 CPPUNIT_ASSERT(!bi
.IsZero());
55 CPPUNIT_ASSERT(bi
.IsNeg());
56 CPPUNIT_ASSERT(bi
.IsLong());
57 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(-42), static_cast<sal_Int32
>(bi
));
60 #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
61 // positive number just fitting to long
63 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::max()));
64 CPPUNIT_ASSERT(bi
.IsSet());
65 CPPUNIT_ASSERT(!bi
.IsZero());
66 CPPUNIT_ASSERT(!bi
.IsNeg());
67 CPPUNIT_ASSERT(bi
.IsLong());
68 CPPUNIT_ASSERT_EQUAL(std::numeric_limits
<long>::max(), static_cast<long>(bi
));
71 // negative number just fitting to long
73 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::min()));
74 CPPUNIT_ASSERT(bi
.IsSet());
75 CPPUNIT_ASSERT(!bi
.IsZero());
76 CPPUNIT_ASSERT(bi
.IsNeg());
77 CPPUNIT_ASSERT(bi
.IsLong());
78 CPPUNIT_ASSERT_EQUAL(std::numeric_limits
<long>::min(), static_cast<long>(bi
));
81 // positive number not fitting to long
83 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::max()) + static_cast<sal_Int64
>(1));
84 CPPUNIT_ASSERT(bi
.IsSet());
85 CPPUNIT_ASSERT(!bi
.IsZero());
86 CPPUNIT_ASSERT(!bi
.IsNeg());
87 CPPUNIT_ASSERT(!bi
.IsLong());
90 // negative number not fitting to long
92 BigInt
bi(static_cast<sal_Int64
>(std::numeric_limits
<long>::min()) - static_cast<sal_Int64
>(1));
93 CPPUNIT_ASSERT(bi
.IsSet());
94 CPPUNIT_ASSERT(!bi
.IsZero());
95 CPPUNIT_ASSERT(bi
.IsNeg());
96 CPPUNIT_ASSERT(!bi
.IsLong());
101 CPPUNIT_TEST_SUITE_REGISTRATION(BigIntTest
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */