diff options
author | David Tardon <dtardon@redhat.com> | 2014-10-17 13:08:32 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-10-17 13:17:21 +0200 |
commit | 968cadb82542b23271b8c472a2e6ec9248343925 (patch) | |
tree | a86a6c4fa87f43c3b053e38c0294ae5cbb234719 /tools/qa | |
parent | 08280034197b577abf994cc05322c010fd1f9895 (diff) |
allow construction of BigInt from sal_Int64 on 32 bit
Change-Id: Ib68920fc9bd693d2f2679b4fc27d9956dc42fc86
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_bigint.cxx | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_bigint.cxx b/tools/qa/cppunit/test_bigint.cxx new file mode 100644 index 000000000000..39ab2503f4ac --- /dev/null +++ b/tools/qa/cppunit/test_bigint.cxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <limits> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <rtl/math.hxx> + +#include <tools/bigint.hxx> + +namespace tools +{ + +class BigIntTest : public CppUnit::TestFixture +{ +public: +#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG + void testConstructionFromInt64(); +#endif + + CPPUNIT_TEST_SUITE(BigIntTest); +#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG + CPPUNIT_TEST(testConstructionFromLongLong); +#endif + CPPUNIT_TEST_SUITE_END(); +}; + +#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG +void BigIntTest::testConstructionFromLongLong() +{ + // small positive number + { + BigInt bi(static_cast<sal_Int64>(42)); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(!bi.IsNeg()); + CPPUNIT_ASSERT(bi.IsLong()); + CPPUNIT_ASSERT_EQUAL(42L, bi); + } + + // small negative number + { + BigInt bi(static_cast<sal_Int64>(-42)); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(bi.IsNeg()); + CPPUNIT_ASSERT(bi.IsLong()); + CPPUNIT_ASSERT_EQUAL(-42L, bi); + } + + // positive number just fitting to long + { + BigInt bi(static_cast<sal_Int64>(std::numeric_limits<long>::max())); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(!bi.IsNeg()); + CPPUNIT_ASSERT(bi.IsLong()); + CPPUNIT_ASSERT_EQUAL(std::numeric_limits<long>::max(), bi); + } + + // negative number just fitting to long + { + BigInt bi(static_cast<sal_Int64>(std::numeric_limits<long>::min())); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(bi.IsNeg()); + CPPUNIT_ASSERT(bi.IsLong()); + CPPUNIT_ASSERT_EQUAL(std::numeric_limits<long>::min(), bi); + } + + // positive number not fitting to long + { + BigInt bi(static_cast<sal_Int64>(std::numeric_limits<long>::max() + 1)); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(!bi.IsNeg()); + CPPUNIT_ASSERT(!bi.IsLong()); + } + + // negative number not fitting to long + { + BigInt bi(static_cast<sal_Int64>(std::numeric_limits<long>::min() - 1)); + BigInt bi(static_cast<sal_Int64>(42)); + CPPUNIT_ASSERT(bi.IsSet()); + CPPUNIT_ASSERT(!bi.IsZero()); + CPPUNIT_ASSERT(bi.IsNeg()); + CPPUNIT_ASSERT(!bi.IsLong()); + } +} +#endif + +CPPUNIT_TEST_SUITE_REGISTRATION(BigIntTest); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |