forked from KLab/makuo_php_ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
154 lines (126 loc) · 3.91 KB
/
test.php
File metadata and controls
154 lines (126 loc) · 3.91 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
define('PRINT_RESULT', false);
function TestStatus($makuo) {
echo "testing \$makuo->status()...\n";
//Array
//(
// [process] => 21995
// [version] => 1.2.1
// [basedir] => /home/kishimoto-k/makuo-test/base/
// [mfalloc] => 2
// [command] => 0
// [send op] => 0
// [recv op] => 0
//)
$res = $makuo->status();
if (PRINT_RESULT){ print_r($res); }
assert(is_array($res));
foreach (array("process", "version", "basedir",
"command", "send op", "recv op") as $key) {
assert(array_key_exists($key, $res));
}
}
function TestMembers($makuo) {
echo "testing \$makuo->members()...\n";
//Array
//(
// [0] => 10.10.2.27
//)
$res = $makuo->members();
if (PRINT_RESULT){ print_r($res); }
assert(is_array($res));
foreach ($res as $key => $value) {
assert(is_integer($key));
assert(substr_count($value, ".") == 3); // $value = x.x.x.x
}
}
function TestCheck($makuo) {
echo "testing \$makuo->check()...\n";
//Array
//(
// [0] => error: No such file or directory sag15:sag14.txt
// [1] => error: No such file or directory sag15:sag14-2.txt
//)
$res = $makuo->check();
if (PRINT_RESULT){ print_r($res); }
assert(is_array($res));
foreach ($res as $key => $value) {
assert(is_integer($key));
}
}
function TestSend($makuo) {
echo "testing \$makuo->send()...\n";
assert($makuo->send("", array("recursive" => true, "dryrun" => true, "delete" => true)));
assert(!$makuo->send("foo", array("recursive" => true, "dryrun" => true, "bar")));
assert($makuo->error === "error: No such file or directory foo\r\n");
// check robustness
//assert(!$makuo->send(1, 1));
$str = "A";
while (strlen($str) < 10000) { $str .= $str; }
assert($makuo->send($str) == false);
assert($makuo->error === "Too long parameter");
$str = "A";
while (strlen($str) < 1024) { $str .= $str; }
assert($makuo->send($str) == false);
assert($makuo->error === "Too long parameter");
}
function TestSync($makuo) {
echo "testing \$makuo->sync()...\n";
$makuo->sync("", array("recursive" => true, "dryrun" => true));
// check robustness
@$makuo->sync();
@$makuo->sync(1, array("recursive" => true, "dryrun" => true));
@$makuo->sync(42, 42);
}
function TestExclude($makuo) {
echo "testing \$makuo->exclude_*()...\n";
$l = $makuo->exclude_list();
assert(is_array($l));
assert(empty($l));
$makuo->exclude_add(array("a.txt"));
$l = $makuo->exclude_list();
assert(!empty($l));
assert(count($l) == 1);
assert($l[0] == 'a.txt');
$makuo->exclude_add(array("b.txt"));
$l = $makuo->exclude_list();
assert(count($l) == 2);
$makuo->exclude_del("a.txt");
$l = $makuo->exclude_list();
assert(count($l) == 1);
assert($l[0] == 'b.txt');
$arr = array();
for ($i = 0; $i < 10; ++$i) {
array_push($arr, "$i.txt");
}
$makuo->exclude_add($arr);
$l = $makuo->exclude_list();
assert(count($l) == 11);
$makuo->exclude_clear();
$l = $makuo->exclude_list();
assert(is_array($l));
assert(empty($l));
}
function RunAllTests() {
$makuo = new Makuosan(array("rcv_timeout" => 5));
if (!$makuo->connect_tcp("127.0.0.1", 5000, 1)) {
echo "could not connect.\n";
echo "ErrorMessage: " . $makuo->error . "\n";
return;
}
/* if (!$makuo->connect_unix("/Users/keisuke/klab/php-module/makuo.socket", 1)) { */
/* if (!$makuo->connect_unix("/home/kishimoto-k/makuo-test/makuosan.sock")) { */
/* echo "could not connect.\n"; */
/* echo "ErrorMessage: " . $makuo->error . "\n"; */
/* return; */
/* } */
TestStatus($makuo);
TestMembers($makuo);
TestCheck($makuo);
TestSend($makuo);
TestSync($makuo);
TestExclude($makuo);
$makuo->close();
}
RunAllTests();
?>