/[ascend]/trunk/ascend/compiler/test/test_units.c
ViewVC logotype

Diff of /trunk/ascend/compiler/test/test_units.c

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

revision 3354 by jpye, Sun Apr 15 12:36:00 2018 UTC revision 3355 by jpye, Mon Apr 16 05:56:23 2018 UTC
# Line 122  static void test_test2(void){ Line 122  static void test_test2(void){
122      CU_TEST(NULL!=u);      CU_TEST(NULL!=u);
123      CU_TEST(0==pos);      CU_TEST(0==pos);
124    
125      u = FindOrDefineUnits("NNN/mmm", &pos, &errcode);  #define EXPECT_ERROR(USTR,ERRCODE) \
126      CU_TEST(1==errcode);      u = FindOrDefineUnits(USTR,&pos,&errcode);\
127      CU_TEST(NULL==u);      if(errcode && errcode!=ERRCODE){\
128            CONSOLE_DEBUG("Expected error code %d, got %d",ERRCODE,errcode);\
129      u = FindOrDefineUnits("N/(m", &pos, &errcode);          char **e1 = UnitsExplainError(USTR,pos,errcode);\
130      CU_TEST(2==errcode);          CONSOLE_DEBUG("error: %s",e1[1]);\
131      CU_TEST(NULL==u);          CONSOLE_DEBUG("-------%s  %s",e1[2],e1[0]);\
132        }\
133      u = FindOrDefineUnits("N-m", &pos, &errcode);      CU_TEST(ERRCODE==errcode);\
134      CU_TEST(3==errcode);      if(ERRCODE)CU_TEST(NULL==u) else CU_TEST(NULL!=u);
135      CU_TEST(NULL==u);  
136        EXPECT_ERROR("NNN/mmm",1);
137    
138        EXPECT_ERROR("N",0);
139        EXPECT_ERROR("N^2",0);
140        EXPECT_ERROR("N^-2",0);
141        EXPECT_ERROR("N/m",0);
142        EXPECT_ERROR("N/m/kg",0);
143        EXPECT_ERROR("N/m*kg",0);
144    
145        EXPECT_ERROR("N/(m",2);
146        EXPECT_ERROR("N-m",3);
147        EXPECT_ERROR("/m",8);
148        EXPECT_ERROR("N/m*kg/",7);
149    
150      u = FindOrDefineUnits("N", &pos, &errcode);      EXPECT_ERROR("N^1/2",0);
151      CU_TEST(0==errcode);      char *s1 = UnitsStringSI(u);
152      CU_TEST(NULL!=u);      CONSOLE_DEBUG("string = %s",s1);
153        ASC_FREE(s1);
     u = FindOrDefineUnits("N^2", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
   
     u = FindOrDefineUnits("N^-2", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
   
     u = FindOrDefineUnits("N/m", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
   
     u = FindOrDefineUnits("/m", &pos, &errcode);  
     CU_TEST(8==errcode);  
     CU_TEST(NULL==u);  
   
     u = FindOrDefineUnits("N/m/kg", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
154    
155      u = FindOrDefineUnits("N/m*kg", &pos, &errcode);      EXPECT_ERROR("3.5*m",0);
156      CU_TEST(0==errcode);      EXPECT_ERROR("3.5*m*",7);
     CU_TEST(NULL!=u);  
157    
158      u = FindOrDefineUnits("N/m*kg/", &pos, &errcode);      EXPECT_ERROR(".678e-2*m",0);
     CU_TEST(7==errcode);  
     CU_TEST(NULL==u);  
159    
160      u = FindOrDefineUnits("N^1/2", &pos, &errcode);      EXPECT_ERROR("XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
161      CU_TEST(0==errcode);  XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
162      CU_TEST(NULL!=u);  XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
163    XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
164    XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
165    YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
166    YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
167    YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
168    YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
169    YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\
170    ZaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa"
171            ,5);
172    
173      char *s1 = UnitsStringSI(u);      EXPECT_ERROR("3.6N",6);
     CONSOLE_DEBUG("string = %s",s1);  
     ASC_FREE(s1);  
174    
175  #if 0  #if 0
176      u = FindOrDefineUnits("kg^0.3", &pos, &errcode);      EXPECT_ERROR("N/m)",9);
177      CONSOLE_DEBUG("error code = %d, pos = %lu",errcode,pos);      EXPECT_ERROR("kg^0.3",0)
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
178    
179      u = FindOrDefineUnits("N^(3/10)", &pos, &errcode);      u = FindOrDefineUnits("N^(3/10)", &pos, &errcode);
180      CONSOLE_DEBUG("error code = %d, pos = %lu",errcode,pos);      CONSOLE_DEBUG("error code = %d, pos = %lu",errcode,pos);
# Line 196  static void test_test2(void){ Line 192  static void test_test2(void){
192      CU_TEST(NULL!=u);      CU_TEST(NULL!=u);
193  #endif  #endif
194    
     u = FindOrDefineUnits("3.5*m", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
   
     u = FindOrDefineUnits("3.5*m*", &pos, &errcode);  
     CU_TEST(7==errcode);  
     CU_TEST(NULL==u);  
   
     u = FindOrDefineUnits(".678e-2*m", &pos, &errcode);  
     CU_TEST(0==errcode);  
     CU_TEST(NULL!=u);  
   
     u = FindOrDefineUnits("XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 XaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 YaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa\  
 ZaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaaAaaaabaaaa"  
         ,&pos, &errcode);  
     //CONSOLE_DEBUG("error code = %d",errcode);  
     CU_TEST(5==errcode);  
     CU_TEST(NULL==u);  
   
     u = FindOrDefineUnits("3.6N", &pos, &errcode);  
     //CONSOLE_DEBUG("error code = %d",errcode);  
     CU_TEST(6==errcode);  
     CU_TEST(NULL==u);  
   
195  #if 0  #if 0
196      u = FindOrDefineUnits("3.5e9e0*m", &pos, &errcode);      u = FindOrDefineUnits("3.5e9e0*m", &pos, &errcode);
197      CONSOLE_DEBUG("error code = %d",errcode);      CONSOLE_DEBUG("error code = %d",errcode);

Legend:
Removed from v.3354  
changed lines
  Added in v.3355

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