| 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 |
|
|---|
| 11 | using namespace mil;
|
|---|
| 12 | using namespace mil::Test;
|
|---|
| 13 |
|
|---|
| 14 | namespace Test9 {
|
|---|
| 15 |
|
|---|
| 16 | int global = 0;
|
|---|
| 17 | atomic<bool> spin;
|
|---|
| 18 |
|
|---|
| 19 | struct TinyEvent {
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | struct SmallEvent {
|
|---|
| 23 | short data;
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | struct MiddleEvent {
|
|---|
| 27 | char pad[20];
|
|---|
| 28 | int data;
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | struct BigEvent {
|
|---|
| 32 | char pad[500];
|
|---|
| 33 | int data;
|
|---|
| 34 | };
|
|---|
| 35 |
|
|---|
| 36 | struct 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 |
|
|---|
| 52 | struct 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 < 50000; i++) {
|
|---|
| 62 | SmallEvent e;
|
|---|
| 63 | e.data = 5;
|
|---|
| 64 | foo.post(e, *this);
|
|---|
| 65 | }
|
|---|
| 66 | this->loop();
|
|---|
| 67 | }
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | struct 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 |
|
|---|
| 87 | struct 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 |
|
|---|
| 108 | struct 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 |
|
|---|
| 127 | struct 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 |
|
|---|
| 146 | template <class Receiver>
|
|---|
| 147 | struct 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 |
|
|---|
| 177 | template <class Receiver>
|
|---|
| 178 | struct 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 |
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | using namespace Test9;
|
|---|
| 206 |
|
|---|
| 207 | QT_TEST(test_asdfadfaadfasdfadf) {
|
|---|
| 208 | global = 0;
|
|---|
| 209 |
|
|---|
| 210 | {
|
|---|
| 211 | spin.store(true);
|
|---|
| 212 | Hoge hoge;
|
|---|
| 213 | Hage<Hoge> hage(hoge);
|
|---|
| 214 | hoge.start();
|
|---|
| 215 | hage.start();
|
|---|
| 216 | sleep(1);
|
|---|
| 217 | spin.store(false);
|
|---|
| 218 | sleep(1);
|
|---|
| 219 | QT_CHECK_EQUAL(global, 600);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | {
|
|---|
| 223 | spin.store(true);
|
|---|
| 224 | Hoge hoge;
|
|---|
| 225 | Fuga<Hoge> fuga(hoge);
|
|---|
| 226 | hoge.start();
|
|---|
| 227 | fuga.start();
|
|---|
| 228 | sleep(1);
|
|---|
| 229 | spin.store(false);
|
|---|
| 230 | sleep(1);
|
|---|
| 231 | QT_CHECK_EQUAL(global, 3450);
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | {
|
|---|
| 235 | spin.store(true);
|
|---|
| 236 | Hige hige;
|
|---|
| 237 | Hage<Hige> hage(hige);
|
|---|
| 238 | hige.start();
|
|---|
| 239 | hage.start();
|
|---|
| 240 | sleep(1);
|
|---|
| 241 | spin.store(false);
|
|---|
| 242 | sleep(1);
|
|---|
| 243 | QT_CHECK_EQUAL(global, 4650);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | {
|
|---|
| 247 | spin.store(true);
|
|---|
| 248 | Hige hige;
|
|---|
| 249 | Fuga<Hige> fuga(hige);
|
|---|
| 250 | hige.start();
|
|---|
| 251 | fuga.start();
|
|---|
| 252 | sleep(1);
|
|---|
| 253 | spin.store(false);
|
|---|
| 254 | sleep(1);
|
|---|
| 255 | QT_CHECK_EQUAL(global, 10350);
|
|---|
| 256 | }
|
|---|
| 257 | }
|
|---|
| 258 | QT_TEST(test_adifjadfioajdfaoidffgzg8) {
|
|---|
| 259 | for (int i = 0; i < 5; i++) {
|
|---|
| 260 | global = 0;
|
|---|
| 261 | spin.store(true);
|
|---|
| 262 |
|
|---|
| 263 | Foo foo;
|
|---|
| 264 | Bar bar(foo);
|
|---|
| 265 |
|
|---|
| 266 | foo.start();
|
|---|
| 267 | bar.start();
|
|---|
| 268 |
|
|---|
| 269 | sleep(1);
|
|---|
| 270 | spin.store(false);
|
|---|
| 271 | sleep(1);
|
|---|
| 272 | QT_CHECK_EQUAL(global, 2500);
|
|---|
| 273 | }
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 | QT_TEST(test_dasfhsdfsadfoiaaaaaoioio) {
|
|---|
| 278 | global = 0;
|
|---|
| 279 | spin.store(true);
|
|---|
| 280 |
|
|---|
| 281 | Foo foo;
|
|---|
| 282 | Bar2 bar(foo);
|
|---|
| 283 |
|
|---|
| 284 | foo.start();
|
|---|
| 285 | bar.start();
|
|---|
| 286 |
|
|---|
| 287 | sleep(1);
|
|---|
| 288 | spin.store(false);
|
|---|
| 289 | sleep(1);
|
|---|
| 290 | QT_CHECK_EQUAL(global, 500);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | QT_TEST(test_dasfhsdfsadfoiaaaaaoioioa89) {
|
|---|
| 294 | {
|
|---|
| 295 | global = 0;
|
|---|
| 296 | spin.store(true);
|
|---|
| 297 |
|
|---|
| 298 | Foo foo;
|
|---|
| 299 | Bar bar(foo);
|
|---|
| 300 |
|
|---|
| 301 | foo.start();
|
|---|
| 302 | bar.start();
|
|---|
| 303 |
|
|---|
| 304 | sleep(1);
|
|---|
| 305 | spin.store(false);
|
|---|
| 306 | sleep(1);
|
|---|
| 307 | QT_CHECK_EQUAL(global, 2500);
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | {
|
|---|
| 311 | global = 0;
|
|---|
| 312 | spin.store(true);
|
|---|
| 313 |
|
|---|
| 314 | Foo foo;
|
|---|
| 315 | Bar2 bar(foo);
|
|---|
| 316 |
|
|---|
| 317 | foo.start();
|
|---|
| 318 | bar.start();
|
|---|
| 319 |
|
|---|
| 320 | sleep(1);
|
|---|
| 321 | spin.store(false);
|
|---|
| 322 | sleep(1);
|
|---|
| 323 | QT_CHECK_EQUAL(global, 500);
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | {
|
|---|
| 327 | global = 0;
|
|---|
| 328 | spin.store(true);
|
|---|
| 329 |
|
|---|
| 330 | Foo foo;
|
|---|
| 331 | Bar3 bar(foo);
|
|---|
| 332 |
|
|---|
| 333 | foo.start();
|
|---|
| 334 | bar.start();
|
|---|
| 335 |
|
|---|
| 336 | sleep(1);
|
|---|
| 337 | spin.store(false);
|
|---|
| 338 | sleep(1);
|
|---|
| 339 | QT_CHECK_EQUAL(global, 3000);
|
|---|
| 340 | }
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | QT_TEST(test_das1223sadfoio) {
|
|---|
| 344 | global = 0;
|
|---|
| 345 | spin.store(false);
|
|---|
| 346 |
|
|---|
| 347 | Foo foo;
|
|---|
| 348 | Bar bar(foo);
|
|---|
| 349 |
|
|---|
| 350 | bar.start();
|
|---|
| 351 | sleep(1);
|
|---|
| 352 | foo.start();
|
|---|
| 353 | sleep(1);
|
|---|
| 354 | QT_CHECK_EQUAL(global, 0);
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|