libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

dirname_test.c (2398B)


      1 #include <cwalk.h>
      2 #include <memory.h>
      3 #include <stdlib.h>
      4 
      5 int dirname_relative(void)
      6 {
      7   const char *path;
      8   size_t length;
      9 
     10   cwk_path_set_style(CWK_STYLE_UNIX);
     11   path = "../one/two.txt";
     12   cwk_path_get_dirname(path, &length);
     13 
     14   if (length != 7) {
     15     return EXIT_FAILURE;
     16   }
     17 
     18   return EXIT_SUCCESS;
     19 }
     20 
     21 int dirname_three_segments(void)
     22 {
     23   const char *path;
     24   size_t length;
     25 
     26   cwk_path_set_style(CWK_STYLE_UNIX);
     27   path = "/one/two/three.txt";
     28   cwk_path_get_dirname(path, &length);
     29 
     30   if (length != 9) {
     31     return EXIT_FAILURE;
     32   }
     33 
     34   return EXIT_SUCCESS;
     35 }
     36 
     37 int dirname_root(void)
     38 {
     39   const char *path;
     40   size_t length;
     41 
     42   cwk_path_set_style(CWK_STYLE_UNIX);
     43   path = "/";
     44   cwk_path_get_dirname(path, &length);
     45 
     46   if (length != 0) {
     47     return EXIT_FAILURE;
     48   }
     49 
     50   return EXIT_SUCCESS;
     51 }
     52 
     53 int dirname_special_directories(void)
     54 {
     55   const char *path;
     56   size_t length;
     57 
     58   cwk_path_set_style(CWK_STYLE_UNIX);
     59   path = "..";
     60   cwk_path_get_dirname(path, &length);
     61 
     62   if (length != 0) {
     63     return EXIT_FAILURE;
     64   }
     65 
     66   path = ".";
     67   cwk_path_get_dirname(path, &length);
     68 
     69   if (length != 0) {
     70     return EXIT_FAILURE;
     71   }
     72 
     73   return EXIT_SUCCESS;
     74 }
     75 
     76 int dirname_no_separators(void)
     77 {
     78   const char *path;
     79   size_t length;
     80 
     81   cwk_path_set_style(CWK_STYLE_UNIX);
     82   path = "file_name";
     83   cwk_path_get_dirname(path, &length);
     84 
     85   if (length != 0) {
     86     return EXIT_FAILURE;
     87   }
     88 
     89   return EXIT_SUCCESS;
     90 }
     91 
     92 int dirname_trailing_separators(void)
     93 {
     94   const char *path;
     95   size_t length;
     96 
     97   cwk_path_set_style(CWK_STYLE_UNIX);
     98   path = "/my/path.txt////";
     99   cwk_path_get_dirname(path, &length);
    100 
    101   if (length != 4) {
    102     return EXIT_FAILURE;
    103   }
    104 
    105   return EXIT_SUCCESS;
    106 }
    107 
    108 int dirname_trailing_separator(void)
    109 {
    110   const char *path;
    111   size_t length;
    112 
    113   cwk_path_set_style(CWK_STYLE_UNIX);
    114   path = "/my/path.txt/";
    115   cwk_path_get_dirname(path, &length);
    116 
    117   if (length != 4) {
    118     return EXIT_FAILURE;
    119   }
    120 
    121   return EXIT_SUCCESS;
    122 }
    123 
    124 int dirname_empty(void)
    125 {
    126   const char *path;
    127   size_t length;
    128 
    129   cwk_path_set_style(CWK_STYLE_UNIX);
    130   path = "";
    131   cwk_path_get_dirname(path, &length);
    132 
    133   if (length != 0) {
    134     return EXIT_FAILURE;
    135   }
    136 
    137   return EXIT_SUCCESS;
    138 }
    139 
    140 int dirname_simple(void)
    141 {
    142   const char *path;
    143   size_t length;
    144 
    145   cwk_path_set_style(CWK_STYLE_UNIX);
    146   path = "/my/path.txt";
    147   cwk_path_get_dirname(path, &length);
    148 
    149   if (length != 4) {
    150     return EXIT_FAILURE;
    151   }
    152 
    153   return EXIT_SUCCESS;
    154 }