1 /**
2 * \file TestValidation.cpp
3 * \brief Validation of Date ModelCreator and ModelHistory 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 #include <sbml/common/extern.h>
44
45 #include <sbml/SBMLReader.h>
46 #include <sbml/SBMLTypes.h>
47
48 #include <sbml/SBMLDocument.h>
49 #include <sbml/Model.h>
50 #include <sbml/SBMLTypeCodes.h>
51
52 #include <sbml/annotation/RDFAnnotation.h>
53 #include <sbml/annotation/ModelHistory.h>
54 #include <sbml/annotation/ModelCreator.h>
55 #include <sbml/annotation/Date.h>
56 #include <check.h>
57
58 LIBSBML_CPP_NAMESPACE_USE
59
60 CK_CPPSTART
61
START_TEST(test_Validation_Date1)62 START_TEST (test_Validation_Date1)
63 {
64 Date * date = new Date(200, 12, 30, 12, 15, 45, 1, 2, 0);
65 fail_unless(date != NULL);
66
67 fail_unless (!(date->representsValidDate()));
68
69 delete date;
70 }
71 END_TEST
72
73
START_TEST(test_Validation_Date2)74 START_TEST (test_Validation_Date2)
75 {
76 Date * date = new Date(2007, 14, 30, 12, 15, 45, 1, 2, 0);
77 fail_unless(date != NULL);
78
79 fail_unless (!(date->representsValidDate()));
80
81 delete date;
82 }
83 END_TEST
84
85
START_TEST(test_Validation_Date3)86 START_TEST (test_Validation_Date3)
87 {
88 Date * date = new Date("Jan 12");
89 fail_unless(date != NULL);
90
91 fail_unless (!(date->representsValidDate()));
92
93 delete date;
94 }
95 END_TEST
96
97
START_TEST(test_Validation_Date4)98 START_TEST (test_Validation_Date4)
99 {
100 Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0);
101 fail_unless(date != NULL);
102
103 fail_unless (date->representsValidDate());
104
105 delete date;
106 }
107 END_TEST
108
109
START_TEST(test_Validation_ModelCreator)110 START_TEST (test_Validation_ModelCreator)
111 {
112 ModelCreator * mc = new ModelCreator();
113 fail_unless(mc != NULL);
114
115 fail_unless (!(mc->hasRequiredAttributes()));
116
117 mc->setEmail("k123");
118
119 fail_unless (!(mc->hasRequiredAttributes()));
120
121 mc->setFamilyName("Keating");
122
123 fail_unless (!(mc->hasRequiredAttributes()));
124
125 mc->setGivenName("Sarah");
126
127 fail_unless (mc->hasRequiredAttributes());
128
129 delete mc;
130 }
131 END_TEST
132
133
START_TEST(test_Validation_ModelHistory1)134 START_TEST (test_Validation_ModelHistory1)
135 {
136 ModelHistory * mh = new ModelHistory();
137 fail_unless(mh != NULL);
138
139 fail_unless (!(mh->hasRequiredAttributes()));
140
141 Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0);
142 mh->setCreatedDate(date);
143
144 fail_unless (!(mh->hasRequiredAttributes()));
145
146 mh->setModifiedDate(date);
147
148 fail_unless (!(mh->hasRequiredAttributes()));
149
150 ModelCreator * mc = new ModelCreator();
151 mc->setFamilyName("Keating");
152 mc->setGivenName("Sarah");
153
154 mh->addCreator(mc);
155
156 fail_unless (mh->hasRequiredAttributes());
157
158 delete mh;
159 delete mc;
160 delete date;
161 }
162 END_TEST
163
164
START_TEST(test_Validation_ModelHistory2)165 START_TEST (test_Validation_ModelHistory2)
166 {
167 ModelHistory * mh = new ModelHistory();
168 fail_unless(mh != NULL);
169
170 fail_unless (!(mh->hasRequiredAttributes()));
171
172 Date * date = new Date(200, 12, 30, 12, 15, 45, 1, 2, 0);
173 mh->setCreatedDate(date);
174
175 fail_unless (!(mh->hasRequiredAttributes()));
176
177 mh->setModifiedDate(date);
178
179 fail_unless (!(mh->hasRequiredAttributes()));
180
181 ModelCreator * mc = new ModelCreator();
182 mc->setFamilyName("Keating");
183 mc->setGivenName("Sarah");
184
185 mh->addCreator(mc);
186
187 fail_unless (!(mh->hasRequiredAttributes()));
188
189 delete mh;
190 delete mc;
191 delete date;
192 }
193 END_TEST
194
195
START_TEST(test_Validation_ModelHistory3)196 START_TEST (test_Validation_ModelHistory3)
197 {
198 ModelHistory * mh = new ModelHistory();
199 fail_unless(mh != NULL);
200
201 fail_unless (!(mh->hasRequiredAttributes()));
202
203 Date * date = new Date(2007, 12, 30, 12, 15, 45, 1, 2, 0);
204 mh->setCreatedDate(date);
205
206 fail_unless (!(mh->hasRequiredAttributes()));
207
208 mh->setModifiedDate(date);
209
210 fail_unless (!(mh->hasRequiredAttributes()));
211
212 ModelCreator * mc = new ModelCreator();
213 mc->setFamilyName("Keating");
214
215 mh->addCreator(mc);
216
217 fail_unless (!(mh->hasRequiredAttributes()));
218
219 delete mh;
220 delete mc;
221 delete date;
222 }
223 END_TEST
224
225
START_TEST(test_Validation_CVTerm1)226 START_TEST (test_Validation_CVTerm1)
227 {
228 CVTerm * cv = new CVTerm();
229 fail_unless(cv != NULL);
230
231 fail_unless (!(cv->hasRequiredAttributes()));
232
233 cv->setQualifierType(MODEL_QUALIFIER);
234
235 fail_unless (!(cv->hasRequiredAttributes()));
236
237 cv->setModelQualifierType(BQM_IS);
238
239 fail_unless (!(cv->hasRequiredAttributes()));
240
241 cv->addResource("ggg");
242
243 fail_unless ((cv->hasRequiredAttributes()));
244
245 delete cv;
246 }
247 END_TEST
248
249
START_TEST(test_Validation_CVTerm2)250 START_TEST (test_Validation_CVTerm2)
251 {
252 CVTerm * cv = new CVTerm();
253 fail_unless(cv != NULL);
254
255 fail_unless (!(cv->hasRequiredAttributes()));
256
257 cv->setQualifierType(BIOLOGICAL_QUALIFIER);
258
259 fail_unless (!(cv->hasRequiredAttributes()));
260
261 cv->setBiologicalQualifierType(BQB_IS);
262
263 fail_unless (!(cv->hasRequiredAttributes()));
264
265 cv->addResource("ggg");
266
267 fail_unless ((cv->hasRequiredAttributes()));
268
269 delete cv;
270 }
271 END_TEST
272
START_TEST(test_Validation_Date_Default)273 START_TEST (test_Validation_Date_Default)
274 {
275 Date *date1 = new Date();
276 Date *date2 = new Date("");
277
278 fail_unless (date1->getYear() == date2->getYear() );
279 fail_unless (date1->getMonth() == date2->getMonth() );
280 fail_unless (date1->getDay() == date2->getDay() );
281 fail_unless (date1->getHour() == date2->getHour() );
282 fail_unless (date1->getMinute() == date2->getMinute() );
283 fail_unless (date1->getSecond() == date2->getSecond() );
284 fail_unless (date1->getSignOffset() == date2->getSignOffset() );
285 fail_unless (date1->getHoursOffset() == date2->getHoursOffset() );
286 fail_unless (date1->getMinutesOffset() == date2->getMinutesOffset() );
287
288 delete date1;
289 delete date2;
290
291 }
292 END_TEST
293
294
295 Suite *
create_suite_Validation(void)296 create_suite_Validation (void)
297 {
298 Suite *suite = suite_create("Validation");
299 TCase *tcase = tcase_create("Validation");
300
301 tcase_add_test(tcase, test_Validation_Date1 );
302 tcase_add_test(tcase, test_Validation_Date2 );
303 tcase_add_test(tcase, test_Validation_Date3 );
304 tcase_add_test(tcase, test_Validation_Date4 );
305 tcase_add_test(tcase, test_Validation_Date_Default );
306 tcase_add_test(tcase, test_Validation_ModelCreator );
307 tcase_add_test(tcase, test_Validation_ModelHistory1 );
308 tcase_add_test(tcase, test_Validation_ModelHistory2 );
309 tcase_add_test(tcase, test_Validation_ModelHistory3 );
310 tcase_add_test(tcase, test_Validation_CVTerm1 );
311 tcase_add_test(tcase, test_Validation_CVTerm2 );
312
313 suite_add_tcase(suite, tcase);
314
315 return suite;
316 }
317
318
319 CK_CPPEND
320
321