1 /**
2  * @file    TestConversionOption.cpp
3  * @brief   Tests for creating conversion options
4  * @author  Frank Bergmann
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/SBMLReader.h>
45 #include <sbml/SBMLTypes.h>
46 
47 #include <sbml/conversion/ConversionOption.h>
48 
49 
50 
51 #include <string>
52 
53 #include <check.h>
54 
55 LIBSBML_CPP_NAMESPACE_USE
56 
57 BEGIN_C_DECLS
58 
59 
60 extern char *TestDataDirectory;
61 
62 
START_TEST(test_conversion_options_read)63 START_TEST (test_conversion_options_read)
64 {
65   ConversionOption option("key");
66 
67   fail_unless(option.getKey() == "key");
68   fail_unless(option.getValue() == "");
69   fail_unless(option.getType() == CNV_TYPE_STRING);
70   fail_unless(option.getDescription() == "");
71 
72   option.setDescription("Something");
73   fail_unless(option.getDescription() == "Something");
74 
75   option.setValue("Something");
76   fail_unless(option.getValue() == "Something");
77 
78   option.setType(CNV_TYPE_BOOL);
79   fail_unless(option.getType() == CNV_TYPE_BOOL);
80 
81 }
82 END_TEST
83 
START_TEST(test_conversion_options_convert)84 START_TEST (test_conversion_options_convert)
85 {
86   ConversionOption option("key", "1");
87   fail_unless(option.getKey() == "key");
88   fail_unless(option.getValue() == "1");
89   fail_unless(option.getIntValue() == 1);
90   fail_unless(option.getDoubleValue() == 1.0);
91   fail_unless(option.getFloatValue() == 1.0f);
92   fail_unless(option.getBoolValue() == ((bool)1));
93 
94 }
95 END_TEST
96 
97 
START_TEST(test_conversion_options_readWrite)98   START_TEST (test_conversion_options_readWrite)
99 {
100   ConversionOption option("key", true, "");
101   fail_unless(option.getBoolValue() == true);
102   fail_unless(option.getValue() == "true");
103 
104   option.setBoolValue(false);
105   fail_unless(option.getBoolValue() == false);
106   fail_unless(option.getType() == CNV_TYPE_BOOL);
107 
108   option.setIntValue(0);
109   fail_unless(option.getBoolValue() == false);
110 
111   option.setIntValue(1);
112   fail_unless(option.getBoolValue() == true);
113 
114 }
115 END_TEST
116 
START_TEST(test_conversion_options_set)117 START_TEST (test_conversion_options_set)
118 {
119   ConversionOption option("key", "test", "");
120   fail_unless(option.getValue() == "test");
121   fail_unless(option.getType() == CNV_TYPE_STRING);
122 
123   option.setFloatValue(1.1f);
124   fail_unless(option.getFloatValue() == 1.1f );
125   fail_unless(option.getType() == CNV_TYPE_SINGLE);
126 
127   option.setDoubleValue(2.1);
128   fail_unless(option.getDoubleValue() == 2.1 );
129   fail_unless(option.getType() == CNV_TYPE_DOUBLE);
130 
131   option.setIntValue(3);
132   fail_unless(option.getIntValue() == 3 );
133   fail_unless(option.getType() == CNV_TYPE_INT);
134 
135   option.setBoolValue(true);
136   fail_unless(option.getBoolValue() == true );
137   fail_unless(option.getType() == CNV_TYPE_BOOL);
138 
139 }
140 END_TEST
141 
START_TEST(test_conversion_options_constructor)142 START_TEST (test_conversion_options_constructor)
143 {
144   ConversionOption option1("key", "test", "");
145   fail_unless(option1.getValue() == "test");
146   fail_unless(option1.getType() == CNV_TYPE_STRING);
147 
148   ConversionOption option2("key", 1.1, "");
149   fail_unless(option2.getDoubleValue() == 1.1);
150   fail_unless(option2.getType() == CNV_TYPE_DOUBLE);
151 
152   ConversionOption option3("key", 1.1f, "");
153   fail_unless(option3.getFloatValue() == 1.1f);
154   fail_unless(option3.getType() == CNV_TYPE_SINGLE);
155 
156   ConversionOption option4("key", 10, "");
157   fail_unless(option4.getIntValue() == 10);
158   fail_unless(option4.getType() == CNV_TYPE_INT);
159 
160   ConversionOption option5("key", false, "");
161   fail_unless(option5.getBoolValue() == false);
162   fail_unless(option5.getType() == CNV_TYPE_BOOL);
163 
164 }
165 END_TEST
166 
START_TEST(test_conversion_options_clone)167 START_TEST (test_conversion_options_clone)
168 {
169   ConversionOption option("key", 1.1, "some description");
170   fail_unless(option.getDoubleValue() == 1.1);
171   fail_unless(option.getType() == CNV_TYPE_DOUBLE);
172 
173   ConversionOption *clone = option.clone();
174 
175   fail_unless(option.getKey() == clone->getKey());
176   fail_unless(option.getType() == clone->getType());
177   fail_unless(option.getValue() == clone->getValue());
178   fail_unless(option.getDescription() == clone->getDescription());
179 
180   delete clone;
181 }
182 END_TEST
183 
184 
185 
186 Suite *
create_suite_TestConversionOption(void)187 create_suite_TestConversionOption (void)
188 {
189   Suite *suite = suite_create("ConversionOption");
190   TCase *tcase = tcase_create("ConversionOption");
191 
192 
193   tcase_add_test(tcase, test_conversion_options_read);
194   tcase_add_test(tcase, test_conversion_options_convert);
195   tcase_add_test(tcase, test_conversion_options_readWrite);
196   tcase_add_test(tcase, test_conversion_options_set);
197   tcase_add_test(tcase, test_conversion_options_constructor);
198   tcase_add_test(tcase, test_conversion_options_clone);
199 
200   suite_add_tcase(suite, tcase);
201 
202   return suite;
203 }
204 
205 
206 END_C_DECLS
207 
208