/[ascend]/trunk/ascend/packages/test/test_defaultall.c
ViewVC logotype

Contents of /trunk/ascend/packages/test/test_defaultall.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2241 - (show annotations) (download) (as text)
Sun Aug 1 03:17:50 2010 UTC (8 years, 11 months ago) by jpye
File MIME type: text/x-csrc
File size: 5394 byte(s)
Adding test case for defaultall.c errors.
1 /* ASCEND modelling environment
2 Copyright (C) 2007 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 @file
20 Unit test functions for default_all automatic recursive methods.
21 */
22 #include <string.h>
23 #include <CUnit/CUnit.h>
24
25 #include <ascend/general/env.h>
26 #include <ascend/utilities/ascConfig.h>
27 #include <ascend/utilities/ascEnvVar.h>
28 #include <ascend/utilities/error.h>
29
30 #include <ascend/compiler/ascCompiler.h>
31 #include <ascend/compiler/module.h>
32 #include <ascend/compiler/parser.h>
33 #include <ascend/compiler/library.h>
34 #include <ascend/compiler/simlist.h>
35 #include <ascend/compiler/instquery.h>
36 #include <ascend/compiler/parentchild.h>
37 #include <ascend/compiler/atomvalue.h>
38 #include <ascend/compiler/instance_io.h>
39 #include <ascend/compiler/instantiate.h>
40 #include <ascend/compiler/initialize.h>
41 #include <ascend/compiler/watchpt.h>
42
43 #include <test/assertimpl.h>
44
45
46 static void test_default1(void){
47
48 struct module_t *m;
49 int status;
50
51 CONSOLE_DEBUG("Loading model...");
52
53 Asc_CompilerInit(1);
54 Asc_PutEnv(ASC_ENV_LIBRARY "=models");
55
56 /* load the file */
57 m = Asc_OpenModule("test/defaultall/test1.a4c",&status);
58 CU_ASSERT(status == 0);
59
60 /* parse it */
61 CU_ASSERT(0 == zz_parse());
62
63 /* find the model */
64 CU_ASSERT(FindType(AddSymbol("test1"))!=NULL);
65
66 /* instantiate it */
67 struct Instance *sim = SimsCreateInstance(AddSymbol("test1"), AddSymbol("sim1"), e_normal, NULL);
68 CU_ASSERT_FATAL(sim!=NULL);
69
70 CONSOLE_DEBUG("Running on_load...");
71
72 symchar *onload = AddSymbol("on_load");
73 enum Proc_enum pe;
74 pe = Initialize(sim,CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);
75 CU_ASSERT_FATAL(pe == Proc_all_ok);
76
77 /* check for vars and rels */
78 struct Instance *root = GetSimulationRoot(sim);
79 struct Instance *inst, *a, *b;
80
81 CU_ASSERT_FATAL((inst = ChildByChar(root,AddSymbol("s1"))) && InstanceKind(inst)==MODEL_INST);
82 CU_ASSERT_FATAL((a = ChildByChar(inst,AddSymbol("a"))) && InstanceKind(a)==REAL_ATOM_INST);
83 CU_ASSERT_FATAL((b = ChildByChar(inst,AddSymbol("b"))) && InstanceKind(b)==REAL_ATOM_INST);
84
85 CONSOLE_DEBUG("Checking values...");
86
87 /* check that values have been correctly initialised */
88 double va = RealAtomValue(a);
89 double vb = RealAtomValue(b);
90 CONSOLE_DEBUG("Value of 'a' = %f",va);
91 CU_ASSERT(vb==4.);
92 CONSOLE_DEBUG("Value of 'b' = %f",vb);
93 CU_ASSERT(vb==8.);
94
95 CONSOLE_DEBUG("Cleaning up...");
96 /* clean up */
97 sim_destroy(sim);
98 Asc_CompilerDestroy();
99 }
100
101
102
103 static void test_default2(void){
104
105 struct module_t *m;
106 int status;
107
108 CONSOLE_DEBUG("Loading model...");
109
110 Asc_CompilerInit(1);
111 Asc_PutEnv(ASC_ENV_LIBRARY "=models");
112
113 /* load the file */
114 m = Asc_OpenModule("test/defaultall/test2.a4c",&status);
115 CU_ASSERT(status == 0);
116
117 /* parse it */
118 CU_ASSERT(0 == zz_parse());
119
120 /* find the model */
121 CU_ASSERT(FindType(AddSymbol("test2"))!=NULL);
122
123 /* instantiate it */
124 struct Instance *sim = SimsCreateInstance(AddSymbol("test2"), AddSymbol("sim1"), e_normal, NULL);
125 CU_ASSERT_FATAL(sim!=NULL);
126
127 CONSOLE_DEBUG("Running on_load...");
128
129 symchar *onload = AddSymbol("on_load");
130 enum Proc_enum pe;
131 pe = Initialize(sim,CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);
132 CU_ASSERT_FATAL(pe == Proc_all_ok);
133
134 /* check for vars and rels */
135 struct Instance *root = GetSimulationRoot(sim);
136 struct Instance *inst, *a, *b;
137
138 CU_ASSERT_FATAL((inst = ChildByChar(root,AddSymbol("s2"))) && InstanceKind(inst)==MODEL_INST);
139 CU_ASSERT_FATAL((inst = ChildByChar(root,AddSymbol("s1a"))) && InstanceKind(inst)==MODEL_INST);
140 CU_ASSERT_FATAL((a = ChildByChar(inst,AddSymbol("a"))) && InstanceKind(a)==REAL_ATOM_INST);
141 CU_ASSERT_FATAL((b = ChildByChar(inst,AddSymbol("b"))) && InstanceKind(b)==REAL_ATOM_INST);
142
143 CONSOLE_DEBUG("Checking values...");
144
145 /* check that values have been correctly initialised */
146 double va = RealAtomValue(a);
147 double vb = RealAtomValue(b);
148 CONSOLE_DEBUG("Value of 'a' = %f",va);
149 CU_ASSERT(vb==4.);
150 CONSOLE_DEBUG("Value of 'b' = %f",vb);
151 CU_ASSERT(vb==8.);
152
153 CONSOLE_DEBUG("Cleaning up...");
154 /* clean up */
155 sim_destroy(sim);
156 Asc_CompilerDestroy();
157 }
158
159
160 /*===========================================================================*/
161 /* Registration information */
162
163 /* the list of tests */
164
165 #define TESTS(T,X) \
166 T(default1) \
167 X T(default2)
168
169 /* you shouldn't need to change the following */
170
171 #define TESTDECL(TESTFN) {#TESTFN,test_##TESTFN}
172
173 #define X ,
174
175 static CU_TestInfo defaultall_test_list[] = {
176 TESTS(TESTDECL,X)
177 X CU_TEST_INFO_NULL
178 };
179
180 static CU_SuiteInfo suites[] = {
181 {"packages_defaultall", NULL, NULL, defaultall_test_list},
182 CU_SUITE_INFO_NULL
183 };
184
185 /*-------------------------------------------------------------------*/
186 CU_ErrorCode test_register_packages_defaultall(void){
187 return CU_register_suites(suites);
188 }
189

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22