1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 namespace Ice 6 { 7 namespace enums 8 { 9 public class AllTests : global::Test.AllTests 10 { allTests(global::Test.TestHelper helper)11 public static Test.TestIntfPrx allTests(global::Test.TestHelper helper) 12 { 13 Ice.Communicator communicator = helper.communicator(); 14 string sref = "test:" + helper.getTestEndpoint(0); 15 Ice.ObjectPrx obj = communicator.stringToProxy(sref); 16 test(obj != null); 17 var proxy = Test.TestIntfPrxHelper.uncheckedCast(obj); 18 test(proxy != null); 19 20 var output = helper.getWriter(); 21 22 output.Write("testing enum values... "); 23 output.Flush(); 24 25 test((int)Test.ByteEnum.benum1 == 0); 26 test((int)Test.ByteEnum.benum2 == 1); 27 test((int)Test.ByteEnum.benum3 == Test.ByteConst1.value); 28 test((int)Test.ByteEnum.benum4 == Test.ByteConst1.value + 1); 29 test((int)Test.ByteEnum.benum5 == Test.ShortConst1.value); 30 test((int)Test.ByteEnum.benum6 == Test.ShortConst1.value + 1); 31 test((int)Test.ByteEnum.benum7 == Test.IntConst1.value); 32 test((int)Test.ByteEnum.benum8 == Test.IntConst1.value + 1); 33 test((int)Test.ByteEnum.benum9 == Test.LongConst1.value); 34 test((int)Test.ByteEnum.benum10 == Test.LongConst1.value + 1); 35 test((int)Test.ByteEnum.benum11 == Test.ByteConst2.value); 36 37 test((int)Test.ShortEnum.senum1 == 3); 38 test((int)Test.ShortEnum.senum2 == 4); 39 test((int)Test.ShortEnum.senum3 == Test.ByteConst1.value); 40 test((int)Test.ShortEnum.senum4 == Test.ByteConst1.value + 1); 41 test((int)Test.ShortEnum.senum5 == Test.ShortConst1.value); 42 test((int)Test.ShortEnum.senum6 == Test.ShortConst1.value + 1); 43 test((int)Test.ShortEnum.senum7 == Test.IntConst1.value); 44 test((int)Test.ShortEnum.senum8 == Test.IntConst1.value + 1); 45 test((int)Test.ShortEnum.senum9 == Test.LongConst1.value); 46 test((int)Test.ShortEnum.senum10 == Test.LongConst1.value + 1); 47 test((int)Test.ShortEnum.senum11 == Test.ShortConst2.value); 48 49 test((int)Test.IntEnum.ienum1 == 0); 50 test((int)Test.IntEnum.ienum2 == 1); 51 test((int)Test.IntEnum.ienum3 == Test.ByteConst1.value); 52 test((int)Test.IntEnum.ienum4 == Test.ByteConst1.value + 1); 53 test((int)Test.IntEnum.ienum5 == Test.ShortConst1.value); 54 test((int)Test.IntEnum.ienum6 == Test.ShortConst1.value + 1); 55 test((int)Test.IntEnum.ienum7 == Test.IntConst1.value); 56 test((int)Test.IntEnum.ienum8 == Test.IntConst1.value + 1); 57 test((int)Test.IntEnum.ienum9 == Test.LongConst1.value); 58 test((int)Test.IntEnum.ienum10 == Test.LongConst1.value + 1); 59 test((int)Test.IntEnum.ienum11 == Test.IntConst2.value); 60 test((int)Test.IntEnum.ienum12 == Test.LongConst2.value); 61 62 test((int)Test.SimpleEnum.red == 0); 63 test((int)Test.SimpleEnum.green == 1); 64 test((int)Test.SimpleEnum.blue == 2); 65 66 output.WriteLine("ok"); 67 68 output.Write("testing enum streaming... "); 69 output.Flush(); 70 71 Ice.OutputStream ostr; 72 byte[] bytes; 73 74 bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0"); 75 76 ostr = new Ice.OutputStream(communicator); 77 ostr.writeEnum((int)Test.ByteEnum.benum11,(int)Test.ByteEnum.benum11); 78 bytes = ostr.finished(); 79 test(bytes.Length == 1); // ByteEnum should require one byte 80 81 ostr = new Ice.OutputStream(communicator); 82 ostr.writeEnum((int)Test.ShortEnum.senum11,(int)Test.ShortEnum.senum11); 83 bytes = ostr.finished(); 84 test(bytes.Length ==(encoding_1_0 ? 2 : 5)); 85 86 ostr = new Ice.OutputStream(communicator); 87 ostr.writeEnum((int)Test.IntEnum.ienum11,(int)Test.IntEnum.ienum12); 88 bytes = ostr.finished(); 89 test(bytes.Length ==(encoding_1_0 ? 4 : 5)); 90 91 ostr = new Ice.OutputStream(communicator); 92 ostr.writeEnum((int)Test.SimpleEnum.blue,(int)Test.SimpleEnum.blue); 93 bytes = ostr.finished(); 94 test(bytes.Length == 1); // SimpleEnum should require one byte 95 96 output.WriteLine("ok"); 97 98 output.Write("testing enum operations... "); 99 output.Flush(); 100 101 Test.ByteEnum byteEnum; 102 test(proxy.opByte(Test.ByteEnum.benum1, out byteEnum) == Test.ByteEnum.benum1); 103 test(byteEnum == Test.ByteEnum.benum1); 104 test(proxy.opByte(Test.ByteEnum.benum11, out byteEnum) == Test.ByteEnum.benum11); 105 test(byteEnum == Test.ByteEnum.benum11); 106 107 Test.ShortEnum shortEnum; 108 test(proxy.opShort(Test.ShortEnum.senum1, out shortEnum) == Test.ShortEnum.senum1); 109 test(shortEnum == Test.ShortEnum.senum1); 110 test(proxy.opShort(Test.ShortEnum.senum11, out shortEnum) == Test.ShortEnum.senum11); 111 test(shortEnum == Test.ShortEnum.senum11); 112 113 Test.IntEnum intEnum; 114 test(proxy.opInt(Test.IntEnum.ienum1, out intEnum) == Test.IntEnum.ienum1); 115 test(intEnum == Test.IntEnum.ienum1); 116 test(proxy.opInt(Test.IntEnum.ienum11, out intEnum) == Test.IntEnum.ienum11); 117 test(intEnum == Test.IntEnum.ienum11); 118 test(proxy.opInt(Test.IntEnum.ienum12, out intEnum) == Test.IntEnum.ienum12); 119 test(intEnum == Test.IntEnum.ienum12); 120 121 Test.SimpleEnum s; 122 test(proxy.opSimple(Test.SimpleEnum.green, out s) == Test.SimpleEnum.green); 123 test(s == Test.SimpleEnum.green); 124 125 output.WriteLine("ok"); 126 127 output.Write("testing enum sequences operations... "); 128 output.Flush(); 129 130 { 131 var b1 = new Test.ByteEnum[11] 132 { 133 Test.ByteEnum.benum1, 134 Test.ByteEnum.benum2, 135 Test.ByteEnum.benum3, 136 Test.ByteEnum.benum4, 137 Test.ByteEnum.benum5, 138 Test.ByteEnum.benum6, 139 Test.ByteEnum.benum7, 140 Test.ByteEnum.benum8, 141 Test.ByteEnum.benum9, 142 Test.ByteEnum.benum10, 143 Test.ByteEnum.benum11 144 }; 145 146 Test.ByteEnum[] b2; 147 Test.ByteEnum[] b3 = proxy.opByteSeq(b1, out b2); 148 149 for(int i = 0; i < b1.Length; ++i) 150 { 151 test(b1[i] == b2[i]); 152 test(b1[i] == b3[i]); 153 } 154 } 155 156 { 157 var s1 = new Test.ShortEnum[11] 158 { 159 Test.ShortEnum.senum1, 160 Test.ShortEnum.senum2, 161 Test.ShortEnum.senum3, 162 Test.ShortEnum.senum4, 163 Test.ShortEnum.senum5, 164 Test.ShortEnum.senum6, 165 Test.ShortEnum.senum7, 166 Test.ShortEnum.senum8, 167 Test.ShortEnum.senum9, 168 Test.ShortEnum.senum10, 169 Test.ShortEnum.senum11 170 }; 171 172 Test.ShortEnum[] s2; 173 Test.ShortEnum[] s3 = proxy.opShortSeq(s1, out s2); 174 175 for(int i = 0; i < s1.Length; ++i) 176 { 177 test(s1[i] == s2[i]); 178 test(s1[i] == s3[i]); 179 } 180 } 181 182 { 183 Test.IntEnum[] i1 = new Test.IntEnum[11] 184 { 185 Test.IntEnum.ienum1, 186 Test.IntEnum.ienum2, 187 Test.IntEnum.ienum3, 188 Test.IntEnum.ienum4, 189 Test.IntEnum.ienum5, 190 Test.IntEnum.ienum6, 191 Test.IntEnum.ienum7, 192 Test.IntEnum.ienum8, 193 Test.IntEnum.ienum9, 194 Test.IntEnum.ienum10, 195 Test.IntEnum.ienum11 196 }; 197 198 Test.IntEnum[] i2; 199 Test.IntEnum[] i3 = proxy.opIntSeq(i1, out i2); 200 201 for(int i = 0; i < i1.Length; ++i) 202 { 203 test(i1[i] == i2[i]); 204 test(i1[i] == i3[i]); 205 } 206 } 207 208 { 209 var s1 = new Test.SimpleEnum[3] 210 { 211 Test.SimpleEnum.red, 212 Test.SimpleEnum.green, 213 Test.SimpleEnum.blue 214 }; 215 216 Test.SimpleEnum[] s2; 217 Test.SimpleEnum[] s3 = proxy.opSimpleSeq(s1, out s2); 218 219 for(int i = 0; i < s1.Length; ++i) 220 { 221 test(s1[i] == s2[i]); 222 test(s1[i] == s3[i]); 223 } 224 } 225 226 output.WriteLine("ok"); 227 return proxy; 228 } 229 } 230 } 231 } 232