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