update dev300-m58
[ooovba.git] / tools / test / tests.cxx
blobc55d92ad6001bd4a4af9a28851fe713d8859b883
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tests.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_tools.hxx"
34 // autogenerated file with codegen.pl
36 #include <cppunit/simpleheader.hxx>
37 #include <rtl/math.hxx>
38 #include <tools/fract.hxx>
40 #include <stdio.h>
42 namespace tools
45 class FractionTest : public CppUnit::TestFixture
47 public:
48 void setUp()
52 void tearDown()
56 void testFraction()
58 const Fraction aFract(1082130431,1073741824);
59 CPPUNIT_ASSERT_MESSAGE( "Fraction #1 not approximately equal to 1.007812499068677",
60 rtl::math::approxEqual((double)aFract,1.007812499068677) );
62 Fraction aFract2( aFract );
63 aFract2.ReduceInaccurate(8);
64 CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1",
65 aFract2.GetNumerator() == 1 &&
66 aFract2.GetDenominator() == 1 );
68 Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
69 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong",
70 aFract3.GetNumerator() == 0x7AAAAAAA &&
71 aFract3.GetDenominator() == 0x35555555 );
72 aFract3.ReduceInaccurate(30);
73 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate errorneously cut precision",
74 aFract3.GetNumerator() == 0x7AAAAAAA &&
75 aFract3.GetDenominator() == 0x35555555 );
77 aFract3.ReduceInaccurate(29);
78 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed",
79 aFract3.GetNumerator() == 0x3D555555 &&
80 aFract3.GetDenominator() == 0x1AAAAAAA );
82 aFract3.ReduceInaccurate(9);
83 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed",
84 aFract3.GetNumerator() == 0x0147 &&
85 aFract3.GetDenominator() == 0x008E );
87 aFract3.ReduceInaccurate(1);
88 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed",
89 aFract3.GetNumerator() == 2 &&
90 aFract3.GetDenominator() == 1 );
92 aFract3.ReduceInaccurate(0);
93 CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed",
94 aFract3.GetNumerator() == 2 &&
95 aFract3.GetDenominator() == 1 );
97 #if SAL_TYPES_SIZEOFLONG == 8
98 Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
99 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 cancellation wrong",
100 aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
101 aFract4.GetDenominator() == 0x3555555555555555 );
102 aFract4.ReduceInaccurate(62);
103 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate errorneously cut precision",
104 aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
105 aFract4.GetDenominator() == 0x3555555555555555 );
107 aFract4.ReduceInaccurate(61);
108 CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate reduce to 61 bit failed",
109 aFract4.GetNumerator() == 0x3D55555555555555 &&
110 aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA );
111 #endif
114 CPPUNIT_TEST_SUITE(FractionTest);
115 CPPUNIT_TEST(testFraction);
116 CPPUNIT_TEST_SUITE_END();
119 // -----------------------------------------------------------------------------
120 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(tools::FractionTest, "FractionTest");
121 } // namespace tools
124 // -----------------------------------------------------------------------------
126 // this macro creates an empty function, which will called by the RegisterAllFunctions()
127 // to let the user the possibility to also register some functions by hand.
128 NOADDITIONAL;