1 /**
2  * @file    TestReadFromFileL3V2.cpp
3  * @brief   Tests for reading MathML from files into ASTNodes.
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 
43 #include <sbml/common/common.h>
44 
45 #include <sbml/SBMLReader.h>
46 #include <sbml/SBMLTypes.h>
47 
48 #include <sbml/math/ASTNode.h>
49 
50 
51 
52 #include <string>
53 
54 #include <check.h>
55 
56 static bool
equals(const char * expected,const char * actual)57 equals(const char* expected, const char* actual)
58 {
59   if (!strcmp(expected, actual)) return true;
60 
61   printf("\nStrings are not equal:\n");
62   printf("Expected:\n[%s]\n", expected);
63   printf("Actual:\n[%s]\n", actual);
64 
65   return false;
66 }
67 
68 LIBSBML_CPP_NAMESPACE_USE
69 
70 BEGIN_C_DECLS
71 
72 
73 extern char *TestDataDirectory;
74 
75 
START_TEST(test_read_MathML_L3V2)76 START_TEST (test_read_MathML_L3V2)
77 {
78   const char *expected =
79     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
80     "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
81     "  <apply>\n"
82     "    <max/>\n"
83     "    <cn> 2 </cn>\n"
84     "    <cn> 3 </cn>\n"
85     "  </apply>\n"
86     "</math>";
87 
88   std::string filename(TestDataDirectory);
89   filename += "L3V2Math.xml";
90 
91 
92   SBMLDocument *d = readSBML(filename.c_str());
93 
94   if (d == NULL)
95   {
96     fail("readSBML(\"L3V2Math.xml\") returned a NULL pointer.");
97   }
98 
99   Model * m = d->getModel();
100   fail_unless( m != NULL, NULL );
101 
102   InitialAssignment *ia = m->getInitialAssignment(0);
103   const ASTNode * math = ia->getMath();
104 
105   std::string out = writeMathMLToStdString(math);
106 
107   fail_unless(equals(expected, out.c_str()));
108 
109   const char *expected1 =
110     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
111     "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n"
112     "  <apply>\n"
113     "    <times/>\n"
114     "    <cn> 2 </cn>\n"
115     "    <cn> 3 </cn>\n"
116     "  </apply>\n"
117     "</math>";
118 
119   ia = m->getInitialAssignment(1);
120   math = ia->getMath();
121   fail_unless(math->getNumPlugins() == 0);
122 
123   out = writeMathMLToStdString(math);
124 
125   fail_unless(equals(expected1, out.c_str()));
126 
127   delete d;
128 }
129 END_TEST
130 
131 
132 Suite *
create_suite_TestReadFromFileL3V2(void)133 create_suite_TestReadFromFileL3V2(void)
134 {
135   Suite *suite = suite_create("test-data/L3V2Math.xml");
136   TCase *tcase = tcase_create("test-data/L3V2Math.xml");
137 
138 
139   tcase_add_test(tcase, test_read_MathML_L3V2);
140 
141   suite_add_tcase(suite, tcase);
142 
143   return suite;
144 }
145 
146 
147 END_C_DECLS
148 
149