1 //
2 // Filename    : TestTransformation
3 // Description : Tests for the Transformation class
4 // Organization: University of Heidelberg
5 // Created     : 2009-09-30
6 //
7 // Copyright 2008 University of Heidelberg
8 //
9 // This library is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU Lesser General Public License as published
11 // by the Free Software Foundation; either version 2.1 of the License, or
12 // any later version.
13 //
14 // This library is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
16 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
17 // documentation provided hereunder is on an "as is" basis, and the
18 // University of Heidelberg have no obligations to
19 // provide maintenance, support, updates, enhancements or modifications.
20 // In no event shall the University of Heidelberg be
21 // liable to any party for direct, indirect, special, incidental or
22 // consequential damages, including lost profits, arising out of the use of
23 // this software and its documentation, even if the University of
24 // Heidelberg have been advised of the possibility of such
25 // damage.  See the GNU Lesser General Public License for more details.
26 //
27 // You should have received a copy of the GNU Lesser General Public License
28 // along with this library; if not, write to the Free Software Foundation,
29 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 //
31 // The original code contained here was initially developed by:
32 //
33 //     Ralph Gauges
34 //     BIOQUANT/BQ0018
35 //     Im Neuenheimer Feld 267
36 //     69120 Heidelberg
37 //     Germany
38 //
39 //     mailto:ralph.gauges@bioquant.uni-heidelberg.de
40 //
41 // Contributor(s):
42 
43 
44 
45 #include <sbml/common/common.h>
46 #include <sbml/common/extern.h>
47 
48 #include "Transformation.h"
49 #include "Text.h"
50 
51 #include <check.h>
52 #include <limits>
53 
54 LIBSBML_CPP_NAMESPACE_USE
55 
56 BEGIN_C_DECLS
57 
58 static Transformation *T;
59 static RenderPkgNamespaces *renderns;
60 
61 void
TransformationTest_setup(void)62 TransformationTest_setup (void)
63 {
64   renderns = new (std::nothrow) RenderPkgNamespaces();
65     T = new (std::nothrow) Text(renderns);
66 
67     if (T == NULL)
68     {
69         fail("new(std::nothrow)Text(renderns) returned a NULL pointer.");
70     }
71 
72 }
73 
74 void
TransformationTest_teardown(void)75 TransformationTest_teardown (void)
76 {
77     delete T;
78     delete renderns;
79 }
80 
START_TEST(test_Transformation_setMatrix)81 START_TEST (test_Transformation_setMatrix )
82 {
83     fail_unless(!T->isSetMatrix());
84     const double* m=T->Transformation::getMatrix();
85     fail_unless(m != NULL);
86     double newM[12]={12.0,11.0,10.0,9.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0};
87     T->Transformation::setMatrix(newM);
88     fail_unless(T->isSetMatrix());
89     m=T->Transformation::getMatrix();
90     fail_unless(m != NULL);
91     // test the twelve values
92     fail_unless(fabs((m[0] - 12.0) / 12.0) < 1e-9);
93     fail_unless(fabs((m[1] - 11.0) / 11.0) < 1e-9);
94     fail_unless(fabs((m[2] - 10.0) / 10.0) < 1e-9);
95     fail_unless(fabs((m[3] - 9.0) / 9.0) < 1e-9);
96     fail_unless(fabs((m[4] - 8.0) / 8.0) < 1e-9);
97     fail_unless(fabs((m[5] - 7.0) / 7.0) < 1e-9);
98     fail_unless(fabs((m[6] - 6.0) / 6.0) < 1e-9);
99     fail_unless(fabs((m[7] - 5.0) / 5.0) < 1e-9);
100     fail_unless(fabs((m[8] - 4.0) / 4.0) < 1e-9);
101     fail_unless(fabs((m[9] - 3.0) / 3.0) < 1e-9);
102     fail_unless(fabs((m[10] - 2.0) / 2.0) < 1e-9);
103     fail_unless(fabs((m[11] - 1.0) / 1.0) < 1e-9);
104     m=Transformation::getIdentityMatrix();
105     fail_unless(m != NULL);
106     // test the twelve values
107     fail_unless(fabs((m[0] - 1.0) / 1.0) < 1e-9);
108     fail_unless(m[1]  < 1e-9);
109     fail_unless(m[2]  < 1e-9);
110     fail_unless(m[3]  < 1e-9);
111     fail_unless(fabs((m[4] - 1.0) / 1.0) < 1e-9);
112     fail_unless(m[5]  < 1e-9);
113     fail_unless(m[6]  < 1e-9);
114     fail_unless(m[7]  < 1e-9);
115     fail_unless(fabs((m[8] - 1.0) / 1.0) < 1e-9);
116     fail_unless(m[9]  < 1e-9);
117     fail_unless(m[10] < 1e-9);
118     fail_unless(m[11] < 1e-9);
119 }
120 END_TEST
121 
122 
START_TEST(test_Transformation_setTransform)123 START_TEST(test_Transformation_setTransform)
124 {
125   fail_unless(!T->isSetTransform());
126   double transform[] = { 0.0 };
127   T->getTransform(transform);
128   fail_unless(util_isEqual(transform[0], 0.0));
129 
130   double newTransform[12] = { 12.0,11.0,10.0,9.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0 };
131   T->setTransform(newTransform);
132   fail_unless(T->isSetTransform());
133 
134   double retTransform[12];
135   T->getTransform(retTransform);
136   fail_unless(retTransform != NULL);
137   // test the twelve values
138   fail_unless(util_isEqual(retTransform[0], 12.0));
139   fail_unless(util_isEqual(retTransform[1], 11.0));
140   fail_unless(util_isEqual(retTransform[2], 10.0));
141   fail_unless(util_isEqual(retTransform[3], 9.0));
142   fail_unless(util_isEqual(retTransform[4], 8.0));
143   fail_unless(util_isEqual(retTransform[5], 7.0));
144   fail_unless(util_isEqual(retTransform[6], 6.0));
145   fail_unless(util_isEqual(retTransform[7], 5.0));
146   fail_unless(util_isEqual(retTransform[8], 4.0));
147   fail_unless(util_isEqual(retTransform[9], 3.0));
148   fail_unless(util_isEqual(retTransform[10], 2.0));
149   fail_unless(util_isEqual(retTransform[11], 1.0));
150 
151   fail_unless(T->unsetTransform() == LIBSBML_OPERATION_SUCCESS);
152   fail_unless(!T->isSetTransform());
153 }
154 END_TEST
155 
156 
157 Suite *
create_suite_Transformation(void)158 create_suite_Transformation (void)
159 {
160   Suite *suite = suite_create("Transformation");
161   TCase *tcase = tcase_create("Transformation");
162 
163 
164   tcase_add_checked_fixture( tcase,
165                              TransformationTest_setup,
166                              TransformationTest_teardown );
167 
168   tcase_add_test( tcase, test_Transformation_setMatrix );
169   tcase_add_test(tcase, test_Transformation_setTransform);
170 
171   suite_add_tcase(suite, tcase);
172 
173   return suite;
174 }
175 
176 END_C_DECLS
177