1 /**
2 * \file TestCompartmentTypeType.c
3 * \brief CompartmentTypeType unit tests
4 * \author Sarah Keating
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2020 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. University of Heidelberg, Heidelberg, Germany
13 * 3. University College London, London, UK
14 *
15 * Copyright (C) 2019 jointly by the following organizations:
16 * 1. California Institute of Technology, Pasadena, CA, USA
17 * 2. University of Heidelberg, Heidelberg, Germany
18 *
19 * Copyright (C) 2013-2018 jointly by the following organizations:
20 * 1. California Institute of Technology, Pasadena, CA, USA
21 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22 * 3. University of Heidelberg, Heidelberg, Germany
23 *
24 * Copyright (C) 2009-2013 jointly by the following organizations:
25 * 1. California Institute of Technology, Pasadena, CA, USA
26 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27 *
28 * Copyright (C) 2006-2008 by the California Institute of Technology,
29 * Pasadena, CA, USA
30 *
31 * Copyright (C) 2002-2005 jointly by the following organizations:
32 * 1. California Institute of Technology, Pasadena, CA, USA
33 * 2. Japan Science and Technology Agency, Japan
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the GNU Lesser General Public License as published by
37 * the Free Software Foundation. A copy of the license agreement is provided
38 * in the file named "LICENSE.txt" included with this software distribution
39 * and also available online as http://sbml.org/software/libsbml/license.html
40 * ---------------------------------------------------------------------- -->*/
41
42 #include <sbml/common/common.h>
43
44 #include <sbml/SBase.h>
45 #include <sbml/CompartmentType.h>
46 #include <sbml/xml/XMLNamespaces.h>
47 #include <sbml/SBMLDocument.h>
48
49 #include <check.h>
50
51
52
53 #include <sbml/common/extern.h>
54
55 LIBSBML_CPP_NAMESPACE_USE
56
57 BEGIN_C_DECLS
58
59 static CompartmentType_t *CT;
60
61
62 void
CompartmentTypeTest_setup(void)63 CompartmentTypeTest_setup (void)
64 {
65 CT = CompartmentType_create(2, 4);
66
67 if (CT == NULL)
68 {
69 fail("CompartmentType_create() returned a NULL pointer.");
70 }
71 }
72
73
74 void
CompartmentTypeTest_teardown(void)75 CompartmentTypeTest_teardown (void)
76 {
77 CompartmentType_free(CT);
78 }
79
80
START_TEST(test_CompartmentType_create)81 START_TEST (test_CompartmentType_create)
82 {
83 fail_unless( SBase_getTypeCode ((SBase_t *) CT) == SBML_COMPARTMENT_TYPE );
84 fail_unless( SBase_getMetaId ((SBase_t *) CT) == NULL );
85 fail_unless( SBase_getNotes ((SBase_t *) CT) == NULL );
86 fail_unless( SBase_getAnnotation((SBase_t *) CT) == NULL );
87
88 fail_unless( CompartmentType_getId (CT) == NULL );
89 fail_unless( CompartmentType_getName (CT) == NULL );
90
91 fail_unless( !CompartmentType_isSetId (CT) );
92 fail_unless( !CompartmentType_isSetName (CT) );
93 }
94 END_TEST
95
96
97 //START_TEST (test_CompartmentType_createWith)
98 //{
99 // CompartmentType_t *c = CompartmentType_createWith("A", "");
100 //
101 //
102 // fail_unless( SBase_getTypeCode ((SBase_t *) c) == SBML_COMPARTMENT_TYPE );
103 // fail_unless( SBase_getMetaId ((SBase_t *) c) == NULL );
104 // fail_unless( SBase_getNotes ((SBase_t *) c) == NULL );
105 // fail_unless( SBase_getAnnotation((SBase_t *) c) == NULL );
106 //
107 // fail_unless( CompartmentType_getName(c) == NULL );
108 //
109 // fail_unless( !strcmp( CompartmentType_getId (c), "A" ) );
110 //
111 // fail_unless( CompartmentType_isSetId (c) );
112 // fail_unless( !CompartmentType_isSetName (c) );
113 //
114 // CompartmentType_free(c);
115 //}
116 //END_TEST
117
118
START_TEST(test_CompartmentType_free_NULL)119 START_TEST (test_CompartmentType_free_NULL)
120 {
121 CompartmentType_free(NULL);
122 }
123 END_TEST
124
125
START_TEST(test_CompartmentType_setId)126 START_TEST (test_CompartmentType_setId)
127 {
128 const char *id = "mitochondria";
129
130
131 CompartmentType_setId(CT, id);
132
133 fail_unless( !strcmp(CompartmentType_getId(CT), id) );
134 fail_unless( CompartmentType_isSetId(CT) );
135
136 if (CompartmentType_getId(CT) == id)
137 {
138 fail("CompartmentType_setId(...) did not make a copy of string.");
139 }
140
141 /* Reflexive case (pathological) */
142 CompartmentType_setId(CT, CompartmentType_getId(CT));
143 fail_unless( !strcmp(CompartmentType_getId(CT), id) );
144
145 CompartmentType_setId(CT, NULL);
146 fail_unless( !CompartmentType_isSetId(CT) );
147
148 if (CompartmentType_getId(CT) != NULL)
149 {
150 fail("CompartmentType_setId(CT, NULL) did not clear string.");
151 }
152 }
153 END_TEST
154
155
START_TEST(test_CompartmentType_setName)156 START_TEST (test_CompartmentType_setName)
157 {
158 const char *name = "My_Favorite_Factory";
159
160
161 CompartmentType_setName(CT, name);
162
163 fail_unless( !strcmp(CompartmentType_getName(CT), name) );
164 fail_unless( CompartmentType_isSetName(CT) );
165
166 if (CompartmentType_getName(CT) == name)
167 {
168 fail("CompartmentType_setName(...) did not make a copy of string.");
169 }
170
171 /* Reflexive case (pathological) */
172 CompartmentType_setName(CT, CompartmentType_getName(CT));
173 fail_unless( !strcmp(CompartmentType_getName(CT), name) );
174
175 CompartmentType_setName(CT, NULL);
176 fail_unless( !CompartmentType_isSetName(CT) );
177
178 if (CompartmentType_getName(CT) != NULL)
179 {
180 fail("CompartmentType_setName(CT, NULL) did not clear string.");
181 }
182 }
183 END_TEST
184
185
START_TEST(test_CompartmentType_unsetName)186 START_TEST (test_CompartmentType_unsetName)
187 {
188 CompartmentType_setName(CT, "name");
189
190 fail_unless( !strcmp( CompartmentType_getName(CT), "name" ));
191 fail_unless( CompartmentType_isSetName(CT) );
192
193 CompartmentType_unsetName(CT);
194
195 fail_unless( !CompartmentType_isSetName(CT) );
196 }
197 END_TEST
198
199
START_TEST(test_CompartmentType_createWithNS)200 START_TEST (test_CompartmentType_createWithNS )
201 {
202 XMLNamespaces_t *xmlns = XMLNamespaces_create();
203 XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml");
204 SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(2,2);
205 SBMLNamespaces_addNamespaces(sbmlns,xmlns);
206
207 CompartmentType_t *object =
208 CompartmentType_createWithNS (sbmlns);
209
210
211 fail_unless( SBase_getTypeCode ((SBase_t *) object) == SBML_COMPARTMENT_TYPE );
212 fail_unless( SBase_getMetaId ((SBase_t *) object) == NULL );
213 fail_unless( SBase_getNotes ((SBase_t *) object) == NULL );
214 fail_unless( SBase_getAnnotation((SBase_t *) object) == NULL );
215
216 fail_unless( SBase_getLevel ((SBase_t *) object) == 2 );
217 fail_unless( SBase_getVersion ((SBase_t *) object) == 2 );
218
219 fail_unless( CompartmentType_getNamespaces (object) != NULL );
220 fail_unless( XMLNamespaces_getLength(CompartmentType_getNamespaces(object)) == 2 );
221
222 CompartmentType_free(object);
223 XMLNamespaces_free(xmlns);
224 SBMLNamespaces_free(sbmlns);
225 }
226 END_TEST
227
228
229 Suite *
create_suite_CompartmentType(void)230 create_suite_CompartmentType (void)
231 {
232 Suite *suite = suite_create("CompartmentType");
233 TCase *tcase = tcase_create("CompartmentType");
234
235
236 tcase_add_checked_fixture( tcase,
237 CompartmentTypeTest_setup,
238 CompartmentTypeTest_teardown );
239
240 tcase_add_test( tcase, test_CompartmentType_create );
241 //tcase_add_test( tcase, test_CompartmentType_createWith );
242 tcase_add_test( tcase, test_CompartmentType_free_NULL );
243 tcase_add_test( tcase, test_CompartmentType_setId );
244 tcase_add_test( tcase, test_CompartmentType_setName );
245 tcase_add_test( tcase, test_CompartmentType_unsetName );
246 tcase_add_test( tcase, test_CompartmentType_createWithNS );
247
248 suite_add_tcase(suite, tcase);
249
250 return suite;
251 }
252
253 END_C_DECLS
254
255
256