/[ascend]/trunk/ascend/compiler/test/test_fixfree.c
ViewVC logotype

Contents of /trunk/ascend/compiler/test/test_fixfree.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2408 - (show annotations) (download) (as text)
Thu Mar 3 02:58:22 2011 UTC (11 years, 5 months ago) by jpye
File MIME type: text/x-csrc
File size: 4279 byte(s)
Working on bug #491. More to come.
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 FIX and FREE argument lists, especially where
21 there are invalid things in the list.
22 */
23 #include <string.h>
24
25 #include <ascend/general/env.h>
26 #include <ascend/general/platform.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/symtab.h>
35 #include <ascend/compiler/simlist.h>
36 #include <ascend/compiler/instquery.h>
37 #include <ascend/compiler/parentchild.h>
38 #include <ascend/compiler/atomvalue.h>
39
40 #include <ascend/compiler/initialize.h>
41
42 #include <test/common.h>
43 #include <test/assertimpl.h>
44
45 static struct Instance *load_model(const char *name){
46 struct module_t *m;
47 int status;
48
49 Asc_CompilerInit(1);
50 Asc_PutEnv(ASC_ENV_LIBRARY "=models");
51
52 /* load the file */
53 m = Asc_OpenModule("test/compiler/fixfree.a4c",&status);
54 CU_ASSERT(status == 0);
55
56 /* parse it */
57 CU_ASSERT(0 == zz_parse());
58
59 /* instantiate it */
60 struct Instance *sim = SimsCreateInstance(AddSymbol(name), AddSymbol("sim1"), e_normal, NULL);
61 CU_ASSERT_FATAL(sim!=NULL);
62
63 return sim;
64 }
65
66 #define GET_FIXED(VAR) \
67 inst = ChildByChar(root,AddSymbol(VAR)); \
68 CU_ASSERT_FATAL(inst!=NULL); \
69 CU_ASSERT((InstanceKind(inst)==REAL_ATOM_INST)); \
70 inst = ChildByChar(inst,AddSymbol("fixed")); \
71 CU_ASSERT_FATAL(inst!=NULL);
72
73 #define CHECK_FIXED(VAR) \
74 GET_FIXED(VAR);\
75 CU_ASSERT(GetBooleanAtomValue(inst));
76 #define CHECK_FREE(VAR) \
77 GET_FIXED(VAR);\
78 CU_ASSERT(!GetBooleanAtomValue(inst));
79
80
81 static void test_test1(void){
82 struct Instance *sim = load_model("test1");
83
84 /* check for vars and rels */
85 struct Instance *root = GetSimulationRoot(sim);
86 struct Instance *inst;
87
88 CHECK_FREE("x");
89 CHECK_FREE("y");
90 CHECK_FREE("z");
91
92 /** Call on_load */
93 struct Name *name = CreateIdName(AddSymbol("on_load"));
94 enum Proc_enum pe = Initialize(GetSimulationRoot(sim),name,"sim1", ASCERR, WP_STOPONERR, NULL, NULL);
95 CU_ASSERT(pe==Proc_all_ok);
96
97 CHECK_FREE("x");
98 CHECK_FIXED("y");
99 CHECK_FREE("z");
100
101 sim_destroy(sim);
102 Asc_CompilerDestroy();
103 }
104
105 static void test_test2(void){
106 struct Instance *sim = load_model("test2");
107
108 /* check for vars and rels */
109 struct Instance *root = GetSimulationRoot(sim);
110 struct Instance *inst;
111
112 CHECK_FREE("x");
113 CHECK_FREE("y");
114 CHECK_FREE("z");
115
116 /** Call on_load */
117 struct Name *name = CreateIdName(AddSymbol("on_load"));
118 enum Proc_enum pe = Initialize(GetSimulationRoot(sim),name,"sim1", ASCERR, WP_STOPONERR, NULL, NULL);
119 CU_ASSERT(pe!=Proc_all_ok);
120
121 CHECK_FREE("y");
122 CHECK_FIXED("x");
123 CHECK_FREE("z"); /* we expect names after the wrong ones not to have been changed */
124
125 sim_destroy(sim);
126 Asc_CompilerDestroy();
127 }
128
129 static void test_test3(void){
130 struct Instance *sim = load_model("test3");
131
132 /* check for vars and rels */
133 struct Instance *root = GetSimulationRoot(sim);
134 struct Instance *inst;
135
136 CHECK_FREE("x");
137 CHECK_FREE("z");
138
139 /** Call on_load */
140 struct Name *name = CreateIdName(AddSymbol("on_load"));
141 enum Proc_enum pe = Initialize(GetSimulationRoot(sim),name,"sim1", ASCERR, WP_STOPONERR, NULL, NULL);
142 CU_ASSERT(pe!=Proc_all_ok);
143
144 CHECK_FIXED("x");
145 CHECK_FREE("z");
146
147 sim_destroy(sim);
148 Asc_CompilerDestroy();
149 }
150
151
152 /*===========================================================================*/
153 /* Registration information */
154
155 /* the list of tests */
156
157 #define TESTS(T) \
158 T(test1) \
159 T(test2) \
160 T(test3)
161
162 REGISTER_TESTS_SIMPLE(compiler_fixfree, TESTS)
163

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