/[ascend]/trunk/ascend/packages/test/test_defaultall.c
ViewVC logotype

Diff of /trunk/ascend/packages/test/test_defaultall.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2243 by jpye, Sun Aug 1 03:55:33 2010 UTC revision 2244 by jpye, Mon Aug 2 01:05:11 2010 UTC
# Line 43  Line 43 
43  #include <test/assertimpl.h>  #include <test/assertimpl.h>
44    
45    
46  static void test_default1(void){  static struct Instance *load_and_initialise(const char *fname, const char *modelname){
47    
48      struct module_t *m;      struct module_t *m;
49      int status;      int status;
50    
51      CONSOLE_DEBUG("Loading model...");      CONSOLE_DEBUG("Loading model '%s'...",fname);
52    
53      Asc_CompilerInit(1);      Asc_CompilerInit(1);
54      Asc_PutEnv(ASC_ENV_LIBRARY "=models");      Asc_PutEnv(ASC_ENV_LIBRARY "=models");
55            
56      /* load the file */      /* load the file */
57      m = Asc_OpenModule("test/defaultall/test1.a4c",&status);      m = Asc_OpenModule(fname,&status);
58      CU_ASSERT(status == 0);      CU_ASSERT(status == 0);
59    
60      /* parse it */      /* parse it */
61      CU_ASSERT(0 == zz_parse());      CU_ASSERT(0 == zz_parse());
62    
63      /* find the model */          /* find the model */    
64      CU_ASSERT(FindType(AddSymbol("test1"))!=NULL);      CU_ASSERT(FindType(AddSymbol(modelname))!=NULL);
65    
66      /* instantiate it */      /* instantiate it */
67      struct Instance *sim = SimsCreateInstance(AddSymbol("test1"), AddSymbol("sim1"), e_normal, NULL);      struct Instance *sim = SimsCreateInstance(AddSymbol(modelname), AddSymbol("sim1"), e_normal, NULL);
68      CU_ASSERT_FATAL(sim!=NULL);      CU_ASSERT_FATAL(sim!=NULL);
69    
70      CONSOLE_DEBUG("Running on_load...");      CONSOLE_DEBUG("Running on_load...");
71    
72      symchar *onload = AddSymbol("on_load");      symchar *onload = AddSymbol("on_load");
73      enum Proc_enum pe;      enum Proc_enum pe;
74      pe = Initialize(sim,CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);      pe = Initialize(GetSimulationRoot(sim),CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);
75      CU_ASSERT_FATAL(pe == Proc_all_ok);      CU_ASSERT_FATAL(pe == Proc_all_ok);
76    
77        return sim;
78    }
79    
80    static void test_default1(void){
81    
82        struct Instance *sim = load_and_initialise("test/defaultall/test1.a4c", "test1");
83    
84      /* check for vars and rels */      /* check for vars and rels */
85      struct Instance *root = GetSimulationRoot(sim);      struct Instance *root = GetSimulationRoot(sim);
86      struct Instance *inst, *a, *b;      struct Instance *inst, *a, *b;
# Line 88  static void test_default1(void){ Line 95  static void test_default1(void){
95      double va = RealAtomValue(a);      double va = RealAtomValue(a);
96      double vb = RealAtomValue(b);      double vb = RealAtomValue(b);
97      CONSOLE_DEBUG("Value of 'a' = %f",va);      CONSOLE_DEBUG("Value of 'a' = %f",va);
98      CU_ASSERT(vb==4.);      CU_ASSERT(va==4.);
99      CONSOLE_DEBUG("Value of 'b' = %f",vb);      CONSOLE_DEBUG("Value of 'b' = %f",vb);
100      CU_ASSERT(vb==8.);      CU_ASSERT(vb==8.);
101    
# Line 102  static void test_default1(void){ Line 109  static void test_default1(void){
109    
110  static void test_default2(void){  static void test_default2(void){
111    
112      struct module_t *m;      struct Instance *sim = load_and_initialise("test/defaultall/test2.a4c", "test2");
     int status;  
   
     CONSOLE_DEBUG("Loading model...");  
   
     Asc_CompilerInit(1);  
     Asc_PutEnv(ASC_ENV_LIBRARY "=models");  
       
     /* load the file */  
     m = Asc_OpenModule("test/defaultall/test2.a4c",&status);  
     CU_ASSERT(status == 0);  
   
     /* parse it */  
     CU_ASSERT(0 == zz_parse());  
   
     /* find the model */      
     CU_ASSERT(FindType(AddSymbol("test2"))!=NULL);  
   
     /* instantiate it */  
     struct Instance *sim = SimsCreateInstance(AddSymbol("test2"), AddSymbol("sim1"), e_normal, NULL);  
     CU_ASSERT_FATAL(sim!=NULL);  
   
     CONSOLE_DEBUG("Running on_load...");  
   
     symchar *onload = AddSymbol("on_load");  
     enum Proc_enum pe;  
     pe = Initialize(sim,CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);  
     CU_ASSERT_FATAL(pe == Proc_all_ok);  
113    
114      /* check for vars and rels */      /* check for vars and rels */
115      struct Instance *root = GetSimulationRoot(sim);      struct Instance *root, *inst1, *inst2, *a, *b;
116      struct Instance *inst1, *inst2, *a, *b;      root = GetSimulationRoot(sim);
117    
118      CU_ASSERT_FATAL((inst1 = ChildByChar(root,AddSymbol("s2"))) && InstanceKind(inst1)==MODEL_INST);      CU_ASSERT_FATAL((inst1 = ChildByChar(root,AddSymbol("s2"))) && InstanceKind(inst1)==MODEL_INST);
119      CU_ASSERT_FATAL((inst2 = ChildByChar(inst1,AddSymbol("s1a"))) && InstanceKind(inst2)==MODEL_INST);      CU_ASSERT_FATAL((inst2 = ChildByChar(inst1,AddSymbol("s1a"))) && InstanceKind(inst2)==MODEL_INST);
# Line 146  static void test_default2(void){ Line 126  static void test_default2(void){
126      double va = RealAtomValue(a);      double va = RealAtomValue(a);
127      double vb = RealAtomValue(b);      double vb = RealAtomValue(b);
128      CONSOLE_DEBUG("Value of 'a' = %f",va);      CONSOLE_DEBUG("Value of 'a' = %f",va);
129      CU_ASSERT(vb==4.);      CU_ASSERT(va==4.);
130      CONSOLE_DEBUG("Value of 'b' = %f",vb);      CONSOLE_DEBUG("Value of 'b' = %f",vb);
131      CU_ASSERT(vb==8.);      CU_ASSERT(vb==8.);
132    

Legend:
Removed from v.2243  
changed lines
  Added in v.2244

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