1 module thrift_test_common;
2 
3 import std.stdio;
4 import thrift.test.ThriftTest_types;
5 
6 enum ProtocolType {
7   binary,
8   compact,
9   json
10 }
11 
writeInsanityReturn(in Insanity[Numberz][UserId]insane)12 void writeInsanityReturn(in Insanity[Numberz][UserId] insane) {
13   write("{");
14   foreach(key1, value1; insane) {
15     writef("%s => {", key1);
16     foreach(key2, value2; value1) {
17       writef("%s => {", key2);
18       write("{");
19       foreach(key3, value3; value2.userMap) {
20         writef("%s => %s, ", key3, value3);
21       }
22       write("}, ");
23 
24       write("{");
25       foreach (x; value2.xtructs) {
26         writef("{\"%s\", %s, %s, %s}, ",
27           x.string_thing, x.byte_thing, x.i32_thing, x.i64_thing);
28       }
29       write("}");
30 
31       write("}, ");
32     }
33     write("}, ");
34   }
35   write("}");
36 }
37 
38 Insanity[Numberz][UserId] testInsanityReturn;
39 int[int][int] testMapMapReturn;
40 
this()41 static this() {
42   testInsanityReturn = {
43     Insanity[Numberz][UserId] insane;
44 
45     Xtruct hello;
46     hello.string_thing = "Hello2";
47     hello.byte_thing = 2;
48     hello.i32_thing = 2;
49     hello.i64_thing = 2;
50 
51     Xtruct goodbye;
52     goodbye.string_thing = "Goodbye4";
53     goodbye.byte_thing = 4;
54     goodbye.i32_thing = 4;
55     goodbye.i64_thing = 4;
56 
57     Insanity crazy;
58     crazy.userMap[Numberz.EIGHT] = 8;
59     crazy.xtructs ~= goodbye;
60 
61     Insanity looney;
62     // The C++ TestServer also assigns these to crazy, but that is probably
63     // an oversight.
64     looney.userMap[Numberz.FIVE] = 5;
65     looney.xtructs ~= hello;
66 
67     Insanity[Numberz] first_map;
68     first_map[Numberz.TWO] = crazy;
69     first_map[Numberz.THREE] = crazy;
70     insane[1] = first_map;
71 
72     Insanity[Numberz] second_map;
73     second_map[Numberz.SIX] = looney;
74     insane[2] = second_map;
75     return insane;
76   }();
77 
78   testMapMapReturn = {
79     int[int] pos;
80     int[int] neg;
81 
82     for (int i = 1; i < 5; i++) {
83       pos[i] = i;
84       neg[-i] = -i;
85     }
86 
87     int[int][int] result;
88     result[4] = pos;
89     result[-4] = neg;
90     return result;
91   }();
92 }
93