Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <limits>
21 : #include <cppunit/TestFixture.h>
22 : #include <cppunit/extensions/HelperMacros.h>
23 :
24 : #include <rtl/math.hxx>
25 :
26 : #include <tools/bigint.hxx>
27 :
28 : namespace tools
29 : {
30 :
31 0 : class BigIntTest : public CppUnit::TestFixture
32 : {
33 : public:
34 : #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
35 : void testConstructionFromLongLong();
36 : #endif
37 :
38 4 : CPPUNIT_TEST_SUITE(BigIntTest);
39 : #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
40 : CPPUNIT_TEST(testConstructionFromLongLong);
41 : #endif
42 4 : CPPUNIT_TEST_SUITE_END();
43 : };
44 :
45 : #if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
46 : void BigIntTest::testConstructionFromLongLong()
47 : {
48 : // small positive number
49 : {
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));
56 : }
57 :
58 : // small negative number
59 : {
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));
66 : }
67 :
68 : // positive number just fitting to long
69 : {
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));
76 : }
77 :
78 : // negative number just fitting to long
79 : {
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));
86 : }
87 :
88 : // positive number not fitting to long
89 : {
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());
95 : }
96 :
97 : // negative number not fitting to long
98 : {
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());
104 : }
105 : }
106 : #endif
107 :
108 2 : CPPUNIT_TEST_SUITE_REGISTRATION(BigIntTest);
109 :
110 6 : }
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|