1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // https://developers.google.com/protocol-buffers/ 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions are 7 // met: 8 // 9 // * Redistributions of source code must retain the above copyright 10 // notice, this list of conditions and the following disclaimer. 11 // * Redistributions in binary form must reproduce the above 12 // copyright notice, this list of conditions and the following disclaimer 13 // in the documentation and/or other materials provided with the 14 // distribution. 15 // * Neither the name of Google Inc. nor the names of its 16 // contributors may be used to endorse or promote products derived from 17 // this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 package com.google.protobuf; 32 33 import static com.google.protobuf.UnittestLite.OptionalGroup_extension_lite; 34 import static com.google.protobuf.UnittestLite.RepeatedGroup_extension_lite; 35 import static com.google.protobuf.UnittestLite.defaultBoolExtensionLite; 36 import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite; 37 import static com.google.protobuf.UnittestLite.defaultCordExtensionLite; 38 import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite; 39 import static com.google.protobuf.UnittestLite.defaultFixed32ExtensionLite; 40 import static com.google.protobuf.UnittestLite.defaultFixed64ExtensionLite; 41 import static com.google.protobuf.UnittestLite.defaultFloatExtensionLite; 42 import static com.google.protobuf.UnittestLite.defaultForeignEnumExtensionLite; 43 import static com.google.protobuf.UnittestLite.defaultImportEnumExtensionLite; 44 import static com.google.protobuf.UnittestLite.defaultInt32ExtensionLite; 45 import static com.google.protobuf.UnittestLite.defaultInt64ExtensionLite; 46 import static com.google.protobuf.UnittestLite.defaultNestedEnumExtensionLite; 47 import static com.google.protobuf.UnittestLite.defaultSfixed32ExtensionLite; 48 import static com.google.protobuf.UnittestLite.defaultSfixed64ExtensionLite; 49 import static com.google.protobuf.UnittestLite.defaultSint32ExtensionLite; 50 import static com.google.protobuf.UnittestLite.defaultSint64ExtensionLite; 51 import static com.google.protobuf.UnittestLite.defaultStringExtensionLite; 52 import static com.google.protobuf.UnittestLite.defaultStringPieceExtensionLite; 53 import static com.google.protobuf.UnittestLite.defaultUint32ExtensionLite; 54 import static com.google.protobuf.UnittestLite.defaultUint64ExtensionLite; 55 import static com.google.protobuf.UnittestLite.oneofBytesExtensionLite; 56 import static com.google.protobuf.UnittestLite.oneofNestedMessageExtensionLite; 57 import static com.google.protobuf.UnittestLite.oneofStringExtensionLite; 58 import static com.google.protobuf.UnittestLite.oneofUint32ExtensionLite; 59 import static com.google.protobuf.UnittestLite.optionalBoolExtensionLite; 60 import static com.google.protobuf.UnittestLite.optionalBytesExtensionLite; 61 import static com.google.protobuf.UnittestLite.optionalCordExtensionLite; 62 import static com.google.protobuf.UnittestLite.optionalDoubleExtensionLite; 63 import static com.google.protobuf.UnittestLite.optionalFixed32ExtensionLite; 64 import static com.google.protobuf.UnittestLite.optionalFixed64ExtensionLite; 65 import static com.google.protobuf.UnittestLite.optionalFloatExtensionLite; 66 import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite; 67 import static com.google.protobuf.UnittestLite.optionalForeignMessageExtensionLite; 68 import static com.google.protobuf.UnittestLite.optionalGroupExtensionLite; 69 import static com.google.protobuf.UnittestLite.optionalImportEnumExtensionLite; 70 import static com.google.protobuf.UnittestLite.optionalImportMessageExtensionLite; 71 import static com.google.protobuf.UnittestLite.optionalInt32ExtensionLite; 72 import static com.google.protobuf.UnittestLite.optionalInt64ExtensionLite; 73 import static com.google.protobuf.UnittestLite.optionalLazyMessageExtensionLite; 74 import static com.google.protobuf.UnittestLite.optionalNestedEnumExtensionLite; 75 import static com.google.protobuf.UnittestLite.optionalNestedMessageExtensionLite; 76 import static com.google.protobuf.UnittestLite.optionalPublicImportMessageExtensionLite; 77 import static com.google.protobuf.UnittestLite.optionalSfixed32ExtensionLite; 78 import static com.google.protobuf.UnittestLite.optionalSfixed64ExtensionLite; 79 import static com.google.protobuf.UnittestLite.optionalSint32ExtensionLite; 80 import static com.google.protobuf.UnittestLite.optionalSint64ExtensionLite; 81 import static com.google.protobuf.UnittestLite.optionalStringExtensionLite; 82 import static com.google.protobuf.UnittestLite.optionalStringPieceExtensionLite; 83 import static com.google.protobuf.UnittestLite.optionalUint32ExtensionLite; 84 import static com.google.protobuf.UnittestLite.optionalUint64ExtensionLite; 85 import static com.google.protobuf.UnittestLite.packedBoolExtensionLite; 86 import static com.google.protobuf.UnittestLite.packedDoubleExtensionLite; 87 import static com.google.protobuf.UnittestLite.packedEnumExtensionLite; 88 import static com.google.protobuf.UnittestLite.packedFixed32ExtensionLite; 89 import static com.google.protobuf.UnittestLite.packedFixed64ExtensionLite; 90 import static com.google.protobuf.UnittestLite.packedFloatExtensionLite; 91 import static com.google.protobuf.UnittestLite.packedInt32ExtensionLite; 92 import static com.google.protobuf.UnittestLite.packedInt64ExtensionLite; 93 import static com.google.protobuf.UnittestLite.packedSfixed32ExtensionLite; 94 import static com.google.protobuf.UnittestLite.packedSfixed64ExtensionLite; 95 import static com.google.protobuf.UnittestLite.packedSint32ExtensionLite; 96 import static com.google.protobuf.UnittestLite.packedSint64ExtensionLite; 97 import static com.google.protobuf.UnittestLite.packedUint32ExtensionLite; 98 import static com.google.protobuf.UnittestLite.packedUint64ExtensionLite; 99 import static com.google.protobuf.UnittestLite.repeatedBoolExtensionLite; 100 import static com.google.protobuf.UnittestLite.repeatedBytesExtensionLite; 101 import static com.google.protobuf.UnittestLite.repeatedCordExtensionLite; 102 import static com.google.protobuf.UnittestLite.repeatedDoubleExtensionLite; 103 import static com.google.protobuf.UnittestLite.repeatedFixed32ExtensionLite; 104 import static com.google.protobuf.UnittestLite.repeatedFixed64ExtensionLite; 105 import static com.google.protobuf.UnittestLite.repeatedFloatExtensionLite; 106 import static com.google.protobuf.UnittestLite.repeatedForeignEnumExtensionLite; 107 import static com.google.protobuf.UnittestLite.repeatedForeignMessageExtensionLite; 108 import static com.google.protobuf.UnittestLite.repeatedGroupExtensionLite; 109 import static com.google.protobuf.UnittestLite.repeatedImportEnumExtensionLite; 110 import static com.google.protobuf.UnittestLite.repeatedImportMessageExtensionLite; 111 import static com.google.protobuf.UnittestLite.repeatedInt32ExtensionLite; 112 import static com.google.protobuf.UnittestLite.repeatedInt64ExtensionLite; 113 import static com.google.protobuf.UnittestLite.repeatedLazyMessageExtensionLite; 114 import static com.google.protobuf.UnittestLite.repeatedNestedEnumExtensionLite; 115 import static com.google.protobuf.UnittestLite.repeatedNestedMessageExtensionLite; 116 import static com.google.protobuf.UnittestLite.repeatedSfixed32ExtensionLite; 117 import static com.google.protobuf.UnittestLite.repeatedSfixed64ExtensionLite; 118 import static com.google.protobuf.UnittestLite.repeatedSint32ExtensionLite; 119 import static com.google.protobuf.UnittestLite.repeatedSint64ExtensionLite; 120 import static com.google.protobuf.UnittestLite.repeatedStringExtensionLite; 121 import static com.google.protobuf.UnittestLite.repeatedStringPieceExtensionLite; 122 import static com.google.protobuf.UnittestLite.repeatedUint32ExtensionLite; 123 import static com.google.protobuf.UnittestLite.repeatedUint64ExtensionLite; 124 125 import com.google.protobuf.UnittestImportLite.ImportEnumLite; 126 import com.google.protobuf.UnittestImportLite.ImportMessageLite; 127 import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite; 128 import com.google.protobuf.UnittestLite.ForeignEnumLite; 129 import com.google.protobuf.UnittestLite.ForeignMessageLite; 130 import com.google.protobuf.UnittestLite.TestAllExtensionsLite; 131 import com.google.protobuf.UnittestLite.TestAllTypesLite; 132 import com.google.protobuf.UnittestLite.TestPackedExtensionsLite; 133 134 /** 135 * Contains methods for setting fields of {@code TestAllTypesLite}, {@code TestAllExtensionsLite}, 136 * and {@code TestPackedExtensionsLite}. This is analogous to the functionality in TestUtil.java but 137 * does not depend on the presence of any non-lite protos. 138 * 139 * <p>This code is not to be used outside of {@code com.google.protobuf} and 140 * subpackages. 141 */ 142 public final class TestUtilLite { TestUtilLite()143 private TestUtilLite() {} 144 145 /** Helper to convert a String to ByteString. */ toBytes(String str)146 static ByteString toBytes(String str) { 147 return ByteString.copyFrom(str.getBytes(Internal.UTF_8)); 148 } 149 150 /** 151 * Get a {@code TestAllTypesLite.Builder} with all fields set as they would be by 152 * {@link #setAllFields(TestAllTypesLite.Builder)}. 153 */ getAllLiteSetBuilder()154 public static TestAllTypesLite.Builder getAllLiteSetBuilder() { 155 TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder(); 156 setAllFields(builder); 157 return builder; 158 } 159 160 /** 161 * Get a {@code TestAllExtensionsLite} with all fields set as they would be by 162 * {@link #setAllExtensions(TestAllExtensionsLite.Builder)}. 163 */ getAllLiteExtensionsSet()164 public static TestAllExtensionsLite getAllLiteExtensionsSet() { 165 TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder(); 166 setAllExtensions(builder); 167 return builder.build(); 168 } 169 getLitePackedExtensionsSet()170 public static TestPackedExtensionsLite getLitePackedExtensionsSet() { 171 TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.newBuilder(); 172 setPackedExtensions(builder); 173 return builder.build(); 174 } 175 176 /** 177 * Set every field of {@code builder} to the values expected by 178 * {@code assertAllFieldsSet()}. 179 */ setAllFields(TestAllTypesLite.Builder builder)180 public static void setAllFields(TestAllTypesLite.Builder builder) { 181 builder.setOptionalInt32 (101); 182 builder.setOptionalInt64 (102); 183 builder.setOptionalUint32 (103); 184 builder.setOptionalUint64 (104); 185 builder.setOptionalSint32 (105); 186 builder.setOptionalSint64 (106); 187 builder.setOptionalFixed32 (107); 188 builder.setOptionalFixed64 (108); 189 builder.setOptionalSfixed32(109); 190 builder.setOptionalSfixed64(110); 191 builder.setOptionalFloat (111); 192 builder.setOptionalDouble (112); 193 builder.setOptionalBool (true); 194 builder.setOptionalString ("115"); 195 builder.setOptionalBytes (toBytes("116")); 196 197 builder.setOptionalGroup( 198 TestAllTypesLite.OptionalGroup.newBuilder().setA(117).build()); 199 builder.setOptionalNestedMessage( 200 TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build()); 201 builder.setOptionalForeignMessage( 202 ForeignMessageLite.newBuilder().setC(119).build()); 203 builder.setOptionalImportMessage( 204 ImportMessageLite.newBuilder().setD(120).build()); 205 builder.setOptionalPublicImportMessage( 206 PublicImportMessageLite.newBuilder().setE(126).build()); 207 builder.setOptionalLazyMessage( 208 TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build()); 209 210 builder.setOptionalNestedEnum (TestAllTypesLite.NestedEnum.BAZ); 211 builder.setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ); 212 builder.setOptionalImportEnum (ImportEnumLite.IMPORT_LITE_BAZ); 213 214 builder.setOptionalStringPiece("124"); 215 builder.setOptionalCord("125"); 216 217 // ----------------------------------------------------------------- 218 219 builder.addRepeatedInt32 (201); 220 builder.addRepeatedInt64 (202); 221 builder.addRepeatedUint32 (203); 222 builder.addRepeatedUint64 (204); 223 builder.addRepeatedSint32 (205); 224 builder.addRepeatedSint64 (206); 225 builder.addRepeatedFixed32 (207); 226 builder.addRepeatedFixed64 (208); 227 builder.addRepeatedSfixed32(209); 228 builder.addRepeatedSfixed64(210); 229 builder.addRepeatedFloat (211); 230 builder.addRepeatedDouble (212); 231 builder.addRepeatedBool (true); 232 builder.addRepeatedString ("215"); 233 builder.addRepeatedBytes (toBytes("216")); 234 235 builder.addRepeatedGroup( 236 TestAllTypesLite.RepeatedGroup.newBuilder().setA(217).build()); 237 builder.addRepeatedNestedMessage( 238 TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build()); 239 builder.addRepeatedForeignMessage( 240 ForeignMessageLite.newBuilder().setC(219).build()); 241 builder.addRepeatedImportMessage( 242 ImportMessageLite.newBuilder().setD(220).build()); 243 builder.addRepeatedLazyMessage( 244 TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build()); 245 246 builder.addRepeatedNestedEnum (TestAllTypesLite.NestedEnum.BAR); 247 builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR); 248 builder.addRepeatedImportEnum (ImportEnumLite.IMPORT_LITE_BAR); 249 250 builder.addRepeatedStringPiece("224"); 251 builder.addRepeatedCord("225"); 252 253 // Add a second one of each field. 254 builder.addRepeatedInt32 (301); 255 builder.addRepeatedInt64 (302); 256 builder.addRepeatedUint32 (303); 257 builder.addRepeatedUint64 (304); 258 builder.addRepeatedSint32 (305); 259 builder.addRepeatedSint64 (306); 260 builder.addRepeatedFixed32 (307); 261 builder.addRepeatedFixed64 (308); 262 builder.addRepeatedSfixed32(309); 263 builder.addRepeatedSfixed64(310); 264 builder.addRepeatedFloat (311); 265 builder.addRepeatedDouble (312); 266 builder.addRepeatedBool (false); 267 builder.addRepeatedString ("315"); 268 builder.addRepeatedBytes (toBytes("316")); 269 270 builder.addRepeatedGroup( 271 TestAllTypesLite.RepeatedGroup.newBuilder().setA(317).build()); 272 builder.addRepeatedNestedMessage( 273 TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build()); 274 builder.addRepeatedForeignMessage( 275 ForeignMessageLite.newBuilder().setC(319).build()); 276 builder.addRepeatedImportMessage( 277 ImportMessageLite.newBuilder().setD(320).build()); 278 builder.addRepeatedLazyMessage( 279 TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build()); 280 281 builder.addRepeatedNestedEnum (TestAllTypesLite.NestedEnum.BAZ); 282 builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ); 283 builder.addRepeatedImportEnum (ImportEnumLite.IMPORT_LITE_BAZ); 284 285 builder.addRepeatedStringPiece("324"); 286 builder.addRepeatedCord("325"); 287 288 // ----------------------------------------------------------------- 289 290 builder.setDefaultInt32 (401); 291 builder.setDefaultInt64 (402); 292 builder.setDefaultUint32 (403); 293 builder.setDefaultUint64 (404); 294 builder.setDefaultSint32 (405); 295 builder.setDefaultSint64 (406); 296 builder.setDefaultFixed32 (407); 297 builder.setDefaultFixed64 (408); 298 builder.setDefaultSfixed32(409); 299 builder.setDefaultSfixed64(410); 300 builder.setDefaultFloat (411); 301 builder.setDefaultDouble (412); 302 builder.setDefaultBool (false); 303 builder.setDefaultString ("415"); 304 builder.setDefaultBytes (toBytes("416")); 305 306 builder.setDefaultNestedEnum (TestAllTypesLite.NestedEnum.FOO); 307 builder.setDefaultForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO); 308 builder.setDefaultImportEnum (ImportEnumLite.IMPORT_LITE_FOO); 309 310 builder.setDefaultStringPiece("424"); 311 builder.setDefaultCord("425"); 312 313 builder.setOneofUint32(601); 314 builder.setOneofNestedMessage( 315 TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build()); 316 builder.setOneofString("603"); 317 builder.setOneofBytes(toBytes("604")); 318 } 319 320 /** 321 * Get an unmodifiable {@link ExtensionRegistryLite} containing all the 322 * extensions of {@code TestAllExtensionsLite}. 323 */ getExtensionRegistryLite()324 public static ExtensionRegistryLite getExtensionRegistryLite() { 325 ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance(); 326 registerAllExtensionsLite(registry); 327 return registry.getUnmodifiable(); 328 } 329 330 /** 331 * Register all of {@code TestAllExtensionsLite}'s extensions with the 332 * given {@link ExtensionRegistryLite}. 333 */ registerAllExtensionsLite(ExtensionRegistryLite registry)334 public static void registerAllExtensionsLite(ExtensionRegistryLite registry) { 335 UnittestLite.registerAllExtensions(registry); 336 } 337 338 // =================================================================== 339 // Lite extensions 340 341 /** 342 * Set every field of {@code message} to the values expected by 343 * {@code assertAllExtensionsSet()}. 344 */ setAllExtensions(TestAllExtensionsLite.Builder message)345 public static void setAllExtensions(TestAllExtensionsLite.Builder message) { 346 message.setExtension(optionalInt32ExtensionLite , 101); 347 message.setExtension(optionalInt64ExtensionLite , 102L); 348 message.setExtension(optionalUint32ExtensionLite , 103); 349 message.setExtension(optionalUint64ExtensionLite , 104L); 350 message.setExtension(optionalSint32ExtensionLite , 105); 351 message.setExtension(optionalSint64ExtensionLite , 106L); 352 message.setExtension(optionalFixed32ExtensionLite , 107); 353 message.setExtension(optionalFixed64ExtensionLite , 108L); 354 message.setExtension(optionalSfixed32ExtensionLite, 109); 355 message.setExtension(optionalSfixed64ExtensionLite, 110L); 356 message.setExtension(optionalFloatExtensionLite , 111F); 357 message.setExtension(optionalDoubleExtensionLite , 112D); 358 message.setExtension(optionalBoolExtensionLite , true); 359 message.setExtension(optionalStringExtensionLite , "115"); 360 message.setExtension(optionalBytesExtensionLite , toBytes("116")); 361 362 message.setExtension(optionalGroupExtensionLite, 363 OptionalGroup_extension_lite.newBuilder().setA(117).build()); 364 message.setExtension(optionalNestedMessageExtensionLite, 365 TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build()); 366 message.setExtension(optionalForeignMessageExtensionLite, 367 ForeignMessageLite.newBuilder().setC(119).build()); 368 message.setExtension(optionalImportMessageExtensionLite, 369 ImportMessageLite.newBuilder().setD(120).build()); 370 message.setExtension(optionalPublicImportMessageExtensionLite, 371 PublicImportMessageLite.newBuilder().setE(126).build()); 372 message.setExtension(optionalLazyMessageExtensionLite, 373 TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build()); 374 375 message.setExtension(optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ); 376 message.setExtension(optionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 377 message.setExtension(optionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ); 378 379 message.setExtension(optionalStringPieceExtensionLite, "124"); 380 message.setExtension(optionalCordExtensionLite, "125"); 381 382 // ----------------------------------------------------------------- 383 384 message.addExtension(repeatedInt32ExtensionLite , 201); 385 message.addExtension(repeatedInt64ExtensionLite , 202L); 386 message.addExtension(repeatedUint32ExtensionLite , 203); 387 message.addExtension(repeatedUint64ExtensionLite , 204L); 388 message.addExtension(repeatedSint32ExtensionLite , 205); 389 message.addExtension(repeatedSint64ExtensionLite , 206L); 390 message.addExtension(repeatedFixed32ExtensionLite , 207); 391 message.addExtension(repeatedFixed64ExtensionLite , 208L); 392 message.addExtension(repeatedSfixed32ExtensionLite, 209); 393 message.addExtension(repeatedSfixed64ExtensionLite, 210L); 394 message.addExtension(repeatedFloatExtensionLite , 211F); 395 message.addExtension(repeatedDoubleExtensionLite , 212D); 396 message.addExtension(repeatedBoolExtensionLite , true); 397 message.addExtension(repeatedStringExtensionLite , "215"); 398 message.addExtension(repeatedBytesExtensionLite , toBytes("216")); 399 400 message.addExtension(repeatedGroupExtensionLite, 401 RepeatedGroup_extension_lite.newBuilder().setA(217).build()); 402 message.addExtension(repeatedNestedMessageExtensionLite, 403 TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build()); 404 message.addExtension(repeatedForeignMessageExtensionLite, 405 ForeignMessageLite.newBuilder().setC(219).build()); 406 message.addExtension(repeatedImportMessageExtensionLite, 407 ImportMessageLite.newBuilder().setD(220).build()); 408 message.addExtension(repeatedLazyMessageExtensionLite, 409 TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build()); 410 411 message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAR); 412 message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); 413 message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAR); 414 415 message.addExtension(repeatedStringPieceExtensionLite, "224"); 416 message.addExtension(repeatedCordExtensionLite, "225"); 417 418 // Add a second one of each field. 419 message.addExtension(repeatedInt32ExtensionLite , 301); 420 message.addExtension(repeatedInt64ExtensionLite , 302L); 421 message.addExtension(repeatedUint32ExtensionLite , 303); 422 message.addExtension(repeatedUint64ExtensionLite , 304L); 423 message.addExtension(repeatedSint32ExtensionLite , 305); 424 message.addExtension(repeatedSint64ExtensionLite , 306L); 425 message.addExtension(repeatedFixed32ExtensionLite , 307); 426 message.addExtension(repeatedFixed64ExtensionLite , 308L); 427 message.addExtension(repeatedSfixed32ExtensionLite, 309); 428 message.addExtension(repeatedSfixed64ExtensionLite, 310L); 429 message.addExtension(repeatedFloatExtensionLite , 311F); 430 message.addExtension(repeatedDoubleExtensionLite , 312D); 431 message.addExtension(repeatedBoolExtensionLite , false); 432 message.addExtension(repeatedStringExtensionLite , "315"); 433 message.addExtension(repeatedBytesExtensionLite , toBytes("316")); 434 435 message.addExtension(repeatedGroupExtensionLite, 436 RepeatedGroup_extension_lite.newBuilder().setA(317).build()); 437 message.addExtension(repeatedNestedMessageExtensionLite, 438 TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build()); 439 message.addExtension(repeatedForeignMessageExtensionLite, 440 ForeignMessageLite.newBuilder().setC(319).build()); 441 message.addExtension(repeatedImportMessageExtensionLite, 442 ImportMessageLite.newBuilder().setD(320).build()); 443 message.addExtension(repeatedLazyMessageExtensionLite, 444 TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build()); 445 446 message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ); 447 message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 448 message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ); 449 450 message.addExtension(repeatedStringPieceExtensionLite, "324"); 451 message.addExtension(repeatedCordExtensionLite, "325"); 452 453 // ----------------------------------------------------------------- 454 455 message.setExtension(defaultInt32ExtensionLite , 401); 456 message.setExtension(defaultInt64ExtensionLite , 402L); 457 message.setExtension(defaultUint32ExtensionLite , 403); 458 message.setExtension(defaultUint64ExtensionLite , 404L); 459 message.setExtension(defaultSint32ExtensionLite , 405); 460 message.setExtension(defaultSint64ExtensionLite , 406L); 461 message.setExtension(defaultFixed32ExtensionLite , 407); 462 message.setExtension(defaultFixed64ExtensionLite , 408L); 463 message.setExtension(defaultSfixed32ExtensionLite, 409); 464 message.setExtension(defaultSfixed64ExtensionLite, 410L); 465 message.setExtension(defaultFloatExtensionLite , 411F); 466 message.setExtension(defaultDoubleExtensionLite , 412D); 467 message.setExtension(defaultBoolExtensionLite , false); 468 message.setExtension(defaultStringExtensionLite , "415"); 469 message.setExtension(defaultBytesExtensionLite , toBytes("416")); 470 471 message.setExtension(defaultNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.FOO); 472 message.setExtension(defaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_FOO); 473 message.setExtension(defaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_FOO); 474 475 message.setExtension(defaultStringPieceExtensionLite, "424"); 476 message.setExtension(defaultCordExtensionLite, "425"); 477 478 message.setExtension(oneofUint32ExtensionLite, 601); 479 message.setExtension(oneofNestedMessageExtensionLite, 480 TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build()); 481 message.setExtension(oneofStringExtensionLite, "603"); 482 message.setExtension(oneofBytesExtensionLite, toBytes("604")); 483 } 484 485 // ------------------------------------------------------------------- 486 487 /** 488 * Modify the repeated extensions of {@code message} to contain the values 489 * expected by {@code assertRepeatedExtensionsModified()}. 490 */ modifyRepeatedExtensions( TestAllExtensionsLite.Builder message)491 public static void modifyRepeatedExtensions( 492 TestAllExtensionsLite.Builder message) { 493 message.setExtension(repeatedInt32ExtensionLite , 1, 501); 494 message.setExtension(repeatedInt64ExtensionLite , 1, 502L); 495 message.setExtension(repeatedUint32ExtensionLite , 1, 503); 496 message.setExtension(repeatedUint64ExtensionLite , 1, 504L); 497 message.setExtension(repeatedSint32ExtensionLite , 1, 505); 498 message.setExtension(repeatedSint64ExtensionLite , 1, 506L); 499 message.setExtension(repeatedFixed32ExtensionLite , 1, 507); 500 message.setExtension(repeatedFixed64ExtensionLite , 1, 508L); 501 message.setExtension(repeatedSfixed32ExtensionLite, 1, 509); 502 message.setExtension(repeatedSfixed64ExtensionLite, 1, 510L); 503 message.setExtension(repeatedFloatExtensionLite , 1, 511F); 504 message.setExtension(repeatedDoubleExtensionLite , 1, 512D); 505 message.setExtension(repeatedBoolExtensionLite , 1, true); 506 message.setExtension(repeatedStringExtensionLite , 1, "515"); 507 message.setExtension(repeatedBytesExtensionLite , 1, toBytes("516")); 508 509 message.setExtension(repeatedGroupExtensionLite, 1, 510 RepeatedGroup_extension_lite.newBuilder().setA(517).build()); 511 message.setExtension(repeatedNestedMessageExtensionLite, 1, 512 TestAllTypesLite.NestedMessage.newBuilder().setBb(518).build()); 513 message.setExtension(repeatedForeignMessageExtensionLite, 1, 514 ForeignMessageLite.newBuilder().setC(519).build()); 515 message.setExtension(repeatedImportMessageExtensionLite, 1, 516 ImportMessageLite.newBuilder().setD(520).build()); 517 message.setExtension(repeatedLazyMessageExtensionLite, 1, 518 TestAllTypesLite.NestedMessage.newBuilder().setBb(527).build()); 519 520 message.setExtension(repeatedNestedEnumExtensionLite , 1, TestAllTypesLite.NestedEnum.FOO); 521 message.setExtension(repeatedForeignEnumExtensionLite, 1, ForeignEnumLite.FOREIGN_LITE_FOO); 522 message.setExtension(repeatedImportEnumExtensionLite , 1, ImportEnumLite.IMPORT_LITE_FOO); 523 524 message.setExtension(repeatedStringPieceExtensionLite, 1, "524"); 525 message.setExtension(repeatedCordExtensionLite, 1, "525"); 526 } 527 setPackedExtensions(TestPackedExtensionsLite.Builder message)528 public static void setPackedExtensions(TestPackedExtensionsLite.Builder message) { 529 message.addExtension(packedInt32ExtensionLite , 601); 530 message.addExtension(packedInt64ExtensionLite , 602L); 531 message.addExtension(packedUint32ExtensionLite , 603); 532 message.addExtension(packedUint64ExtensionLite , 604L); 533 message.addExtension(packedSint32ExtensionLite , 605); 534 message.addExtension(packedSint64ExtensionLite , 606L); 535 message.addExtension(packedFixed32ExtensionLite , 607); 536 message.addExtension(packedFixed64ExtensionLite , 608L); 537 message.addExtension(packedSfixed32ExtensionLite, 609); 538 message.addExtension(packedSfixed64ExtensionLite, 610L); 539 message.addExtension(packedFloatExtensionLite , 611F); 540 message.addExtension(packedDoubleExtensionLite , 612D); 541 message.addExtension(packedBoolExtensionLite , true); 542 message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); 543 // Add a second one of each field. 544 message.addExtension(packedInt32ExtensionLite , 701); 545 message.addExtension(packedInt64ExtensionLite , 702L); 546 message.addExtension(packedUint32ExtensionLite , 703); 547 message.addExtension(packedUint64ExtensionLite , 704L); 548 message.addExtension(packedSint32ExtensionLite , 705); 549 message.addExtension(packedSint64ExtensionLite , 706L); 550 message.addExtension(packedFixed32ExtensionLite , 707); 551 message.addExtension(packedFixed64ExtensionLite , 708L); 552 message.addExtension(packedSfixed32ExtensionLite, 709); 553 message.addExtension(packedSfixed64ExtensionLite, 710L); 554 message.addExtension(packedFloatExtensionLite , 711F); 555 message.addExtension(packedDoubleExtensionLite , 712D); 556 message.addExtension(packedBoolExtensionLite , false); 557 message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 558 } 559 } 560