xref: /aoo42x/main/tools/test/tests.cxx (revision 9a6a7a0a)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26 // autogenerated file with codegen.pl
27 
28 #include <testshl/simpleheader.hxx>
29 #include <rtl/math.hxx>
30 #include <tools/fract.hxx>
31 
32 #include <stdio.h>
33 
34 namespace tools
35 {
36 
37 class FractionTest : public CppUnit::TestFixture
38 {
39 public:
40     void setUp()
41     {
42     }
43 
44     void tearDown()
45     {
46     }
47 
48     void testFraction()
49     {
50         const Fraction aFract(1082130431,1073741824);
51         CPPUNIT_ASSERT_MESSAGE( "Fraction #1 not approximately equal to 1.007812499068677",
52                                 rtl::math::approxEqual((double)aFract,1.007812499068677) );
53 
54         Fraction aFract2( aFract );
55         aFract2.ReduceInaccurate(8);
56         CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1",
57                                 aFract2.GetNumerator() == 1 &&
58                                 aFract2.GetDenominator() == 1 );
59 
60         Fraction aFract3( 0x7AAAAAAA, 0x35555555 );
61         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong",
62                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
63                                 aFract3.GetDenominator() == 0x35555555 );
64         aFract3.ReduceInaccurate(30);
65         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate errorneously cut precision",
66                                 aFract3.GetNumerator() == 0x7AAAAAAA &&
67                                 aFract3.GetDenominator() == 0x35555555 );
68 
69         aFract3.ReduceInaccurate(29);
70         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed",
71                                 aFract3.GetNumerator() == 0x3D555555 &&
72                                 aFract3.GetDenominator() == 0x1AAAAAAA );
73 
74         aFract3.ReduceInaccurate(9);
75         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed",
76                                 aFract3.GetNumerator() == 0x0147 &&
77                                 aFract3.GetDenominator() == 0x008E );
78 
79         aFract3.ReduceInaccurate(1);
80         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed",
81                                 aFract3.GetNumerator() == 2 &&
82                                 aFract3.GetDenominator() == 1 );
83 
84         aFract3.ReduceInaccurate(0);
85         CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed",
86                                 aFract3.GetNumerator() == 2 &&
87                                 aFract3.GetDenominator() == 1 );
88 
89 #if SAL_TYPES_SIZEOFLONG == 8
90 		Fraction aFract4(0x7AAAAAAAAAAAAAAA, 0x3555555555555555);
91 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 cancellation wrong",
92 						        aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
93 								aFract4.GetDenominator() == 0x3555555555555555 );
94 		aFract4.ReduceInaccurate(62);
95 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate errorneously cut precision",
96 								aFract4.GetNumerator() == 0x7AAAAAAAAAAAAAAA &&
97 								aFract4.GetDenominator() == 0x3555555555555555 );
98 
99 		aFract4.ReduceInaccurate(61);
100 		CPPUNIT_ASSERT_MESSAGE( "Fraction #4 ReduceInaccurate reduce to 61 bit failed",
101 								aFract4.GetNumerator() == 0x3D55555555555555 &&
102 								aFract4.GetDenominator() == 0x1AAAAAAAAAAAAAAA );
103 #endif
104 	}
105 
106     CPPUNIT_TEST_SUITE(FractionTest);
107     CPPUNIT_TEST(testFraction);
108     CPPUNIT_TEST_SUITE_END();
109 };
110 
111 // -----------------------------------------------------------------------------
112 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(tools::FractionTest, "FractionTest");
113 } // namespace tools
114 
115 
116 // -----------------------------------------------------------------------------
117 
118 // this macro creates an empty function, which will called by the RegisterAllFunctions()
119 // to let the user the possibility to also register some functions by hand.
120 NOADDITIONAL;
121 
122