1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
inherit "../pike_test_common"; 
 
#include <testsuite.h> 
 
import TEST.http.WebDAV; 
 
#ifdef DAV_DEBUG 
#define DAV_WERROR(X...)    werror(X) 
#else /* !DAV_DEBUG */ 
#define DAV_WERROR(X...) 
#endif /* DAV_DEBUG */ 
 
private string filesystem_dir = "$VARDIR/testsuite/webdav"; 
// Expanded filesystem_dir. 
private string webdav_mount_point = "webdav/"; 
private string username = "test"; 
private string password = "test"; 
 
void run_tests(Configuration conf) 
{ 
  array(Standards.URI) base_uris = TestUtils.get_test_urls(conf, 
                                                 webdav_mount_point, 
                                                 username, 
                                                 password); 
  int count = 0; 
  foreach (base_uris, Standards.URI base_uri) { 
    DAV_WERROR("Webdav testsuite: Base URI: %s\n", (string)base_uri); 
    mapping(string:string) base_headers = ([ 
      "host": base_uri->host, 
      "user-agent": "Roxen WebDAV Tester", 
      "connection": "keep-alive", 
    ]); 
    WebdavTest testsuite = 
      WebdavTest(webdav_mount_point, base_uri, base_headers, "testdir"+count++); 
    testsuite->run(); 
    // Hack for counting number of tests. 
    ::current_test += testsuite->current_test; 
    ::tests_failed += testsuite->tests_failed; 
  } 
} 
 
 
private class WebdavTest { 
 
  inherit TestBase; 
 
  private string real_dir = roxen_path(filesystem_dir); 
 
  protected void create(string webdav_mount_point, 
                        Standards.URI base_uri, 
                        mapping(string:string) base_headers, 
                        string testdir) 
  { 
    ::create(webdav_mount_point, base_uri, base_headers, testdir); 
    DAV_WERROR("Webdav real_dir: %O\n", real_dir); 
    Stdio.mkdirhier(real_dir); 
  } 
 
  protected int filesystem_check_exists(string path) 
  { 
    path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
    string real_path = Stdio.append_path(real_dir, path); 
    return Stdio.exist(real_path); 
  } 
 
  protected string filesystem_read_file(string path) 
  { 
    path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
    string real_path = Stdio.append_path(real_dir, path); 
    return Stdio.read_bytes(real_path); 
  } 
 
  protected array(string) filesystem_get_dir(string path) 
  { 
    path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
    string real_path = Stdio.append_path(real_dir, path); 
    return get_dir(real_path); 
  } 
 
  protected int filesystem_is_dir(string path) 
  { 
    path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
    string real_path = Stdio.append_path(real_dir, path); 
    return Stdio.is_dir(real_path); 
  } 
 
  protected int filesystem_is_file(string path) 
  { 
    path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
    string real_path = Stdio.append_path(real_dir, path); 
    return Stdio.is_file(real_path); 
  } 
 
  protected int(0..1) filesystem_mkdir_recursive(string(8bit) path) 
  { 
    string real_path = Stdio.append_path (real_dir, path); 
    return Stdio.mkdirhier(real_path); 
  } 
 
  //! Writes a file to @[path], which is used verbatim without any normalization. 
  protected int(0..) filesystem_direct_write(string(8bit) path, 
                                             string(8bit) data) 
  { 
    string real_path = Stdio.append_path (real_dir, path); 
    return Stdio.write_file(real_path, data); 
  } 
 
  // protected int filesystem_recursive_rm(string path) 
  // { 
  //   path = string_to_utf8(Unicode.normalize(utf8_to_string(path), "NFC")); 
  //   string real_path = Stdio.append_path(real_dir, path); 
  //   return Stdio.recursive_rm(real_path); 
  // } 
 
}