/[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 2244 by jpye, Mon Aug 2 01:05:11 2010 UTC revision 2245 by jpye, Mon Aug 2 04:20:18 2010 UTC
# Line 42  Line 42 
42    
43  #include <test/assertimpl.h>  #include <test/assertimpl.h>
44    
45    static enum Proc_enum run_method(struct Instance *sim, const char *methodname){
46        CONSOLE_DEBUG("Running '%s'...",methodname);
47    
48        symchar *onload = AddSymbol(methodname);
49        enum Proc_enum pe;
50        pe = Initialize(GetSimulationRoot(sim),CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);
51        return pe;
52    }
53    
54  static struct Instance *load_and_initialise(const char *fname, const char *modelname){  static struct Instance *load_and_initialise(const char *fname, const char *modelname){
55    
# Line 67  static struct Instance *load_and_initial Line 75  static struct Instance *load_and_initial
75      struct Instance *sim = SimsCreateInstance(AddSymbol(modelname), AddSymbol("sim1"), e_normal, NULL);      struct Instance *sim = SimsCreateInstance(AddSymbol(modelname), AddSymbol("sim1"), e_normal, NULL);
76      CU_ASSERT_FATAL(sim!=NULL);      CU_ASSERT_FATAL(sim!=NULL);
77    
78      CONSOLE_DEBUG("Running on_load...");      CU_ASSERT_FATAL(Proc_all_ok == run_method(sim, "on_load"));
   
     symchar *onload = AddSymbol("on_load");  
     enum Proc_enum pe;  
     pe = Initialize(GetSimulationRoot(sim),CreateIdName(onload),SCP(onload), ASCERR, WP_STOPONERR, NULL, NULL);  
     CU_ASSERT_FATAL(pe == Proc_all_ok);  
79    
80      return sim;      return sim;
81  }  }
# Line 137  static void test_default2(void){ Line 140  static void test_default2(void){
140  }  }
141    
142    
143    static void test_default3(void){
144    
145        struct Instance *sim = load_and_initialise("test/defaultall/test3.a4c", "test3");
146    
147        /* check for vars and rels */
148        struct Instance *root, *inst1, *inst2, *a, *b, *c, *d;
149        root = GetSimulationRoot(sim);
150    
151        CU_ASSERT_FATAL((inst1 = ChildByChar(root,AddSymbol("s2"))) && InstanceKind(inst1)==MODEL_INST);
152        CU_ASSERT_FATAL((inst2 = ChildByChar(inst1,AddSymbol("s1a"))) && InstanceKind(inst2)==MODEL_INST);
153        CU_ASSERT_FATAL((a = ChildByChar(inst2,AddSymbol("a"))) && InstanceKind(a)==REAL_ATOM_INST);
154        CU_ASSERT_FATAL((b = ChildByChar(inst2,AddSymbol("b"))) && InstanceKind(b)==REAL_ATOM_INST);
155        CU_ASSERT_FATAL((c = ChildByChar(inst2,AddSymbol("c"))) && InstanceKind(c)==REAL_ATOM_INST);
156        CU_ASSERT_FATAL((d = ChildByChar(inst1,AddSymbol("d"))) && InstanceKind(d)==REAL_ATOM_INST);
157    
158        CONSOLE_DEBUG("Checking values...");
159    
160        CU_ASSERT(RealAtomValue(a)==4.);
161        CU_ASSERT(RealAtomValue(c)==3);
162        CU_ASSERT(RealAtomValue(b)==8.);
163        CU_ASSERT(RealAtomValue(d)==5);
164    
165        CONSOLE_DEBUG("Cleaning up...");
166        /* clean up */
167        sim_destroy(sim);
168        Asc_CompilerDestroy();
169    }
170    
171    
172    
173    static void test_default3b(void){
174    
175        struct Instance *sim = load_and_initialise("test/defaultall/test3.a4c", "test3");
176    
177        /* check for vars and rels */
178        struct Instance *root, *inst1, *inst2, *a, *b, *c, *d;
179    
180        root = GetSimulationRoot(sim);
181        CU_ASSERT_FATAL((inst1 = ChildByChar(root,AddSymbol("s2"))) && InstanceKind(inst1)==MODEL_INST);
182        CU_ASSERT_FATAL((inst2 = ChildByChar(inst1,AddSymbol("s1a"))) && InstanceKind(inst2)==MODEL_INST);
183        CU_ASSERT_FATAL((a = ChildByChar(inst2,AddSymbol("a"))) && InstanceKind(a)==REAL_ATOM_INST);
184        CU_ASSERT_FATAL((b = ChildByChar(inst2,AddSymbol("b"))) && InstanceKind(b)==REAL_ATOM_INST);
185        CU_ASSERT_FATAL((c = ChildByChar(inst2,AddSymbol("c"))) && InstanceKind(c)==REAL_ATOM_INST);
186        CU_ASSERT_FATAL((d = ChildByChar(inst1,AddSymbol("d"))) && InstanceKind(d)==REAL_ATOM_INST);
187    
188        CU_ASSERT_FATAL(Proc_all_ok == run_method(sim, "mess_up_values"));
189    
190        CU_ASSERT(RealAtomValue(a)==0.);
191        CU_ASSERT(RealAtomValue(b)==0.);
192        CU_ASSERT(RealAtomValue(c)==0.);
193        CU_ASSERT(RealAtomValue(d)==0.);
194    
195        CU_ASSERT_FATAL(Proc_all_ok == run_method(sim, "on_load"));
196    
197        CU_ASSERT(RealAtomValue(a)==4.);
198        CU_ASSERT(RealAtomValue(c)==3);
199        CU_ASSERT(RealAtomValue(b)==8.);
200        CU_ASSERT(RealAtomValue(d)==5);
201    
202        /* clean up */
203        sim_destroy(sim);
204        Asc_CompilerDestroy();
205    }
206    
207  /*===========================================================================*/  /*===========================================================================*/
208  /* Registration information */  /* Registration information */
209    
# Line 144  static void test_default2(void){ Line 211  static void test_default2(void){
211    
212  #define TESTS(T,X) \  #define TESTS(T,X) \
213      T(default1) \      T(default1) \
214      X T(default2)      X T(default2) \
215        X T(default3) \
216        X T(default3b)
217    
218  /* you shouldn't need to change the following */  /* you shouldn't need to change the following */
219    

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

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