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

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