root/lang/objective-cplusplus/i3/trunk/src/mil/src/Test9.cpp @ 34612

Revision 34612, 6.6 kB (checked in by saturday06, 4 years ago)

asdfadfasdfadfaadfadfasdf

Line 
1#include <mil/PrecompiledHeaders.h>
2#include <mil/Mil.h>
3#include <mil/Atomic.h>
4#include <mil/Thread.h>
5#include <mil/GuiModule.h>
6#include <mil/Module.h>
7#include <quicktest/quicktest.h>
8
9#include "Test.h"
10
11using namespace mil;
12using namespace mil::Test;
13
14namespace Test9 {
15
16int global = 0;
17atomic<bool> spin;
18
19struct TinyEvent {
20};
21
22struct SmallEvent {
23    short data;
24};
25
26struct MiddleEvent {
27    char pad[20];
28    int data;
29};
30
31struct BigEvent {
32    char pad[500];
33    int data;
34};
35
36struct Foo : GuiModule<Foo> {
37    void createGui() {
38        this->setWindow(create_window());
39        while (spin.load()) {
40        }
41    }
42
43    void execute(SmallEvent& e) {
44        global += e.data;
45    }
46
47    void execute(BigEvent& e) {
48        global++;
49    }
50};
51
52struct Bar : GuiModule<Bar> {
53    Foo& foo;
54    Bar(Foo& foo): foo(foo) {
55    }
56    void run() {
57        this->setWindow(create_window());
58        while (spin.load()) {
59        }
60
61        for (int i = 0; i < 500; i++) {
62            SmallEvent e;
63            e.data = 5;
64            foo.post(e, *this);
65        }
66        this->loop();
67    }
68};
69
70struct Bar2 : GuiModule<Bar2> {
71    Foo& foo;
72    Bar2(Foo& foo): foo(foo) {
73    }
74    void run() {
75        this->setWindow(create_window());
76        while (spin.load()) {
77        }
78
79        for (int i = 0; i < 500; i++) {
80            BigEvent e2;
81            foo.post(e2, *this);
82        }
83        this->loop();
84    }
85};
86
87struct Bar3 : GuiModule<Bar3> {
88    Foo& foo;
89    Bar3(Foo& foo): foo(foo) {
90    }
91    void run() {
92        this->setWindow(create_window());
93        while (spin.load()) {
94        }
95
96        for (int i = 0; i < 500; i++) {
97            SmallEvent e;
98            e.data = 5;
99            foo.post(e, *this);
100
101            BigEvent e2;
102            foo.post(e2, *this);
103        }
104        this->loop();
105    }
106};
107
108struct Hoge : GuiModule<Hoge> {
109    void createGui() {
110        this->setWindow(create_window());
111        while (spin.load()) {}
112    }
113    void execute(TinyEvent& e) {
114        global++;
115    }
116    void execute(SmallEvent& e) {
117        global += e.data;
118    }
119    void execute(MiddleEvent& e) {
120        global += e.data;
121    }
122    void execute(BigEvent& e) {
123        global += e.data;
124    }
125};
126
127struct Hige : Module<Hige> {
128    void run() {
129        while (spin.load()) {}
130        this->loop();
131    }
132    void execute(TinyEvent& e) {
133        global += 2;
134    }
135    void execute(SmallEvent& e) {
136        global += e.data * 2;
137    }
138    void execute(MiddleEvent& e) {
139        global += e.data * 2;
140    }
141    void execute(BigEvent& e) {
142        global += e.data * 2;
143    }
144};
145
146template <class Receiver>
147struct Hage : GuiModule<Hage<Receiver> > {
148    Receiver& r;
149    Hage(Receiver& r) : r(r) {}
150    void run() {
151        this->setWindow(create_window());
152        while (spin.load()) {}
153
154        //for (int i = 0; i < 50; i++) {
155        //    TinyEvent t;
156        //    r.post(t, *this);
157        //}
158
159        //sleep(1);
160
161        for (int i = 0; i < 50; i++) {
162       
163            MiddleEvent m;
164            m.data = 2;
165            BigEvent b;
166            b.data = 4;
167            r.post(m, *this);
168            r.post(b, *this);
169            r.post(m, *this);
170            r.post(b, *this);
171        }
172        sleep(1);
173        this->loop();
174    }
175};
176
177template <class Receiver>
178struct Fuga : Module<Fuga<Receiver> > {
179    Receiver& r;
180    Fuga(Receiver& r) : r(r) {}
181    void run() {
182        while (spin.load()) {}
183
184        for (int i = 0; i < 50; i++) {
185            TinyEvent t;
186            r.post(t, *this);
187            SmallEvent s;
188            s.data = 8;
189            r.post(s, *this);
190            MiddleEvent m;
191            m.data = 16;
192            r.post(m, *this);
193            BigEvent b;
194            b.data = 32;
195            r.post(b, *this);
196        }
197
198        this->loop();
199    }
200};
201}
202
203using namespace Test9;
204
205QT_TEST(test_asdfadfaadfasdfadf) {
206    global = 0;
207
208    {
209        spin.store(true);
210        Hoge hoge;
211        Hage<Hoge> hage(hoge);
212        hoge.start();
213        hage.start();
214        sleep(1);
215        spin.store(false);
216        sleep(1);
217        QT_CHECK_EQUAL(global, 600);
218    }
219
220    {
221        spin.store(true);
222        Hoge hoge;
223        Fuga<Hoge> fuga(hoge);
224        hoge.start();
225        fuga.start();
226        sleep(1);
227        spin.store(false);
228        sleep(1);
229        QT_CHECK_EQUAL(global, 3450);
230    }
231
232    {
233        spin.store(true);
234        Hige hige;
235        Hage<Hige> hage(hige);
236        hige.start();
237        hage.start();
238        sleep(1);
239        spin.store(false);
240        sleep(1);
241        QT_CHECK_EQUAL(global, 4650);
242    }
243
244    {
245        spin.store(true);
246        Hige hige;
247        Fuga<Hige> fuga(hige);
248        hige.start();
249        fuga.start();
250        sleep(1);
251        spin.store(false);
252        sleep(1);
253        QT_CHECK_EQUAL(global, 10350);
254    }
255}
256
257/*
258
259QT_TEST(test_adifjadfioajdfaoidffgzg8) {
260    for (int i = 0; i < 5; i++) {
261        global = 0;
262        spin.store(true);
263
264        Foo foo;
265        Bar bar(foo);
266
267        foo.start();
268        bar.start();
269
270        sleep(1);
271        spin.store(false);
272        sleep(1);
273        QT_CHECK_EQUAL(global, 2500);
274    }
275}
276
277
278QT_TEST(test_dasfhsdfsadfoiaaaaaoioio) {
279    global = 0;
280    spin.store(true);
281
282    Foo foo;
283    Bar2 bar(foo);
284
285    foo.start();
286    bar.start();
287
288    sleep(1);
289    spin.store(false);
290    sleep(1);
291    QT_CHECK_EQUAL(global, 500);
292}
293
294QT_TEST(test_dasfhsdfsadfoiaaaaaoioioa89) {
295    {
296        global = 0;
297        spin.store(true);
298
299        Foo foo;
300        Bar bar(foo);
301
302        foo.start();
303        bar.start();
304
305        sleep(1);
306        spin.store(false);
307        sleep(1);
308        QT_CHECK_EQUAL(global, 2500);
309    }
310
311    {
312        global = 0;
313        spin.store(true);
314
315        Foo foo;
316        Bar2 bar(foo);
317
318        foo.start();
319        bar.start();
320
321        sleep(1);
322        spin.store(false);
323        sleep(1);
324        QT_CHECK_EQUAL(global, 500);
325    }
326
327    {
328        global = 0;
329        spin.store(true);
330
331        Foo foo;
332        Bar3 bar(foo);
333
334        foo.start();
335        bar.start();
336
337        sleep(1);
338        spin.store(false);
339        sleep(1);
340        QT_CHECK_EQUAL(global, 3000);
341    }
342}
343
344QT_TEST(test_das1223sadfoio) {
345    global = 0;
346    spin.store(false);
347
348    Foo foo;
349    Bar bar(foo);
350
351    bar.start();
352    sleep(1);
353    foo.start();
354    sleep(1);
355    QT_CHECK_EQUAL(global, 0);
356}
357
358*/
Note: See TracBrowser for help on using the browser.