tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / tools / qa / cppunit / test_bigint.cxx
bloba8d3f069a54a894474234a62e54fec846ff579c3
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/.
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>
25 #include <limits>
27 namespace tools
29 class BigIntTest : public CppUnit::TestFixture
31 public:
32 void testConstructionFromLongLong();
33 void testLenB1();
35 CPPUNIT_TEST_SUITE(BigIntTest);
36 CPPUNIT_TEST(testConstructionFromLongLong);
37 CPPUNIT_TEST(testLenB1);
38 CPPUNIT_TEST_SUITE_END();
41 void BigIntTest::testConstructionFromLongLong()
43 // small positive number
45 BigInt bi(static_cast<sal_Int64>(42));
46 CPPUNIT_ASSERT(!bi.IsZero());
47 CPPUNIT_ASSERT(!bi.IsNeg());
48 CPPUNIT_ASSERT(!bi.IsBig());
49 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(42), static_cast<sal_Int32>(bi));
52 // small negative number
54 BigInt bi(static_cast<sal_Int64>(-42));
55 CPPUNIT_ASSERT(!bi.IsZero());
56 CPPUNIT_ASSERT(bi.IsNeg());
57 CPPUNIT_ASSERT(!bi.IsBig());
58 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-42), static_cast<sal_Int32>(bi));
61 // positive number just fitting to sal_Int32
63 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int32>::max()));
64 CPPUNIT_ASSERT(!bi.IsZero());
65 CPPUNIT_ASSERT(!bi.IsNeg());
66 CPPUNIT_ASSERT(!bi.IsBig());
67 CPPUNIT_ASSERT_EQUAL(std::numeric_limits<sal_Int32>::max(), static_cast<sal_Int32>(bi));
70 // negative number just fitting to sal_Int32
72 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int32>::min()));
73 CPPUNIT_ASSERT(!bi.IsZero());
74 CPPUNIT_ASSERT(bi.IsNeg());
75 CPPUNIT_ASSERT(!bi.IsBig());
76 CPPUNIT_ASSERT_EQUAL(std::numeric_limits<sal_Int32>::min(), static_cast<sal_Int32>(bi));
79 // positive number not fitting to sal_Int32
81 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int32>::max()) + 1);
82 CPPUNIT_ASSERT(!bi.IsZero());
83 CPPUNIT_ASSERT(!bi.IsNeg());
84 CPPUNIT_ASSERT(bi.IsBig());
87 // negative number not fitting to sal_Int32
89 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int32>::min()) - 1);
90 CPPUNIT_ASSERT(!bi.IsZero());
91 CPPUNIT_ASSERT(bi.IsNeg());
92 CPPUNIT_ASSERT(bi.IsBig());
95 // max possible sal_Int64 negative number
97 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int64>::min()));
98 CPPUNIT_ASSERT(!bi.IsZero());
99 CPPUNIT_ASSERT(bi.IsNeg());
100 CPPUNIT_ASSERT(bi.IsBig());
101 CPPUNIT_ASSERT_EQUAL(std::numeric_limits<sal_Int64>::min(), static_cast<sal_Int64>(bi));
104 // max possible sal_Int64 positive number
106 BigInt bi(static_cast<sal_Int64>(std::numeric_limits<sal_Int64>::max()));
107 CPPUNIT_ASSERT(!bi.IsZero());
108 CPPUNIT_ASSERT(!bi.IsNeg());
109 CPPUNIT_ASSERT(bi.IsBig());
110 CPPUNIT_ASSERT_EQUAL(std::numeric_limits<sal_Int64>::max(), static_cast<sal_Int64>(bi));
114 void BigIntTest::testLenB1()
116 BigInt dy(2634022912);
117 sal_Int64 md(-4177526784);
118 sal_Int64 mn(2634022912);
119 dy *= md;
120 dy -= (mn - 1) / 2;
121 dy /= mn;
123 CPPUNIT_ASSERT_EQUAL(sal_Int64(-4177526784), sal_Int64(dy));
126 CPPUNIT_TEST_SUITE_REGISTRATION(BigIntTest);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */