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