xref: /aoo41x/main/tools/test/tests.cxx (revision 89b56da7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_tools.hxx"
27 // autogenerated file with codegen.pl
28 
29 #include <testshl/simpleheader.hxx>
30 #include <rtl/math.hxx>
31 #include <tools/fract.hxx>
32 
33 #include <stdio.h>
34 
35 namespace tools
36 {
37 
38 class FractionTest : public CppUnit::TestFixture
39 {
40 public:
41     void setUp()
42     {
43     }
44 
45     void tearDown()
46     {
47     }
48 
49     void testFraction()
50     {
51         const Fraction aFract(1082130431,1073741824);
52         CPPUNIT_ASSERT_MESSAGE( "Fraction #1 not approximately equal to 1.007812499068677",
53                                 rtl::math::approxEqual((double)aFract,1.007812499068677) );
54 
55         Fraction aFract2( aFract );
56         aFract2.ReduceInaccurate(8);
57         CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1",
58                                 aFract2.GetNumerator() == 1 &&
59                                 aFract2.GetDenominator() == 1 );
60 
61         Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
62         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong",
63                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
64                                 aFract3.GetDenominator() == 0x35555555 );
65         aFract3.ReduceInaccurate(30);
66         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate errorneously cut precision",
67                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
68                                 aFract3.GetDenominator() == 0x35555555 );
69 
70         aFract3.ReduceInaccurate(29);
71         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed",
72                                 aFract3.GetNumerator() == 0x3D555555 &&
73                                 aFract3.GetDenominator() == 0x1AAAAAAA );
74 
75         aFract3.ReduceInaccurate(9);
76         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed",
77                                 aFract3.GetNumerator() == 0x0147 &&
78                                 aFract3.GetDenominator() == 0x008E );
79 
80         aFract3.ReduceInaccurate(1);
81         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed",
82                                 aFract3.GetNumerator() == 2 &&
83                                 aFract3.GetDenominator() == 1 );
84 
85         aFract3.ReduceInaccurate(0);
86         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed",
87                                 aFract3.GetNumerator() == 2 &&
88                                 aFract3.GetDenominator() == 1 );
89 
90 #if SAL_TYPES_SIZEOFLONG == 8
91 		Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
92 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 cancellation wrong",
93 						        aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
94 								aFract4.GetDenominator() == 0x3555555555555555 );
95 		aFract4.ReduceInaccurate(62);
96 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate errorneously cut precision",
97 								aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
98 								aFract4.GetDenominator() == 0x3555555555555555 );
99 
100 		aFract4.ReduceInaccurate(61);
101 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate reduce to 61 bit failed",
102 								aFract4.GetNumerator() == 0x3D55555555555555 &&
103 								aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA );
104 #endif
105 	}
106 
107     CPPUNIT_TEST_SUITE(FractionTest);
108     CPPUNIT_TEST(testFraction);
109     CPPUNIT_TEST_SUITE_END();
110 };
111 
112 // -----------------------------------------------------------------------------
113 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(tools::FractionTest, "FractionTest");
114 } // namespace tools
115 
116 
117 // -----------------------------------------------------------------------------
118 
119 // this macro creates an empty function, which will called by the RegisterAllFunctions()
120 // to let the user the possibility to also register some functions by hand.
121 NOADDITIONAL;
122 
123