/[ascend]/trunk/ascend/general/test/test_ospath.c
ViewVC logotype

Diff of /trunk/ascend/general/test/test_ospath.c

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

revision 939 by johnpye, Fri Nov 24 07:00:05 2006 UTC revision 998 by johnpye, Sat Dec 30 06:05:48 2006 UTC
# Line 25  Line 25 
25    
26  FilePathTestFn ospath_searchpath_testexists;  FilePathTestFn ospath_searchpath_testexists;
27    
28    #define NDEBUG
29    
30  #ifndef NDEBUG  #ifndef NDEBUG
31  # include <assert.h>  # include <assert.h>
32  # define M(MSG) fprintf(stderr,"%s:%d: (%s) %s\n",__FILE__,__LINE__,__FUNCTION__,MSG);fflush(stderr);fflush(stderr)  # define M(MSG) fprintf(stderr,"%s:%d: (%s) %s\n",__FILE__,__LINE__,__FUNCTION__,MSG);fflush(stderr);fflush(stderr)
# Line 47  FilePathTestFn ospath_searchpath_testexi Line 49  FilePathTestFn ospath_searchpath_testexi
49  # define MM(VAR) ((void)0)  # define MM(VAR) ((void)0)
50  #endif  #endif
51    
52    #ifndef MEMUSED
53    # define MEMUSED(N) CU_TEST(ascmeminuse()==(N))
54    #endif
55    
56  /**  /**
57      This is a sample searchpath test function. Assumes the 'userfdata' is a      This is a sample searchpath test function. Assumes the 'userdata' is a
58      relative FilePath which is appended to path, and then if it matches      relative FilePath which is appended to path, and then if it matches
59      the path \GTK\bin\johnpye\extfn, returns true. This is of      the path \GTK\bin\johnpye\extfn, returns true. This is of
60      course a fairly useless test function, so it's just for testing.      course a fairly useless test function, so it's just for testing.
# Line 76  int ospath_searchpath_testexists(struct Line 82  int ospath_searchpath_testexists(struct
82    
83      if(ospath_cmp(fp1,fp2)==0){      if(ospath_cmp(fp1,fp2)==0){
84          MC("32","MATCH");          MC("32","MATCH");
85            ospath_free(fp1);
86            ospath_free(fp2);
87          return 1;          return 1;
88      }      }
89      MC("31","NO MATCH");      MC("31","NO MATCH");
90        ospath_free(fp1);
91        ospath_free(fp2);
92      return 0;      return 0;
93  }  }
94    
# Line 89  int ospath_searchpath_testexists(struct Line 99  int ospath_searchpath_testexists(struct
99  #undef M  #undef M
100  #define M MM  #define M MM
101    
102  static void test_ospath(void){  static void test_ospath_getparent(void){
103        struct FilePath *fp1, *fp2, *fp3;
     struct FilePath *fp1, *fp2, *fp3, *fp4;  
     char *s1;  
     struct FilePath **pp, **p1;// will be returned null-terminated  
 #ifdef WINPATHS  
     char pathtext[]="c:\\Program Files\\GnuWin32\\bin;c:\\GTK\\bin;e:\\ascend\\;..\\..\\pygtk";  
     char pathtext2[]="c:\\Program Files\\ASCEND\\models";  
 #else  
     char pathtext[]="\\Program Files\\GnuWin32\\bin:\\GTK\\bin:\\ascend\\:..\\..\\pygtk";  
     char pathtext2[]="/usr/local/ascend/models";  
 #endif  
104    
105      //------------------------      //------------------------
106    
# Line 116  static void test_ospath(void){ Line 116  static void test_ospath(void){
116    
117      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3);      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3);
118    
119        MEMUSED(0);
120    }
121        //------------------------
122    
123    static void test_ospath_cleanup(void){
124        struct FilePath *fp1, *fp2;
125    
126        fp1 = ospath_new_from_posix("/usr/include/../local");
127        fp2 = ospath_new_from_posix("/usr/local");
128    
129        D(fp1);
130        D(fp2);
131        CU_TEST(ospath_cmp(fp1,fp2)==0);
132        M("Passed 'cleanup' test\n");
133    
134        ospath_free(fp1); ospath_free(fp2);
135        MEMUSED(0);
136    }
137      //------------------------      //------------------------
138    
139    static void test_ospath_newfromposix(void){
140    
141        struct FilePath *fp1, *fp2;
142    
143      fp1 = ospath_new_from_posix("models/johnpye/extfn/extfntest");      fp1 = ospath_new_from_posix("models/johnpye/extfn/extfntest");
144      D(fp1);      D(fp1);
145      fp2 = ospath_new("models\\johnpye\\extfn\\extfntest");      fp2 = ospath_new("models\\johnpye\\extfn\\extfntest");
# Line 128  static void test_ospath(void){ Line 150  static void test_ospath(void){
150    
151      ospath_free(fp1);      ospath_free(fp1);
152      ospath_free(fp2);      ospath_free(fp2);
153        MEMUSED(0);
154    }
155      //------------------------      //------------------------
156    
157    static void test_ospath_secondcleanup(void){
158        struct FilePath *fp1, *fp2, *fp3;
159      fp1 = ospath_new(".\\src/.\\images\\..\\\\movies\\");      fp1 = ospath_new(".\\src/.\\images\\..\\\\movies\\");
160      fp2 = ospath_new(".\\src\\movies");      fp2 = ospath_new(".\\src\\movies");
161    
# Line 150  static void test_ospath(void){ Line 176  static void test_ospath(void){
176      CU_TEST(ospath_cmp(fp1,fp3)==0);      CU_TEST(ospath_cmp(fp1,fp3)==0);
177      M("Passed 'second cleanup' test\n");      M("Passed 'second cleanup' test\n");
178    
179        ospath_free(fp1);
180        ospath_free(fp2);
181        ospath_free(fp3);
182        MEMUSED(0);
183    }
184      //------------------------      //------------------------
185    
186    static void test_ospath_append(void){
187    
188        struct FilePath *fp2, *fp3, *fp4;
189    
190      fp2 = ospath_new("\\home\\john");      fp2 = ospath_new("\\home\\john");
191      fp3 = ospath_new("where\\mojo");      fp3 = ospath_new("where\\mojo");
192    
# Line 170  static void test_ospath(void){ Line 205  static void test_ospath(void){
205    
206      ospath_free(fp3);      ospath_free(fp3);
207      ospath_free(fp2);      ospath_free(fp2);
208        ospath_free(fp4);
209        MEMUSED(0);
210    }
211      //---------------------------      //---------------------------
212    
213    static void test_ospath_appendupup(void){
214    
215        struct FilePath *fp2, *fp3, *fp4;
216    
217      fp3 = ospath_new_noclean("../..");      fp3 = ospath_new_noclean("../..");
218      D(fp3);      D(fp3);
219    
# Line 195  static void test_ospath(void){ Line 236  static void test_ospath(void){
236      ospath_free(fp2);      ospath_free(fp2);
237      ospath_free(fp3);      ospath_free(fp3);
238      ospath_free(fp4);      ospath_free(fp4);
239        MEMUSED(0);
240    }
241      //-------------------------      //-------------------------
242    
243    static void test_ospath_up(void){
244    
245        struct FilePath *fp1, *fp2;
246    
247      fp1 = ospath_new("~\\somewhere\\..");      fp1 = ospath_new("~\\somewhere\\..");
248      fp2 = ospath_new("~/.");      fp2 = ospath_new("~/.");
249    
# Line 219  static void test_ospath(void){ Line 265  static void test_ospath(void){
265    
266      ospath_free(fp1);      ospath_free(fp1);
267      ospath_free(fp2);      ospath_free(fp2);
268        MEMUSED(0);
269    }
270      //---------------------------      //---------------------------
271    
272    static void test_ospath_concat(void){
273    
274        struct FilePath *fp1, *fp2, *fp3, *fp4;
275    
276      fp1 = ospath_new("/home");      fp1 = ospath_new("/home");
277      fp2 = ospath_new("john");      fp2 = ospath_new("john");
278      fp3 = ospath_concat(fp1, fp2);      fp3 = ospath_concat(fp1, fp2);
# Line 233  static void test_ospath(void){ Line 284  static void test_ospath(void){
284    
285      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);
286    
     //---------------------------  
   
287      fp1 = ospath_new("c:/Program Files");      fp1 = ospath_new("c:/Program Files");
288      fp2 = ospath_new("GnuWin32\\bin");      fp2 = ospath_new("GnuWin32\\bin");
289      fp3 = ospath_concat(fp1, fp2);      fp3 = ospath_concat(fp1, fp2);
# Line 245  static void test_ospath(void){ Line 294  static void test_ospath(void){
294      M("Passed 'ospath_concat' test\n");      M("Passed 'ospath_concat' test\n");
295    
296      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);
297        MEMUSED(0);
298    }
299      //---------------------------      //---------------------------
300    
301    static void test_ospath_concatmixedslash(void){
302    
303        struct FilePath *fp1, *fp2, *fp3, *fp4;
304    
305      fp1 = ospath_new("c:/Program Files/");      fp1 = ospath_new("c:/Program Files/");
306      fp2 = ospath_new("GnuWin32\\bin");      fp2 = ospath_new("GnuWin32\\bin");
307      fp3 = ospath_concat(fp1, fp2);      fp3 = ospath_concat(fp1, fp2);
# Line 258  static void test_ospath(void){ Line 312  static void test_ospath(void){
312      M("Passed trailing-slash 'ospath_concat' test\n");      M("Passed trailing-slash 'ospath_concat' test\n");
313    
314      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);
315        MEMUSED(0);
316    }
317      //---------------------------      //---------------------------
318    
319    static void test_ospath_trailingslash(void){
320    
321        struct FilePath *fp1, *fp2, *fp3, *fp4;
322    
323      fp1 = ospath_new("c:/Program Files/GnuWin32/bin");      fp1 = ospath_new("c:/Program Files/GnuWin32/bin");
324      fp2 = ospath_new("johnpye/extfn");      fp2 = ospath_new("johnpye/extfn");
325      fp3 = ospath_concat(fp1, fp2);      fp3 = ospath_concat(fp1, fp2);
# Line 271  static void test_ospath(void){ Line 330  static void test_ospath(void){
330      M("Passed trailing-slash 'ospath_concat' test\n");      M("Passed trailing-slash 'ospath_concat' test\n");
331    
332      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);      ospath_free(fp1); ospath_free(fp2); ospath_free(fp3); ospath_free(fp4);
333        MEMUSED(0);
334    }
335      //---------------------------      //---------------------------
336    
337    static void test_ospath_searchpath(void){
338    
339        struct FilePath *fp1, *fp2, *fp3;
340        struct FilePath **pp, **p1;// will be returned null-terminated
341    #ifdef WINPATHS
342        char pathtext[]="c:\\Program Files\\GnuWin32\\bin;c:\\GTK\\bin;e:\\ascend\\;..\\..\\pygtk";
343    #else
344        char pathtext[]="\\Program Files\\GnuWin32\\bin:\\GTK\\bin:\\ascend\\:..\\..\\pygtk";
345    #endif
346    
347      pp = ospath_searchpath_new(pathtext);      pp = ospath_searchpath_new(pathtext);
348    
349      for(p1=pp; *p1!=NULL; ++p1){      for(p1=pp; *p1!=NULL; ++p1){
# Line 312  static void test_ospath(void){ Line 382  static void test_ospath(void){
382      ospath_free(fp1);      ospath_free(fp1);
383      ospath_free(fp2);      ospath_free(fp2);
384      ospath_searchpath_free(pp);      ospath_searchpath_free(pp);
385        MEMUSED(0);
386    }
387      //-------------------------------      //-------------------------------
388    
389    static void test_ospath_searchpath2(void){
390    
391        struct FilePath *fp2, *fp3;
392        struct FilePath **pp, **p1;// will be returned null-terminated
393    #ifdef WINPATHS
394        char pathtext2[]="c:\\Program Files\\ASCEND\\models";
395    #else
396        char pathtext2[]="/usr/local/ascend/models";
397    #endif
398    
399      M("Path-search test 2...");      M("Path-search test 2...");
400    
401      pp = ospath_searchpath_new(pathtext2);      pp = ospath_searchpath_new(pathtext2);
# Line 336  static void test_ospath(void){ Line 417  static void test_ospath(void){
417      ospath_free(fp2);      ospath_free(fp2);
418      ospath_free(fp3);      ospath_free(fp3);
419      ospath_searchpath_free(pp);      ospath_searchpath_free(pp);
420        MEMUSED(0);
421    }
422      //-------------------------------      //-------------------------------
423    
424    static void test_ospath_basefilename(void){
425    
426        struct FilePath *fp1;
427        char *s1;
428    
429      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest.a4c");      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest.a4c");
430      D(fp1);      D(fp1);
431      s1 = ospath_getbasefilename(fp1);      s1 = ospath_getbasefilename(fp1);
# Line 349  static void test_ospath(void){ Line 436  static void test_ospath(void){
436      ospath_free(fp1);      ospath_free(fp1);
437      FREE(s1);      FREE(s1);
438    
     //-------------------------------  
   
439      fp1 = ospath_new("extfntest.a4c");      fp1 = ospath_new("extfntest.a4c");
440      D(fp1);      D(fp1);
441      s1 = ospath_getbasefilename(fp1);      s1 = ospath_getbasefilename(fp1);
# Line 361  static void test_ospath(void){ Line 446  static void test_ospath(void){
446      ospath_free(fp1);      ospath_free(fp1);
447      FREE(s1);      FREE(s1);
448    
   
     //-------------------------------  
   
449      fp1 = ospath_new("/here/is/my/path.dir/");      fp1 = ospath_new("/here/is/my/path.dir/");
450      D(fp1);      D(fp1);
451      s1 = ospath_getbasefilename(fp1);      s1 = ospath_getbasefilename(fp1);
# Line 374  static void test_ospath(void){ Line 456  static void test_ospath(void){
456      ospath_free(fp1);      ospath_free(fp1);
457      if(s1)FREE(s1);      if(s1)FREE(s1);
458    
     //-------------------------------  
   
459  #ifdef WINPATHS  #ifdef WINPATHS
460      fp1 = ospath_new("c:extfntest.a4c");      fp1 = ospath_new("c:extfntest.a4c");
461      D(fp1);      D(fp1);
# Line 387  static void test_ospath(void){ Line 467  static void test_ospath(void){
467      ospath_free(fp1);      ospath_free(fp1);
468      FREE(s1);      FREE(s1);
469  #endif  #endif
470        MEMUSED(0);
471    }
472      //-------------------------------      //-------------------------------
473    
474    static void test_ospath_getfilestem(void){
475    
476        struct FilePath *fp1;
477        char *s1;
478    
479      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest.a4c");      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest.a4c");
480      D(fp1);      D(fp1);
481      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 400  static void test_ospath(void){ Line 486  static void test_ospath(void){
486      ospath_free(fp1);      ospath_free(fp1);
487      FREE(s1);      FREE(s1);
488    
     //-------------------------------  
   
489      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest");      fp1 = ospath_new("/usr/share/data/ascend/models/johnpye/extfn/extfntest");
490      D(fp1);      D(fp1);
491      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 412  static void test_ospath(void){ Line 496  static void test_ospath(void){
496      ospath_free(fp1);      ospath_free(fp1);
497      FREE(s1);      FREE(s1);
498    
     //-------------------------------  
   
499      fp1 = ospath_new("/usr/share/data/ascend/.ascend.ini");      fp1 = ospath_new("/usr/share/data/ascend/.ascend.ini");
500      D(fp1);      D(fp1);
501      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 424  static void test_ospath(void){ Line 506  static void test_ospath(void){
506      ospath_free(fp1);      ospath_free(fp1);
507      FREE(s1);      FREE(s1);
508    
     //-------------------------------  
   
509      fp1 = ospath_new("~/.vimrc");      fp1 = ospath_new("~/.vimrc");
510      D(fp1);      D(fp1);
511      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 436  static void test_ospath(void){ Line 516  static void test_ospath(void){
516      ospath_free(fp1);      ospath_free(fp1);
517      FREE(s1);      FREE(s1);
518    
     //-------------------------------  
   
519      fp1 = ospath_new("~/src/ascend-0.9.5-1.jdpipe.src.rpm");      fp1 = ospath_new("~/src/ascend-0.9.5-1.jdpipe.src.rpm");
520      D(fp1);      D(fp1);
521      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 448  static void test_ospath(void){ Line 526  static void test_ospath(void){
526      ospath_free(fp1);      ospath_free(fp1);
527      FREE(s1);      FREE(s1);
528    
     //-------------------------------  
   
529      fp1 = ospath_new("~/dir1/dir2/");      fp1 = ospath_new("~/dir1/dir2/");
530      D(fp1);      D(fp1);
531      s1 = ospath_getfilestem(fp1);      s1 = ospath_getfilestem(fp1);
# Line 459  static void test_ospath(void){ Line 535  static void test_ospath(void){
535    
536      ospath_free(fp1);      ospath_free(fp1);
537      if(s1)FREE(s1);      if(s1)FREE(s1);
538        MEMUSED(0);
539    }
540      //-------------------------------      //-------------------------------
541    
542    static void test_ospath_getbasefileext(void){
543    
544        struct FilePath *fp1;
545        char *s1;
546    
547      fp1 = ospath_new("~/src/ascend-0.9.5-1.jdpipe.src.rpm");      fp1 = ospath_new("~/src/ascend-0.9.5-1.jdpipe.src.rpm");
548      D(fp1);      D(fp1);
549      s1 = ospath_getfileext(fp1);      s1 = ospath_getfileext(fp1);
# Line 472  static void test_ospath(void){ Line 554  static void test_ospath(void){
554      ospath_free(fp1);      ospath_free(fp1);
555      FREE(s1);      FREE(s1);
556    
     //-------------------------------  
   
557      fp1 = ospath_new("~/.vimrc");      fp1 = ospath_new("~/.vimrc");
558      D(fp1);      D(fp1);
559      s1 = ospath_getfileext(fp1);      s1 = ospath_getfileext(fp1);
# Line 484  static void test_ospath(void){ Line 564  static void test_ospath(void){
564      ospath_free(fp1);      ospath_free(fp1);
565      if(s1)FREE(s1);      if(s1)FREE(s1);
566    
     //-------------------------------  
   
567      fp1 = ospath_new("./ascend4");      fp1 = ospath_new("./ascend4");
568      D(fp1);      D(fp1);
569      s1 = ospath_getfileext(fp1);      s1 = ospath_getfileext(fp1);
# Line 495  static void test_ospath(void){ Line 573  static void test_ospath(void){
573    
574      ospath_free(fp1);      ospath_free(fp1);
575      if(s1)FREE(s1);      if(s1)FREE(s1);
576        MEMUSED(0);
577    }
578      //-------------------------------      //-------------------------------
579    
580    static void test_ospath_getdir(void){
581    
582        struct FilePath *fp1, *fp2, *fp3;
583    
584      fp1 = ospath_new("/home/myfile");      fp1 = ospath_new("/home/myfile");
585      fp2 = ospath_getdir(fp1);      fp2 = ospath_getdir(fp1);
586      fp3 = ospath_new("/home");      fp3 = ospath_new("/home");
# Line 508  static void test_ospath(void){ Line 591  static void test_ospath(void){
591      ospath_free(fp2);      ospath_free(fp2);
592      ospath_free(fp3);      ospath_free(fp3);
593    
     //-------------------------------  
   
594      fp1 = ospath_new("/home/myfile.ext");      fp1 = ospath_new("/home/myfile.ext");
595      fp2 = ospath_getdir(fp1);      fp2 = ospath_getdir(fp1);
596      fp3 = ospath_new("/home");      fp3 = ospath_new("/home");
# Line 520  static void test_ospath(void){ Line 601  static void test_ospath(void){
601      ospath_free(fp2);      ospath_free(fp2);
602      ospath_free(fp3);      ospath_free(fp3);
603    
     //-------------------------------  
   
604      fp1 = ospath_new("/home/mydir/");      fp1 = ospath_new("/home/mydir/");
605      fp2 = ospath_getdir(fp1);      fp2 = ospath_getdir(fp1);
606      fp3 = ospath_new("/home/mydir");      fp3 = ospath_new("/home/mydir");
# Line 531  static void test_ospath(void){ Line 610  static void test_ospath(void){
610      ospath_free(fp1);      ospath_free(fp1);
611      ospath_free(fp2);      ospath_free(fp2);
612      ospath_free(fp3);      ospath_free(fp3);
613        MEMUSED(0);
     //---------------------------------  
     M("ALL TESTS PASSED");  
614  }  }
615    
616  /*===========================================================================*/  /*===========================================================================*/
617  /* Registration information */  /* Registration information */
618    
619    #define T(N) {#N, test_ospath_##N }
620  static CU_TestInfo ospath_test_list[] = {  static CU_TestInfo ospath_test_list[] = {
621    {"test_ospath", test_ospath},      T(getparent)
622    CU_TEST_INFO_NULL      ,T(cleanup)
623        ,T(newfromposix)
624        ,T(secondcleanup)
625        ,T(append)
626        ,T(appendupup)
627        ,T(up)
628        ,T(concat)
629        ,T(concatmixedslash)
630        ,T(trailingslash)
631        ,T(searchpath)
632        ,T(searchpath2)
633        ,T(basefilename)
634        ,T(getfilestem)
635        ,T(getbasefileext)
636        ,T(getdir)
637        ,CU_TEST_INFO_NULL
638  };  };
639    #undef T
640    
641  static CU_SuiteInfo suites[] = {  static CU_SuiteInfo suites[] = {
642    {"test_general_ospath", NULL, NULL, ospath_test_list},    {"test_general_ospath", NULL, NULL, ospath_test_list},

Legend:
Removed from v.939  
changed lines
  Added in v.998

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