1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
22 */
23
24namespace c_glib TTest
25
26enum MyEnum1 {
27  ME1_0 = 0,
28  ME1_1 = 1,
29  ME1_2,
30  ME1_3,
31  ME1_5 = 5,
32  ME1_6,
33}
34
35enum MyEnum2 {
36  ME2_0,
37  ME2_1,
38  ME2_2,
39}
40
41enum MyEnum2_again {
42  // enum value identifiers may appear again in another enum type
43  ME0_1,
44  ME1_1,
45  ME2_1,
46  ME3_1,
47}
48
49enum MyEnum3 {
50  ME3_0,
51  ME3_1,
52  ME3_N2 = -2,
53  ME3_N1,
54  ME3_D0,
55  ME3_D1,
56  ME3_9 = 9,
57  ME3_10,
58}
59
60enum MyEnum4 {
61  ME4_A = 0x7ffffffd
62  ME4_B
63  ME4_C
64  // attempting to define another enum value here fails
65  // with an overflow error, as we overflow values that can be
66  // represented with an i32.
67}
68
69enum MyEnum5 {
70  e1        // fails with 0.9.3 and earlier
71  e2 = 42   // fails with 0.9.3 and earlier
72}
73
74enum MyEnumWithCustomOstream {
75  custom1 = 1,
76  CustoM2
77} (cpp.customostream)
78
79struct MyStruct {
80  1: MyEnum2 me2_2 = MyEnum1.ME2_2
81  2: MyEnum3 me3_n2 = MyEnum3.ME3_N2
82  3: MyEnum3 me3_d1 = MyEnum3.ME3_D1
83}
84
85struct EnumTestStruct {
86  1: MyEnum3 a_enum;
87  2: list<MyEnum3> enum_list;
88  3: set<MyEnum3> enum_set;
89  4: map<MyEnum3, MyEnum3> enum_enum_map;
90  // collections as keys
91  44: map<list<MyEnum3> (python.immutable = ""), MyEnum3> list_enum_map;
92  45: map<set<MyEnum3> (python.immutable = ""), MyEnum3> set_enum_map;
93  46: map<map<MyEnum3,MyEnum3> (python.immutable = ""), MyEnum3> map_enum_map;
94  // collections as values
95  47: map<MyEnum3, map<MyEnum3, MyEnum3>> enum_map_map;
96  48: map<MyEnum3, set<MyEnum3>> enum_set_map;
97  49: map<MyEnum3, list<MyEnum3>> enum_list_map;
98}
99
100const EnumTestStruct ENUM_TEST = {
101  'a_enum': MyEnum3.ME3_D1,
102  'enum_list': [MyEnum3.ME3_D1, MyEnum3.ME3_0, MyEnum3.ME3_N2],
103  'enum_set': [MyEnum3.ME3_D1, MyEnum3.ME3_N1],
104  'enum_enum_map': {MyEnum3.ME3_D1: MyEnum3.ME3_0, MyEnum3.ME3_0: MyEnum3.ME3_D1},
105  'list_enum_map': {[MyEnum3.ME3_D1, MyEnum3.ME3_0]: MyEnum3.ME3_0, [MyEnum3.ME3_D1]: MyEnum3.ME3_0, [MyEnum3.ME3_0]: MyEnum3.ME3_D1},
106  'set_enum_map': {[MyEnum3.ME3_D1, MyEnum3.ME3_0]: MyEnum3.ME3_0, [MyEnum3.ME3_D1]: MyEnum3.ME3_0},
107  'map_enum_map': {{MyEnum3.ME3_N1: MyEnum3.ME3_10}: MyEnum3.ME3_1},
108  'enum_map_map': {MyEnum3.ME3_N1: {MyEnum3.ME3_D1: MyEnum3.ME3_D1}},
109  'enum_set_map': {MyEnum3.ME3_N2: [MyEnum3.ME3_D1, MyEnum3.ME3_N1], MyEnum3.ME3_10: [MyEnum3.ME3_D1, MyEnum3.ME3_N1]},
110  'enum_list_map': {MyEnum3.ME3_D1: [MyEnum3.ME3_10], MyEnum3.ME3_0: [MyEnum3.ME3_9, MyEnum3.ME3_10]},
111}
112
113service EnumTestService {
114  MyEnum3 testEnum(1: MyEnum3 enum1),
115  list<MyEnum3> testEnumList(1: list<MyEnum3> enum1),
116  set<MyEnum3> testEnumSet(1: set<MyEnum3> enum1),
117  map<MyEnum3, MyEnum3> testEnumMap(1: map<MyEnum3, MyEnum3> enum1),
118  EnumTestStruct testEnumStruct(1: EnumTestStruct enum1),
119}
120