1 module iface;
2 
3 public import std.stdio;
4 public import std.datetime;
5 public import std.format;
6 public import std.random;
7 public import drmi.mqtt;
8 public import vibe.core.core;
9 
10 static this()
11 {
12     import vibe.core.log;
13     setLogLevel(LogLevel.debugV);
14 }
15 
16 interface One
17 {
18     string getTime();
19     void printHello();
20     double magicmath(double, double);
21     int[] getArray(int);
22 }
23 
24 interface Two
25 {
26     int sum(int, int);
27 }
28 
29 interface Three
30 {
31     string foo(double);
32     int bar();
33 }
34 
35 void rndSleep() { sleep(uniform(1000, 3000).msecs); }
36 
37 static size_t failcount;
38 
39 void timeoutFail(string msg)
40 {
41     stderr.writeln(msg);
42     failcount++;
43     //exitEventLoop();
44 }
45 
46 void print(Args...)(Args args)
47 {
48     //stderr.writeln(args);
49 }
50 
51 void testGetTime(One one)
52 {
53     rndSleep();
54     try print(one.getTime());
55     catch (RMITimeoutException e) timeoutFail(e.msg);
56 }
57 
58 void testPrintHello(One one)
59 {
60     rndSleep();
61     try one.printHello();
62     catch (RMITimeoutException e) timeoutFail(e.msg);
63 }
64 
65 void testMagicmath(One one)
66 {
67     rndSleep();
68     auto r1 = uniform(5.0, 10.000001), r2 = uniform(1.0, 10.000001);
69     try print("(%s / %s) * %s = %s", r1, r2, r2, one.magicmath(r1, r2));
70     catch (RMITimeoutException e) timeoutFail(e.msg);
71 }
72 
73 void testGetArray(One one)
74 {
75     rndSleep();
76     auto cnt = uniform(1, 6);
77     try print("%(%s, %)", one.getArray(cnt));
78     catch (RMITimeoutException e) timeoutFail(e.msg);
79 }
80 
81 void testSum(Two two)
82 {
83     rndSleep();
84     auto r1 = uniform(-10, 11), r2 = uniform(-10, 11);
85     try print("%s + %s = %s", r1, r2, two.sum(r1, r2));
86     catch (RMITimeoutException e) timeoutFail(e.msg);
87 }
88 
89 void testFoo(Three three)
90 {
91     rndSleep();
92     auto r1 = uniform!"[]"(-1.0, 1.0);
93     try print("three.foo(%s) -> %s", r1, three.foo(r1));
94     catch (RMITimeoutException e) timeoutFail(e.msg);
95 }
96 
97 void testBar(Three three)
98 {
99     rndSleep();
100     try print("three.bar() -> %s", three.bar());
101     catch (RMITimeoutException e) timeoutFail(e.msg);
102 }