/[ascend]/trunk/base/generic/compiler/test/test_hello.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/test/test_hello.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1639 - (show annotations) (download) (as text)
Thu Nov 8 12:50:01 2007 UTC (12 years, 11 months ago) by jpye
File MIME type: text/x-csrc
File size: 2755 byte(s)
Removed lint.
test_parse_string_module is working now.
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 #include <CUnit/CUnit.h>
24
25 #include <general/env.h>
26 #include <utilities/ascConfig.h>
27 #include <utilities/ascEnvVar.h>
28 #include <utilities/error.h>
29
30 #include <compiler/ascCompiler.h>
31 #include <compiler/module.h>
32 #include <compiler/parser.h>
33 #include <compiler/library.h>
34
35 #include <assertimpl.h>
36
37 static void test_init(void){
38
39 CU_ASSERT(0 == Asc_CompilerInit(0));
40
41 Asc_CompilerDestroy();
42 }
43
44 static void test_parse_string_module(void){
45
46 const char *model = "\n\
47 DEFINITION relation\
48 included IS_A boolean;\
49 message IS_A symbol;\
50 included := TRUE;\
51 message := 'none';\
52 END relation;\
53 MODEL test1;\n\
54 x IS_A real;\n\
55 x - 1 = 0;\n\
56 END test1;";
57
58 Asc_CompilerInit(1);
59
60 struct module_t *m;
61 int status;
62
63 m = Asc_OpenStringModule(model, &status, ""/* name prefix*/);
64
65 CONSOLE_DEBUG("Asc_OpenStringModule returns status=%d",status);
66 CU_ASSERT(status==0); /* if successfully created */
67
68 CONSOLE_DEBUG("Beginning parse of %s",Asc_ModuleName(m));
69 status = zz_parse();
70
71 CONSOLE_DEBUG("zz_parse returns status=%d",status);
72
73 CU_ASSERT(status==0);
74
75 struct gl_list_t *l = Asc_TypeByModule(m);
76 CONSOLE_DEBUG("%lu library entries loaded from %s",gl_length(l),Asc_ModuleName(m));
77
78 CU_ASSERT(gl_length(l)==2);
79 }
80
81
82 /*===========================================================================*/
83 /* Registration information */
84
85 /* the list of tests */
86
87 #define TESTS(T,X) \
88 T(init) \
89 X T(parse_string_module)
90
91 /* you shouldn't need to change the following */
92
93 #define TESTDECL(TESTFN) {#TESTFN,test_##TESTFN}
94
95 #define X ,
96
97 static CU_TestInfo hello_test_list[] = {
98 TESTS(TESTDECL,X)
99 X CU_TEST_INFO_NULL
100 };
101
102 static CU_SuiteInfo suites[] = {
103 {"test_compiler_hello", NULL, NULL, hello_test_list},
104 CU_SUITE_INFO_NULL
105 };
106
107 /*-------------------------------------------------------------------*/
108 CU_ErrorCode test_register_compiler_hello(void){
109 return CU_register_suites(suites);
110 }

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