Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 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 | |
Nobuaki Sukegawa | ba3fe86 | 2015-12-01 22:42:55 +0900 | [diff] [blame] | 24 | namespace c_glib TTest |
| 25 | |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 26 | enum MyEnum1 { |
| 27 | ME1_0 = 0, |
| 28 | ME1_1 = 1, |
| 29 | ME1_2, |
| 30 | ME1_3, |
| 31 | ME1_5 = 5, |
| 32 | ME1_6, |
| 33 | } |
| 34 | |
| 35 | enum MyEnum2 { |
| 36 | ME2_0, |
| 37 | ME2_1, |
| 38 | ME2_2, |
| 39 | } |
| 40 | |
Jens Geyer | 86b309c | 2014-09-11 23:54:35 +0200 | [diff] [blame] | 41 | enum 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 | |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 49 | enum 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 | |
| 60 | enum 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 | |
Jens Geyer | 5eed3a1 | 2015-12-08 01:32:12 +0100 | [diff] [blame] | 69 | enum MyEnum5 { |
| 70 | e1 // fails with 0.9.3 and earlier |
| 71 | e2 = 42 // fails with 0.9.3 and earlier |
| 72 | } |
| 73 | |
Jens Geyer | ae0b22c | 2014-09-04 23:04:21 +0200 | [diff] [blame] | 74 | struct MyStruct { |
| 75 | 1: MyEnum2 me2_2 = MyEnum1.ME2_2 |
| 76 | 2: MyEnum3 me3_n2 = MyEnum3.ME3_N2 |
| 77 | 3: MyEnum3 me3_d1 = MyEnum3.ME3_D1 |
| 78 | } |
| 79 | |
Nobuaki Sukegawa | ba3fe86 | 2015-12-01 22:42:55 +0900 | [diff] [blame] | 80 | struct EnumTestStruct { |
| 81 | 1: MyEnum3 a_enum; |
| 82 | 2: list<MyEnum3> enum_list; |
| 83 | 3: set<MyEnum3> enum_set; |
| 84 | 4: map<MyEnum3, MyEnum3> enum_enum_map; |
| 85 | // collections as keys |
| 86 | 44: map<list<MyEnum3> (python.immutable = ""), MyEnum3> list_enum_map; |
| 87 | 45: map<set<MyEnum3> (python.immutable = ""), MyEnum3> set_enum_map; |
| 88 | 46: map<map<MyEnum3,MyEnum3> (python.immutable = ""), MyEnum3> map_enum_map; |
| 89 | // collections as values |
| 90 | 47: map<MyEnum3, map<MyEnum3, MyEnum3>> enum_map_map; |
| 91 | 48: map<MyEnum3, set<MyEnum3>> enum_set_map; |
| 92 | 49: map<MyEnum3, list<MyEnum3>> enum_list_map; |
| 93 | } |
| 94 | |
| 95 | const EnumTestStruct ENUM_TEST = { |
| 96 | 'a_enum': MyEnum3.ME3_D1, |
| 97 | 'enum_list': [MyEnum3.ME3_D1, MyEnum3.ME3_0, MyEnum3.ME3_N2], |
| 98 | 'enum_set': [MyEnum3.ME3_D1, MyEnum3.ME3_N1], |
| 99 | 'enum_enum_map': {MyEnum3.ME3_D1: MyEnum3.ME3_0, MyEnum3.ME3_0: MyEnum3.ME3_D1}, |
| 100 | 'list_enum_map': {[MyEnum3.ME3_D1, MyEnum3.ME3_0]: MyEnum3.ME3_0, [MyEnum3.ME3_D1]: MyEnum3.ME3_0, [MyEnum3.ME3_0]: MyEnum3.ME3_D1}, |
| 101 | 'set_enum_map': {[MyEnum3.ME3_D1, MyEnum3.ME3_0]: MyEnum3.ME3_0, [MyEnum3.ME3_D1]: MyEnum3.ME3_0}, |
| 102 | 'map_enum_map': {{MyEnum3.ME3_N1: MyEnum3.ME3_10}: MyEnum3.ME3_1}, |
| 103 | 'enum_map_map': {MyEnum3.ME3_N1: {MyEnum3.ME3_D1: MyEnum3.ME3_D1}}, |
| 104 | 'enum_set_map': {MyEnum3.ME3_N2: [MyEnum3.ME3_D1, MyEnum3.ME3_N1], MyEnum3.ME3_10: [MyEnum3.ME3_D1, MyEnum3.ME3_N1]}, |
| 105 | 'enum_list_map': {MyEnum3.ME3_D1: [MyEnum3.ME3_10], MyEnum3.ME3_0: [MyEnum3.ME3_9, MyEnum3.ME3_10]}, |
| 106 | } |
| 107 | |
| 108 | service EnumTestService { |
| 109 | MyEnum3 testEnum(1: MyEnum3 enum1), |
| 110 | list<MyEnum3> testEnumList(1: list<MyEnum3> enum1), |
| 111 | set<MyEnum3> testEnumSet(1: set<MyEnum3> enum1), |
| 112 | map<MyEnum3, MyEnum3> testEnumMap(1: map<MyEnum3, MyEnum3> enum1), |
| 113 | EnumTestStruct testEnumStruct(1: EnumTestStruct enum1), |
| 114 | } |