4a649aeeecda60abf7960a0d24909e94be6cd030
[curl-de-sac.git] / webtest / cds_test01.php
1 #!/usr/bin/php
2 <?php
3
4 define('WEBURL', 'http://localhost/curl-de-sac');
5
6 require_once('Obj/curl-de-sac.phh');
7
8 class short_cmd extends CDS_cmd {
9     var $short_data;
10
11     function short_cmd($cmd_cls, $ch, $short_data)
12     {
13         parent::__construct($cmd_cls, $ch);
14         $this->short_data = $short_data;
15     }
16 }
17
18 class short_cmd_cls extends CDS_cmd_cls {
19     function short_cmd_cls()
20     {
21         parent::__construct("short", 10);
22     }
23
24     function create($cds, $url)
25     {
26         printf("short::create url:[%s]\n", $url);
27         
28         do {
29             if (($ch = parent::pre_create($url)) == FALSE)
30                 break;
31
32             if (parent::create($cds, $ch) == FALSE)
33                 break;
34
35             $cmd = new short_cmd($ch, $this, "none currently");
36
37             return $cmd;
38         } while (FALSE);
39         
40         return FALSE;
41     }
42
43     function cb()
44     {
45         printf("short_cb:\n");
46     }
47 }
48
49 class long_cmd extends CDS_cmd {
50     var $long_data;
51
52     function long_cmd($cmd_cls, $ch, $long_data)
53     {
54         parent::__construct($cmd_cls, $ch);
55         $this->long_data = $long_data;
56     }
57 }
58
59 class long_cmd_cls extends CDS_cmd_cls {
60     function long_cmd_cls()
61     {
62         parent::__construct("long", 10);
63     }
64
65     function create($cds, $url)
66     {
67         printf("long::create url:[%s]\n", $url);
68         
69         do {
70             if (($ch = parent::pre_create($url)) == FALSE)
71                 break;
72
73             if (parent::create($cds, $ch) == FALSE)
74                 break;
75
76             $cmd = new long_cmd($ch, $this, "none currently");
77
78             return $cmd;
79         } while (FALSE);
80         
81         return FALSE;
82     }
83
84     function cb()
85     {
86         printf("long_cb:\n");
87     }
88 }
89
90
91 function main()
92 {
93     // create cds
94     $cds = new Curl_de_sac(999);
95
96     // create cds_cmd 1
97     $cmd_cls1 = new short_cmd_cls();
98
99     // registrer cds_cmd 1
100     printf("Register CLS1\n");
101     if (($cds->cmd_register($cmd_cls1)) == FALSE) {
102         fprintf(STDERR, "cmd_cls1 registration failed\n");
103         exit(1);
104     }
105
106     // create cds_cmd 2
107     $cmd_cls2 = new long_cmd_cls();
108
109     // register cds_cmd 2
110     printf("Register CLS2\n");
111     if (($cds->cmd_register($cmd_cls2)) == FALSE) {
112         fprintf(STDERR, "cmd_cls2 registration failed\n");
113         exit(2);
114     }
115
116     // register cds_cmd 2 (retry)
117     printf("Re-register CLS2 (must go wrong)\n");
118     if (($cds->cmd_register($cmd_cls2)) != FALSE) {
119         fprintf(STDERR, "cmd_cls2 re-registration success\n");
120         exit(3);
121     }
122
123     print_r($cds);
124     printf("Deregister CLS2\n");
125     if (($cds->cmd_deregister($cmd_cls2)) == FALSE) {
126         fprintf(STDERR, "cmd_cls2 deregistration failed\n");
127         exit(4);
128     }
129     print_r($cds);
130
131     // re-re-register cds_cmd 2
132     printf("Re-re-register CLS2\n");
133     if (($cds->cmd_register($cmd_cls2)) == FALSE) {
134         fprintf(STDERR, "cmd_cls2 re-re-registration failed\n");
135         exit(5);
136     }
137
138     printf("Deregister all\n");
139     $cds->cmd_deregister_all();
140
141     // registrer cds_cmd 1
142     printf("Register CLS1\n");
143     if (($cds->cmd_register($cmd_cls1)) == FALSE) {
144         fprintf(STDERR, "cmd_cls1 registration failed\n");
145         exit(1);
146     }
147
148     // register cds_cmd 2
149     printf("Register CLS2\n");
150     if (($cds->cmd_register($cmd_cls2)) == FALSE) {
151         fprintf(STDERR, "cmd_cls2 registration failed\n");
152         exit(2);
153     }
154     print_r($cds);
155     printf("SUCCESS\n");
156
157     for ($i = 0 ; $i < 10 ; $i++) {
158         if ($i == 2) {
159             print("load short\n");
160             if ($cds->execute("short", WEBURL.'/short.php') == FALSE) {
161                 printf("push command failed\n");
162                 exit(123);
163             }
164         }
165         printf("Call process\n");
166         $cds->process();
167         sleep(1);
168     }
169     // start loop
170     //   print status
171     //   if input data execute some command
172     //   if end => clean exit
173     exit(0);
174 }
175
176 main();
177
178 ?>