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 blackbox parsing/loading/evaluating. |
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, int assert_parse_ok, int *parsestatus){ |
45 |
struct module_t *m; |
46 |
|
47 |
Asc_CompilerInit(1); |
48 |
Asc_PutEnv(ASC_ENV_LIBRARY "=models"); |
49 |
|
50 |
/* load the file */ |
51 |
char path[PATH_MAX]; |
52 |
strcpy((char *)path,"test/blackbox/"); |
53 |
strncat(path, name, PATH_MAX - strlen(path)); |
54 |
strncat(path, ".a4c", PATH_MAX - strlen(path)); |
55 |
int openmodulestatus; |
56 |
m = Asc_OpenModule(path,&openmodulestatus); |
57 |
CU_ASSERT(openmodulestatus == 0); |
58 |
|
59 |
/* parse it */ |
60 |
if(assert_parse_ok){ |
61 |
CU_ASSERT((*parsestatus = zz_parse()) == 0); |
62 |
}else{ |
63 |
*parsestatus = zz_parse(); |
64 |
if(*parsestatus)return NULL; |
65 |
} |
66 |
|
67 |
/* instantiate it */ |
68 |
struct Instance *sim = SimsCreateInstance(AddSymbol(name), AddSymbol("sim1"), e_normal, NULL); |
69 |
CU_ASSERT_FATAL(sim!=NULL); |
70 |
|
71 |
return sim; |
72 |
} |
73 |
|
74 |
static void test_parsefail1(void){ |
75 |
int parsestatus; |
76 |
struct Instance *sim = load_model("parsefail1", FALSE, &parsestatus); |
77 |
CU_ASSERT(parsestatus!=0); |
78 |
CU_ASSERT(sim==NULL); |
79 |
Asc_CompilerDestroy(); |
80 |
} |
81 |
|
82 |
static void test_parsefail2(void){ |
83 |
int parsestatus; |
84 |
struct Instance *sim = load_model("parsefail2", FALSE, &parsestatus); |
85 |
CU_ASSERT(parsestatus!=0); |
86 |
CU_ASSERT(sim==NULL); |
87 |
Asc_CompilerDestroy(); |
88 |
} |
89 |
|
90 |
static void test_parsefail3(void){ |
91 |
int parsestatus; |
92 |
struct Instance *sim = load_model("parsefail3", FALSE, &parsestatus); |
93 |
CU_ASSERT(parsestatus!=0); |
94 |
CU_ASSERT(sim==NULL); |
95 |
Asc_CompilerDestroy(); |
96 |
} |
97 |
|
98 |
static void test_parsefail4(void){ |
99 |
int parsestatus; |
100 |
struct Instance *sim = load_model("parsefail4", FALSE, &parsestatus); |
101 |
CU_ASSERT(parsestatus!=0); |
102 |
CU_ASSERT(sim==NULL); |
103 |
Asc_CompilerDestroy(); |
104 |
} |
105 |
|
106 |
/*===========================================================================*/ |
107 |
/* Registration information */ |
108 |
|
109 |
/* the list of tests */ |
110 |
|
111 |
#define TESTS(T) \ |
112 |
T(parsefail1) \ |
113 |
T(parsefail2) \ |
114 |
T(parsefail3) \ |
115 |
T(parsefail4) |
116 |
|
117 |
REGISTER_TESTS_SIMPLE(compiler_blackbox, TESTS) |
118 |
|