1 /**
2  * Filename    : TestBoundingBox.cpp
3  * Description : Unit tests for BoundingBox
4  * Organization: European Media Laboratories Research gGmbH
5  * Created     : 2005-05-03
6  *
7  * <!--------------------------------------------------------------------------
8  * This file is part of libSBML.  Please visit http://sbml.org for more
9  * information about SBML, and the latest version of libSBML.
10  *
11  * Copyright (C) 2020 jointly by the following organizations:
12  *     1. California Institute of Technology, Pasadena, CA, USA
13  *     2. University of Heidelberg, Heidelberg, Germany
14  *     3. University College London, London, UK
15  *
16  * Copyright (C) 2019 jointly by the following organizations:
17  *     1. California Institute of Technology, Pasadena, CA, USA
18  *     2. University of Heidelberg, Heidelberg, Germany
19  *
20  * Copyright (C) 2013-2018 jointly by the following organizations:
21  *     1. California Institute of Technology, Pasadena, CA, USA
22  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
23  *     3. University of Heidelberg, Heidelberg, Germany
24  *
25  * Copyright (C) 2009-2013 jointly by the following organizations:
26  *     1. California Institute of Technology, Pasadena, CA, USA
27  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
28  *
29  * Copyright (C) 2004-2008 by European Media Laboratories Research gGmbH,
30  *     Heidelberg, Germany
31  *
32  * This library is free software; you can redistribute it and/or modify it
33  * under the terms of the GNU Lesser General Public License as published by
34  * the Free Software Foundation.  A copy of the license agreement is provided
35  * in the file named "LICENSE.txt" included with this software distribution
36  * and also available online as http://sbml.org/software/libsbml/license.html
37  * ------------------------------------------------------------------------ -->
38  */
39 
40 #include <sbml/common/common.h>
41 
42 #include <sbml/packages/layout/sbml/BoundingBox.h>
43 #include <sbml/packages/layout/extension/LayoutExtension.h>
44 
45 #include <check.h>
46 
47 LIBSBML_CPP_NAMESPACE_USE
48 
49 static BoundingBox* BB;
50 static LayoutPkgNamespaces* LN;
51 
52 static void
BoundingBoxTest_setup(void)53 BoundingBoxTest_setup (void)
54 {
55   LN = new LayoutPkgNamespaces();
56   BB = new BoundingBox(LN);
57 
58   if(BB == NULL)
59   {
60     fail("BoundingBox(); returned a NULL pointer.");
61   }
62 }
63 
64 static void
BoundingBoxTest_teardown(void)65 BoundingBoxTest_teardown (void)
66 {
67   delete BB;
68   delete LN;
69 }
70 
71 
72 CK_CPPSTART
73 
START_TEST(test_BoundingBox_create)74 START_TEST ( test_BoundingBox_create )
75 {
76   fail_unless( BB->getTypeCode() == SBML_LAYOUT_BOUNDINGBOX );
77   fail_unless( BB->getMetaId() == "" );
78   //   fail_unless( SBase_getNotes      ((SBase_t*) BB) == NULL );
79   //   fail_unless( SBase_getAnnotation ((SBase_t*) BB) == NULL );
80 
81   fail_unless(BB->isSetId() == false );
82 
83   Point* pos=BB->getPosition();
84   fail_unless(pos != NULL);
85   fail_unless(pos->getXOffset() == 0.0);
86   fail_unless(pos->getYOffset() == 0.0);
87   fail_unless(pos->getZOffset() == 0.0);
88 
89   Dimensions *dim=BB->getDimensions();
90   fail_unless(dim != NULL);
91   fail_unless(dim->getWidth () == 0.0);
92   fail_unless(dim->getHeight() == 0.0);
93   fail_unless(dim->getDepth () == 0.0);
94 
95 }
96 END_TEST
97 
98 
START_TEST(test_BoundingBox_createWith)99 START_TEST ( test_BoundingBox_createWith )
100 {
101   const char* id="BoundingBox";
102   BoundingBox *bb=new BoundingBox(LN,id);
103   fail_unless( bb->getTypeCode() == SBML_LAYOUT_BOUNDINGBOX );
104   fail_unless( bb->getMetaId()   == "" );
105   //   fail_unless( SBase_getNotes      ((SBase_t*) bb) == NULL );
106   //   fail_unless( SBase_getAnnotation ((SBase_t*) bb) == NULL );
107 
108   fail_unless( bb->isSetId() == true );
109   fail_unless( bb->getId() == id);
110 
111   Point *pos=bb->getPosition();
112   fail_unless(pos != NULL);
113   fail_unless(pos->getXOffset() == 0.0);
114   fail_unless(pos->getYOffset() == 0.0);
115   fail_unless(pos->getZOffset() == 0.0);
116 
117   Dimensions *dim=bb->getDimensions();
118   fail_unless(dim != NULL);
119   fail_unless(dim->getWidth () == 0.0);
120   fail_unless(dim->getHeight() == 0.0);
121   fail_unless(dim->getDepth () == 0.0);
122   delete bb;
123 }
124 END_TEST
125 
START_TEST(test_BoundingBox_createWith_NULL)126 START_TEST ( test_BoundingBox_createWith_NULL )
127 {
128   BoundingBox *bb=new BoundingBox(LN,"");
129   fail_unless( bb->getTypeCode()    == SBML_LAYOUT_BOUNDINGBOX );
130   fail_unless( bb->getMetaId()  == "" );
131   //   fail_unless( SBase_getNotes      ((SBase_t*) bb) == NULL );
132   //   fail_unless( SBase_getAnnotation ((SBase_t*) bb) == NULL );
133 
134   fail_unless( bb->isSetId() == false );
135 
136   Point *pos=bb->getPosition();
137   fail_unless(pos != NULL);
138   fail_unless(pos->getXOffset() == 0.0);
139   fail_unless(pos->getYOffset() == 0.0);
140   fail_unless(pos->getZOffset() == 0.0);
141 
142   Dimensions *dim=bb->getDimensions();
143   fail_unless(dim != NULL);
144   fail_unless(dim->getWidth () == 0.0);
145   fail_unless(dim->getHeight() == 0.0);
146   fail_unless(dim->getDepth () == 0.0);
147 
148   delete bb;
149 }
150 END_TEST
151 
START_TEST(test_BoundingBox_createWithCoordinates)152 START_TEST ( test_BoundingBox_createWithCoordinates )
153 {
154   const char* id="BoundingBox";
155   BoundingBox *bb=new BoundingBox(LN,id,1.1,-2.2,3.3,-4.4,5.5,-6.6);
156   fail_unless( bb->getTypeCode() == SBML_LAYOUT_BOUNDINGBOX );
157   fail_unless( bb->getMetaId() == "" );
158   //   fail_unless( SBase_getNotes      ((SBase_t*) bb) == NULL );
159   //   fail_unless( SBase_getAnnotation ((SBase_t*) bb) == NULL );
160 
161   fail_unless( bb->isSetId() == true );
162   fail_unless( bb->getId() == id);
163 
164   Point *pos=bb->getPosition();
165   fail_unless(pos != NULL);
166   fail_unless(pos->getXOffset() ==  1.1);
167   fail_unless(pos->getYOffset() == -2.2);
168   fail_unless(pos->getZOffset() ==  3.3);
169 
170   Dimensions *dim=bb->getDimensions();
171   fail_unless(dim != NULL);
172   fail_unless(dim->getWidth () == -4.4);
173   fail_unless(dim->getHeight() ==  5.5);
174   fail_unless(dim->getDepth () == -6.6);
175 
176   delete bb;
177 }
178 END_TEST
179 
START_TEST(test_BoundingBox_createWithCoordinates_NULL)180 START_TEST ( test_BoundingBox_createWithCoordinates_NULL )
181 {
182   BoundingBox *bb=new BoundingBox(LN,"",1.1,-2.2,3.3,-4.4,5.5,-6.6);
183   fail_unless( bb->getTypeCode() == SBML_LAYOUT_BOUNDINGBOX );
184   fail_unless( bb->getMetaId() == "" );
185   //   fail_unless( SBase_getNotes      ((SBase_t*) bb) == NULL );
186   //   fail_unless( SBase_getAnnotation ((SBase_t*) bb) == NULL );
187 
188   fail_unless( bb->isSetId() == false );
189 
190   Point *pos=bb->getPosition();
191   fail_unless(pos != NULL);
192   fail_unless(pos->getXOffset() ==  1.1);
193   fail_unless(pos->getYOffset() == -2.2);
194   fail_unless(pos->getZOffset() ==  3.3);
195 
196   Dimensions *dim=bb->getDimensions();
197   fail_unless(dim != NULL);
198   fail_unless(dim->getWidth () == -4.4);
199   fail_unless(dim->getHeight() ==  5.5);
200   fail_unless(dim->getDepth () == -6.6);
201 
202   delete bb;
203 }
204 END_TEST
205 
START_TEST(test_BoundingBox_setId)206 START_TEST ( test_BoundingBox_setId )
207 {
208   const char* id="BoundingBox";
209   BB->setId(id);
210   fail_unless(BB->isSetId() == true);
211   fail_unless(BB->getId() == id);
212 }
213 END_TEST
214 
START_TEST(test_BoundingBox_setId_NULL)215 START_TEST ( test_BoundingBox_setId_NULL )
216 {
217   BB->setId("");
218   fail_unless(BB->isSetId() == false);
219   fail_unless(BB->getId() == "");
220 }
221 END_TEST
222 
START_TEST(test_BoundingBox_setPosition)223 START_TEST ( test_BoundingBox_setPosition )
224 {
225   Point pos=Point(LN,-1.1,2.2,-3.3);
226   BB->setPosition(&pos);
227   Point *pos2=BB->getPosition();
228   fail_unless(pos2 != NULL);
229   fail_unless(pos.getXOffset() == pos2->getXOffset() );
230   fail_unless(pos.getYOffset() == pos2->getYOffset() );
231   fail_unless(pos.getZOffset() == pos2->getZOffset() );
232 }
233 END_TEST
234 
START_TEST(test_BoundingBox_setPosition_NULL)235 START_TEST ( test_BoundingBox_setPosition_NULL )
236 {
237   BB->setPosition(NULL);
238   Point *pos=BB->getPosition();
239   fail_unless(pos != NULL);
240   fail_unless(pos->getXOffset() == 0.0 );
241   fail_unless(pos->getYOffset() == 0.0 );
242   fail_unless(pos->getZOffset() == 0.0 );
243 }
244 END_TEST
245 
START_TEST(test_BoundingBox_setDimensions)246 START_TEST ( test_BoundingBox_setDimensions )
247 {
248   Dimensions dim=Dimensions(LN,-4.4,5.5,-6.6);
249   BB->setDimensions(&dim);
250   Dimensions *dim2=BB->getDimensions();
251   fail_unless(dim2 != NULL);
252   fail_unless(dim.getWidth () == dim2->getWidth () );
253   fail_unless(dim.getHeight() == dim2->getHeight() );
254   fail_unless(dim.getDepth () == dim2->getDepth () );
255 }
256 END_TEST
257 
START_TEST(test_BoundingBox_setDimensions_NULL)258 START_TEST ( test_BoundingBox_setDimensions_NULL )
259 {
260   BB->setDimensions(NULL);
261   Dimensions *dim=BB->getDimensions();
262   fail_unless(dim != NULL);
263   fail_unless(dim->getWidth () == 0.0 );
264   fail_unless(dim->getHeight() == 0.0 );
265   fail_unless(dim->getDepth () == 0.0 );
266 }
267 END_TEST
268 
START_TEST(test_BoundingBox_copyConstructor)269 START_TEST ( test_BoundingBox_copyConstructor )
270 {
271   BoundingBox* bb1=new BoundingBox();
272   XMLNode notes;
273   bb1->setNotes(&notes);
274   XMLNode annotation;
275   bb1->setAnnotation(&annotation);
276   BoundingBox* bb2=new BoundingBox(*bb1);
277   delete bb2;
278   delete bb1;
279 }
280 END_TEST
281 
START_TEST(test_BoundingBox_assignmentOperator)282 START_TEST ( test_BoundingBox_assignmentOperator )
283 {
284   BoundingBox* bb1=new BoundingBox();
285   XMLNode notes;
286   bb1->setNotes(&notes);
287   XMLNode annotation;
288   bb1->setAnnotation(&annotation);
289   BoundingBox bb2=*bb1;
290   delete bb1;
291 }
292 END_TEST
293 
294 Suite *
create_suite_BoundingBox(void)295 create_suite_BoundingBox (void)
296 {
297   Suite *suite = suite_create("BoundingBox");
298   TCase *tcase = tcase_create("BoundingBox");
299 
300 
301   tcase_add_checked_fixture( tcase,
302                             BoundingBoxTest_setup,
303                             BoundingBoxTest_teardown );
304 
305   tcase_add_test( tcase, test_BoundingBox_create                     );
306   tcase_add_test( tcase, test_BoundingBox_createWith                 );
307   tcase_add_test( tcase, test_BoundingBox_createWith_NULL            );
308   tcase_add_test( tcase, test_BoundingBox_createWithCoordinates_NULL );
309   tcase_add_test( tcase,   test_BoundingBox_createWithCoordinates    );
310   tcase_add_test( tcase, test_BoundingBox_setId                      );
311   tcase_add_test( tcase, test_BoundingBox_setId_NULL                 );
312   tcase_add_test( tcase, test_BoundingBox_setPosition                );
313   tcase_add_test( tcase, test_BoundingBox_setPosition_NULL           );
314   tcase_add_test( tcase, test_BoundingBox_setDimensions              );
315   tcase_add_test( tcase, test_BoundingBox_setDimensions_NULL         );
316   tcase_add_test( tcase, test_BoundingBox_copyConstructor            );
317   tcase_add_test( tcase, test_BoundingBox_assignmentOperator         );
318 
319   suite_add_tcase(suite, tcase);
320 
321   return suite;
322 }
323 
324 
325 CK_CPPEND
326