1 |
jpye |
2397 |
/* 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_FIXED("x"); |
97 |
|
|
CHECK_FREE("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_FIXED("z"); |
123 |
|
|
|
124 |
|
|
sim_destroy(sim); |
125 |
|
|
Asc_CompilerDestroy(); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
/*===========================================================================*/ |
129 |
|
|
/* Registration information */ |
130 |
|
|
|
131 |
|
|
/* the list of tests */ |
132 |
|
|
|
133 |
|
|
#define TESTS(T) \ |
134 |
|
|
T(test1) \ |
135 |
|
|
T(test2) |
136 |
|
|
|
137 |
|
|
REGISTER_TESTS_SIMPLE(compiler_fixfree, TESTS) |
138 |
|
|
|