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.defaultBoolExtensionLite; 34 import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite; 35 import static com.google.protobuf.UnittestLite.defaultCordExtensionLite; 36 import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite; 37 import static com.google.protobuf.UnittestLite.defaultFixed32ExtensionLite; 38 import static com.google.protobuf.UnittestLite.defaultFixed64ExtensionLite; 39 import static com.google.protobuf.UnittestLite.defaultFloatExtensionLite; 40 import static com.google.protobuf.UnittestLite.defaultForeignEnumExtensionLite; 41 import static com.google.protobuf.UnittestLite.defaultImportEnumExtensionLite; 42 import static com.google.protobuf.UnittestLite.defaultInt32ExtensionLite; 43 import static com.google.protobuf.UnittestLite.defaultInt64ExtensionLite; 44 import static com.google.protobuf.UnittestLite.defaultNestedEnumExtensionLite; 45 import static com.google.protobuf.UnittestLite.defaultSfixed32ExtensionLite; 46 import static com.google.protobuf.UnittestLite.defaultSfixed64ExtensionLite; 47 import static com.google.protobuf.UnittestLite.defaultSint32ExtensionLite; 48 import static com.google.protobuf.UnittestLite.defaultSint64ExtensionLite; 49 import static com.google.protobuf.UnittestLite.defaultStringExtensionLite; 50 import static com.google.protobuf.UnittestLite.defaultStringPieceExtensionLite; 51 import static com.google.protobuf.UnittestLite.defaultUint32ExtensionLite; 52 import static com.google.protobuf.UnittestLite.defaultUint64ExtensionLite; 53 import static com.google.protobuf.UnittestLite.oneofBytesExtensionLite; 54 import static com.google.protobuf.UnittestLite.oneofNestedMessageExtensionLite; 55 import static com.google.protobuf.UnittestLite.oneofStringExtensionLite; 56 import static com.google.protobuf.UnittestLite.oneofUint32ExtensionLite; 57 import static com.google.protobuf.UnittestLite.optionalBoolExtensionLite; 58 import static com.google.protobuf.UnittestLite.optionalBytesExtensionLite; 59 import static com.google.protobuf.UnittestLite.optionalCordExtensionLite; 60 import static com.google.protobuf.UnittestLite.optionalDoubleExtensionLite; 61 import static com.google.protobuf.UnittestLite.optionalFixed32ExtensionLite; 62 import static com.google.protobuf.UnittestLite.optionalFixed64ExtensionLite; 63 import static com.google.protobuf.UnittestLite.optionalFloatExtensionLite; 64 import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite; 65 import static com.google.protobuf.UnittestLite.optionalForeignMessageExtensionLite; 66 import static com.google.protobuf.UnittestLite.optionalGroupExtensionLite; 67 import static com.google.protobuf.UnittestLite.optionalImportEnumExtensionLite; 68 import static com.google.protobuf.UnittestLite.optionalImportMessageExtensionLite; 69 import static com.google.protobuf.UnittestLite.optionalInt32ExtensionLite; 70 import static com.google.protobuf.UnittestLite.optionalInt64ExtensionLite; 71 import static com.google.protobuf.UnittestLite.optionalLazyMessageExtensionLite; 72 import static com.google.protobuf.UnittestLite.optionalNestedEnumExtensionLite; 73 import static com.google.protobuf.UnittestLite.optionalNestedMessageExtensionLite; 74 import static com.google.protobuf.UnittestLite.optionalPublicImportMessageExtensionLite; 75 import static com.google.protobuf.UnittestLite.optionalSfixed32ExtensionLite; 76 import static com.google.protobuf.UnittestLite.optionalSfixed64ExtensionLite; 77 import static com.google.protobuf.UnittestLite.optionalSint32ExtensionLite; 78 import static com.google.protobuf.UnittestLite.optionalSint64ExtensionLite; 79 import static com.google.protobuf.UnittestLite.optionalStringExtensionLite; 80 import static com.google.protobuf.UnittestLite.optionalStringPieceExtensionLite; 81 import static com.google.protobuf.UnittestLite.optionalUint32ExtensionLite; 82 import static com.google.protobuf.UnittestLite.optionalUint64ExtensionLite; 83 import static com.google.protobuf.UnittestLite.packedBoolExtensionLite; 84 import static com.google.protobuf.UnittestLite.packedDoubleExtensionLite; 85 import static com.google.protobuf.UnittestLite.packedEnumExtensionLite; 86 import static com.google.protobuf.UnittestLite.packedFixed32ExtensionLite; 87 import static com.google.protobuf.UnittestLite.packedFixed64ExtensionLite; 88 import static com.google.protobuf.UnittestLite.packedFloatExtensionLite; 89 import static com.google.protobuf.UnittestLite.packedInt32ExtensionLite; 90 import static com.google.protobuf.UnittestLite.packedInt64ExtensionLite; 91 import static com.google.protobuf.UnittestLite.packedSfixed32ExtensionLite; 92 import static com.google.protobuf.UnittestLite.packedSfixed64ExtensionLite; 93 import static com.google.protobuf.UnittestLite.packedSint32ExtensionLite; 94 import static com.google.protobuf.UnittestLite.packedSint64ExtensionLite; 95 import static com.google.protobuf.UnittestLite.packedUint32ExtensionLite; 96 import static com.google.protobuf.UnittestLite.packedUint64ExtensionLite; 97 import static com.google.protobuf.UnittestLite.repeatedBoolExtensionLite; 98 import static com.google.protobuf.UnittestLite.repeatedBytesExtensionLite; 99 import static com.google.protobuf.UnittestLite.repeatedCordExtensionLite; 100 import static com.google.protobuf.UnittestLite.repeatedDoubleExtensionLite; 101 import static com.google.protobuf.UnittestLite.repeatedFixed32ExtensionLite; 102 import static com.google.protobuf.UnittestLite.repeatedFixed64ExtensionLite; 103 import static com.google.protobuf.UnittestLite.repeatedFloatExtensionLite; 104 import static com.google.protobuf.UnittestLite.repeatedForeignEnumExtensionLite; 105 import static com.google.protobuf.UnittestLite.repeatedForeignMessageExtensionLite; 106 import static com.google.protobuf.UnittestLite.repeatedGroupExtensionLite; 107 import static com.google.protobuf.UnittestLite.repeatedImportEnumExtensionLite; 108 import static com.google.protobuf.UnittestLite.repeatedImportMessageExtensionLite; 109 import static com.google.protobuf.UnittestLite.repeatedInt32ExtensionLite; 110 import static com.google.protobuf.UnittestLite.repeatedInt64ExtensionLite; 111 import static com.google.protobuf.UnittestLite.repeatedLazyMessageExtensionLite; 112 import static com.google.protobuf.UnittestLite.repeatedNestedEnumExtensionLite; 113 import static com.google.protobuf.UnittestLite.repeatedNestedMessageExtensionLite; 114 import static com.google.protobuf.UnittestLite.repeatedSfixed32ExtensionLite; 115 import static com.google.protobuf.UnittestLite.repeatedSfixed64ExtensionLite; 116 import static com.google.protobuf.UnittestLite.repeatedSint32ExtensionLite; 117 import static com.google.protobuf.UnittestLite.repeatedSint64ExtensionLite; 118 import static com.google.protobuf.UnittestLite.repeatedStringExtensionLite; 119 import static com.google.protobuf.UnittestLite.repeatedStringPieceExtensionLite; 120 import static com.google.protobuf.UnittestLite.repeatedUint32ExtensionLite; 121 import static com.google.protobuf.UnittestLite.repeatedUint64ExtensionLite; 122 123 import com.google.protobuf.UnittestImportLite.ImportEnumLite; 124 import com.google.protobuf.UnittestImportLite.ImportMessageLite; 125 import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite; 126 import com.google.protobuf.UnittestLite.ForeignEnumLite; 127 import com.google.protobuf.UnittestLite.ForeignMessageLite; 128 import com.google.protobuf.UnittestLite.OptionalGroup_extension_lite; 129 import com.google.protobuf.UnittestLite.RepeatedGroup_extension_lite; 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 subpackages. 140 */ 141 public final class TestUtilLite { TestUtilLite()142 private TestUtilLite() {} 143 144 /** Helper to convert a String to ByteString. */ toBytes(String str)145 static ByteString toBytes(String str) { 146 return ByteString.copyFrom(str.getBytes(Internal.UTF_8)); 147 } 148 149 /** 150 * Get a {@code TestAllTypesLite.Builder} with all fields set as they would be by {@link 151 * #setAllFields(TestAllTypesLite.Builder)}. 152 */ getAllLiteSetBuilder()153 public static TestAllTypesLite.Builder getAllLiteSetBuilder() { 154 TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder(); 155 setAllFields(builder); 156 return builder; 157 } 158 159 /** 160 * Get a {@code TestAllExtensionsLite} with all fields set as they would be by {@link 161 * #setAllExtensions(TestAllExtensionsLite.Builder)}. 162 */ getAllLiteExtensionsSet()163 public static TestAllExtensionsLite getAllLiteExtensionsSet() { 164 TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder(); 165 setAllExtensions(builder); 166 return builder.build(); 167 } 168 getLitePackedExtensionsSet()169 public static TestPackedExtensionsLite getLitePackedExtensionsSet() { 170 TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.newBuilder(); 171 setPackedExtensions(builder); 172 return builder.build(); 173 } 174 175 /** Set every field of {@code builder} to the values expected by {@code assertAllFieldsSet()}. */ setAllFields(TestAllTypesLite.Builder builder)176 public static void setAllFields(TestAllTypesLite.Builder builder) { 177 builder.setOptionalInt32(101); 178 builder.setOptionalInt64(102); 179 builder.setOptionalUint32(103); 180 builder.setOptionalUint64(104); 181 builder.setOptionalSint32(105); 182 builder.setOptionalSint64(106); 183 builder.setOptionalFixed32(107); 184 builder.setOptionalFixed64(108); 185 builder.setOptionalSfixed32(109); 186 builder.setOptionalSfixed64(110); 187 builder.setOptionalFloat(111); 188 builder.setOptionalDouble(112); 189 builder.setOptionalBool(true); 190 builder.setOptionalString("115"); 191 builder.setOptionalBytes(toBytes("116")); 192 193 builder.setOptionalGroup(TestAllTypesLite.OptionalGroup.newBuilder().setA(117).build()); 194 builder.setOptionalNestedMessage( 195 TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build()); 196 builder.setOptionalForeignMessage(ForeignMessageLite.newBuilder().setC(119).build()); 197 builder.setOptionalImportMessage(ImportMessageLite.newBuilder().setD(120).build()); 198 builder.setOptionalPublicImportMessage(PublicImportMessageLite.newBuilder().setE(126).build()); 199 builder.setOptionalLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build()); 200 201 builder.setOptionalNestedEnum(TestAllTypesLite.NestedEnum.BAZ); 202 builder.setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ); 203 builder.setOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAZ); 204 205 builder.setOptionalStringPiece("124"); 206 builder.setOptionalCord("125"); 207 208 // ----------------------------------------------------------------- 209 210 builder.addRepeatedInt32(201); 211 builder.addRepeatedInt64(202); 212 builder.addRepeatedUint32(203); 213 builder.addRepeatedUint64(204); 214 builder.addRepeatedSint32(205); 215 builder.addRepeatedSint64(206); 216 builder.addRepeatedFixed32(207); 217 builder.addRepeatedFixed64(208); 218 builder.addRepeatedSfixed32(209); 219 builder.addRepeatedSfixed64(210); 220 builder.addRepeatedFloat(211); 221 builder.addRepeatedDouble(212); 222 builder.addRepeatedBool(true); 223 builder.addRepeatedString("215"); 224 builder.addRepeatedBytes(toBytes("216")); 225 226 builder.addRepeatedGroup(TestAllTypesLite.RepeatedGroup.newBuilder().setA(217).build()); 227 builder.addRepeatedNestedMessage( 228 TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build()); 229 builder.addRepeatedForeignMessage(ForeignMessageLite.newBuilder().setC(219).build()); 230 builder.addRepeatedImportMessage(ImportMessageLite.newBuilder().setD(220).build()); 231 builder.addRepeatedLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build()); 232 233 builder.addRepeatedNestedEnum(TestAllTypesLite.NestedEnum.BAR); 234 builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR); 235 builder.addRepeatedImportEnum(ImportEnumLite.IMPORT_LITE_BAR); 236 237 builder.addRepeatedStringPiece("224"); 238 builder.addRepeatedCord("225"); 239 240 // Add a second one of each field. 241 builder.addRepeatedInt32(301); 242 builder.addRepeatedInt64(302); 243 builder.addRepeatedUint32(303); 244 builder.addRepeatedUint64(304); 245 builder.addRepeatedSint32(305); 246 builder.addRepeatedSint64(306); 247 builder.addRepeatedFixed32(307); 248 builder.addRepeatedFixed64(308); 249 builder.addRepeatedSfixed32(309); 250 builder.addRepeatedSfixed64(310); 251 builder.addRepeatedFloat(311); 252 builder.addRepeatedDouble(312); 253 builder.addRepeatedBool(false); 254 builder.addRepeatedString("315"); 255 builder.addRepeatedBytes(toBytes("316")); 256 257 builder.addRepeatedGroup(TestAllTypesLite.RepeatedGroup.newBuilder().setA(317).build()); 258 builder.addRepeatedNestedMessage( 259 TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build()); 260 builder.addRepeatedForeignMessage(ForeignMessageLite.newBuilder().setC(319).build()); 261 builder.addRepeatedImportMessage(ImportMessageLite.newBuilder().setD(320).build()); 262 builder.addRepeatedLazyMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build()); 263 264 builder.addRepeatedNestedEnum(TestAllTypesLite.NestedEnum.BAZ); 265 builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ); 266 builder.addRepeatedImportEnum(ImportEnumLite.IMPORT_LITE_BAZ); 267 268 builder.addRepeatedStringPiece("324"); 269 builder.addRepeatedCord("325"); 270 271 // ----------------------------------------------------------------- 272 273 builder.setDefaultInt32(401); 274 builder.setDefaultInt64(402); 275 builder.setDefaultUint32(403); 276 builder.setDefaultUint64(404); 277 builder.setDefaultSint32(405); 278 builder.setDefaultSint64(406); 279 builder.setDefaultFixed32(407); 280 builder.setDefaultFixed64(408); 281 builder.setDefaultSfixed32(409); 282 builder.setDefaultSfixed64(410); 283 builder.setDefaultFloat(411); 284 builder.setDefaultDouble(412); 285 builder.setDefaultBool(false); 286 builder.setDefaultString("415"); 287 builder.setDefaultBytes(toBytes("416")); 288 289 builder.setDefaultNestedEnum(TestAllTypesLite.NestedEnum.FOO); 290 builder.setDefaultForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO); 291 builder.setDefaultImportEnum(ImportEnumLite.IMPORT_LITE_FOO); 292 293 builder.setDefaultStringPiece("424"); 294 builder.setDefaultCord("425"); 295 296 builder.setOneofUint32(601); 297 builder.setOneofNestedMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build()); 298 builder.setOneofString("603"); 299 builder.setOneofBytes(toBytes("604")); 300 } 301 302 /** 303 * Get an unmodifiable {@link ExtensionRegistryLite} containing all the extensions of {@code 304 * TestAllExtensionsLite}. 305 */ getExtensionRegistryLite()306 public static ExtensionRegistryLite getExtensionRegistryLite() { 307 ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance(); 308 registerAllExtensionsLite(registry); 309 return registry.getUnmodifiable(); 310 } 311 312 /** 313 * Register all of {@code TestAllExtensionsLite}'s extensions with the given {@link 314 * ExtensionRegistryLite}. 315 */ registerAllExtensionsLite(ExtensionRegistryLite registry)316 public static void registerAllExtensionsLite(ExtensionRegistryLite registry) { 317 UnittestLite.registerAllExtensions(registry); 318 } 319 320 // =================================================================== 321 // Lite extensions 322 323 /** 324 * Set every field of {@code message} to the values expected by {@code assertAllExtensionsSet()}. 325 */ setAllExtensions(TestAllExtensionsLite.Builder message)326 public static void setAllExtensions(TestAllExtensionsLite.Builder message) { 327 message.setExtension(optionalInt32ExtensionLite, 101); 328 message.setExtension(optionalInt64ExtensionLite, 102L); 329 message.setExtension(optionalUint32ExtensionLite, 103); 330 message.setExtension(optionalUint64ExtensionLite, 104L); 331 message.setExtension(optionalSint32ExtensionLite, 105); 332 message.setExtension(optionalSint64ExtensionLite, 106L); 333 message.setExtension(optionalFixed32ExtensionLite, 107); 334 message.setExtension(optionalFixed64ExtensionLite, 108L); 335 message.setExtension(optionalSfixed32ExtensionLite, 109); 336 message.setExtension(optionalSfixed64ExtensionLite, 110L); 337 message.setExtension(optionalFloatExtensionLite, 111F); 338 message.setExtension(optionalDoubleExtensionLite, 112D); 339 message.setExtension(optionalBoolExtensionLite, true); 340 message.setExtension(optionalStringExtensionLite, "115"); 341 message.setExtension(optionalBytesExtensionLite, toBytes("116")); 342 343 message.setExtension( 344 optionalGroupExtensionLite, OptionalGroup_extension_lite.newBuilder().setA(117).build()); 345 message.setExtension( 346 optionalNestedMessageExtensionLite, 347 TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build()); 348 message.setExtension( 349 optionalForeignMessageExtensionLite, ForeignMessageLite.newBuilder().setC(119).build()); 350 message.setExtension( 351 optionalImportMessageExtensionLite, ImportMessageLite.newBuilder().setD(120).build()); 352 message.setExtension( 353 optionalPublicImportMessageExtensionLite, 354 PublicImportMessageLite.newBuilder().setE(126).build()); 355 message.setExtension( 356 optionalLazyMessageExtensionLite, 357 TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build()); 358 359 message.setExtension(optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ); 360 message.setExtension(optionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 361 message.setExtension(optionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ); 362 363 message.setExtension(optionalStringPieceExtensionLite, "124"); 364 message.setExtension(optionalCordExtensionLite, "125"); 365 366 // ----------------------------------------------------------------- 367 368 message.addExtension(repeatedInt32ExtensionLite, 201); 369 message.addExtension(repeatedInt64ExtensionLite, 202L); 370 message.addExtension(repeatedUint32ExtensionLite, 203); 371 message.addExtension(repeatedUint64ExtensionLite, 204L); 372 message.addExtension(repeatedSint32ExtensionLite, 205); 373 message.addExtension(repeatedSint64ExtensionLite, 206L); 374 message.addExtension(repeatedFixed32ExtensionLite, 207); 375 message.addExtension(repeatedFixed64ExtensionLite, 208L); 376 message.addExtension(repeatedSfixed32ExtensionLite, 209); 377 message.addExtension(repeatedSfixed64ExtensionLite, 210L); 378 message.addExtension(repeatedFloatExtensionLite, 211F); 379 message.addExtension(repeatedDoubleExtensionLite, 212D); 380 message.addExtension(repeatedBoolExtensionLite, true); 381 message.addExtension(repeatedStringExtensionLite, "215"); 382 message.addExtension(repeatedBytesExtensionLite, toBytes("216")); 383 384 message.addExtension( 385 repeatedGroupExtensionLite, RepeatedGroup_extension_lite.newBuilder().setA(217).build()); 386 message.addExtension( 387 repeatedNestedMessageExtensionLite, 388 TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build()); 389 message.addExtension( 390 repeatedForeignMessageExtensionLite, ForeignMessageLite.newBuilder().setC(219).build()); 391 message.addExtension( 392 repeatedImportMessageExtensionLite, ImportMessageLite.newBuilder().setD(220).build()); 393 message.addExtension( 394 repeatedLazyMessageExtensionLite, 395 TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build()); 396 397 message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAR); 398 message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); 399 message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAR); 400 401 message.addExtension(repeatedStringPieceExtensionLite, "224"); 402 message.addExtension(repeatedCordExtensionLite, "225"); 403 404 // Add a second one of each field. 405 message.addExtension(repeatedInt32ExtensionLite, 301); 406 message.addExtension(repeatedInt64ExtensionLite, 302L); 407 message.addExtension(repeatedUint32ExtensionLite, 303); 408 message.addExtension(repeatedUint64ExtensionLite, 304L); 409 message.addExtension(repeatedSint32ExtensionLite, 305); 410 message.addExtension(repeatedSint64ExtensionLite, 306L); 411 message.addExtension(repeatedFixed32ExtensionLite, 307); 412 message.addExtension(repeatedFixed64ExtensionLite, 308L); 413 message.addExtension(repeatedSfixed32ExtensionLite, 309); 414 message.addExtension(repeatedSfixed64ExtensionLite, 310L); 415 message.addExtension(repeatedFloatExtensionLite, 311F); 416 message.addExtension(repeatedDoubleExtensionLite, 312D); 417 message.addExtension(repeatedBoolExtensionLite, false); 418 message.addExtension(repeatedStringExtensionLite, "315"); 419 message.addExtension(repeatedBytesExtensionLite, toBytes("316")); 420 421 message.addExtension( 422 repeatedGroupExtensionLite, RepeatedGroup_extension_lite.newBuilder().setA(317).build()); 423 message.addExtension( 424 repeatedNestedMessageExtensionLite, 425 TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build()); 426 message.addExtension( 427 repeatedForeignMessageExtensionLite, ForeignMessageLite.newBuilder().setC(319).build()); 428 message.addExtension( 429 repeatedImportMessageExtensionLite, ImportMessageLite.newBuilder().setD(320).build()); 430 message.addExtension( 431 repeatedLazyMessageExtensionLite, 432 TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build()); 433 434 message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ); 435 message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 436 message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ); 437 438 message.addExtension(repeatedStringPieceExtensionLite, "324"); 439 message.addExtension(repeatedCordExtensionLite, "325"); 440 441 // ----------------------------------------------------------------- 442 443 message.setExtension(defaultInt32ExtensionLite, 401); 444 message.setExtension(defaultInt64ExtensionLite, 402L); 445 message.setExtension(defaultUint32ExtensionLite, 403); 446 message.setExtension(defaultUint64ExtensionLite, 404L); 447 message.setExtension(defaultSint32ExtensionLite, 405); 448 message.setExtension(defaultSint64ExtensionLite, 406L); 449 message.setExtension(defaultFixed32ExtensionLite, 407); 450 message.setExtension(defaultFixed64ExtensionLite, 408L); 451 message.setExtension(defaultSfixed32ExtensionLite, 409); 452 message.setExtension(defaultSfixed64ExtensionLite, 410L); 453 message.setExtension(defaultFloatExtensionLite, 411F); 454 message.setExtension(defaultDoubleExtensionLite, 412D); 455 message.setExtension(defaultBoolExtensionLite, false); 456 message.setExtension(defaultStringExtensionLite, "415"); 457 message.setExtension(defaultBytesExtensionLite, toBytes("416")); 458 459 message.setExtension(defaultNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.FOO); 460 message.setExtension(defaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_FOO); 461 message.setExtension(defaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_FOO); 462 463 message.setExtension(defaultStringPieceExtensionLite, "424"); 464 message.setExtension(defaultCordExtensionLite, "425"); 465 466 message.setExtension(oneofUint32ExtensionLite, 601); 467 message.setExtension( 468 oneofNestedMessageExtensionLite, 469 TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build()); 470 message.setExtension(oneofStringExtensionLite, "603"); 471 message.setExtension(oneofBytesExtensionLite, toBytes("604")); 472 } 473 474 // ------------------------------------------------------------------- 475 476 /** 477 * Modify the repeated extensions of {@code message} to contain the values expected by {@code 478 * assertRepeatedExtensionsModified()}. 479 */ modifyRepeatedExtensions(TestAllExtensionsLite.Builder message)480 public static void modifyRepeatedExtensions(TestAllExtensionsLite.Builder message) { 481 message.setExtension(repeatedInt32ExtensionLite, 1, 501); 482 message.setExtension(repeatedInt64ExtensionLite, 1, 502L); 483 message.setExtension(repeatedUint32ExtensionLite, 1, 503); 484 message.setExtension(repeatedUint64ExtensionLite, 1, 504L); 485 message.setExtension(repeatedSint32ExtensionLite, 1, 505); 486 message.setExtension(repeatedSint64ExtensionLite, 1, 506L); 487 message.setExtension(repeatedFixed32ExtensionLite, 1, 507); 488 message.setExtension(repeatedFixed64ExtensionLite, 1, 508L); 489 message.setExtension(repeatedSfixed32ExtensionLite, 1, 509); 490 message.setExtension(repeatedSfixed64ExtensionLite, 1, 510L); 491 message.setExtension(repeatedFloatExtensionLite, 1, 511F); 492 message.setExtension(repeatedDoubleExtensionLite, 1, 512D); 493 message.setExtension(repeatedBoolExtensionLite, 1, true); 494 message.setExtension(repeatedStringExtensionLite, 1, "515"); 495 message.setExtension(repeatedBytesExtensionLite, 1, toBytes("516")); 496 497 message.setExtension( 498 repeatedGroupExtensionLite, 1, RepeatedGroup_extension_lite.newBuilder().setA(517).build()); 499 message.setExtension( 500 repeatedNestedMessageExtensionLite, 501 1, 502 TestAllTypesLite.NestedMessage.newBuilder().setBb(518).build()); 503 message.setExtension( 504 repeatedForeignMessageExtensionLite, 1, ForeignMessageLite.newBuilder().setC(519).build()); 505 message.setExtension( 506 repeatedImportMessageExtensionLite, 1, ImportMessageLite.newBuilder().setD(520).build()); 507 message.setExtension( 508 repeatedLazyMessageExtensionLite, 509 1, 510 TestAllTypesLite.NestedMessage.newBuilder().setBb(527).build()); 511 512 message.setExtension(repeatedNestedEnumExtensionLite, 1, TestAllTypesLite.NestedEnum.FOO); 513 message.setExtension(repeatedForeignEnumExtensionLite, 1, ForeignEnumLite.FOREIGN_LITE_FOO); 514 message.setExtension(repeatedImportEnumExtensionLite, 1, ImportEnumLite.IMPORT_LITE_FOO); 515 516 message.setExtension(repeatedStringPieceExtensionLite, 1, "524"); 517 message.setExtension(repeatedCordExtensionLite, 1, "525"); 518 } 519 setPackedExtensions(TestPackedExtensionsLite.Builder message)520 public static void setPackedExtensions(TestPackedExtensionsLite.Builder message) { 521 message.addExtension(packedInt32ExtensionLite, 601); 522 message.addExtension(packedInt64ExtensionLite, 602L); 523 message.addExtension(packedUint32ExtensionLite, 603); 524 message.addExtension(packedUint64ExtensionLite, 604L); 525 message.addExtension(packedSint32ExtensionLite, 605); 526 message.addExtension(packedSint64ExtensionLite, 606L); 527 message.addExtension(packedFixed32ExtensionLite, 607); 528 message.addExtension(packedFixed64ExtensionLite, 608L); 529 message.addExtension(packedSfixed32ExtensionLite, 609); 530 message.addExtension(packedSfixed64ExtensionLite, 610L); 531 message.addExtension(packedFloatExtensionLite, 611F); 532 message.addExtension(packedDoubleExtensionLite, 612D); 533 message.addExtension(packedBoolExtensionLite, true); 534 message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); 535 // Add a second one of each field. 536 message.addExtension(packedInt32ExtensionLite, 701); 537 message.addExtension(packedInt64ExtensionLite, 702L); 538 message.addExtension(packedUint32ExtensionLite, 703); 539 message.addExtension(packedUint64ExtensionLite, 704L); 540 message.addExtension(packedSint32ExtensionLite, 705); 541 message.addExtension(packedSint64ExtensionLite, 706L); 542 message.addExtension(packedFixed32ExtensionLite, 707); 543 message.addExtension(packedFixed64ExtensionLite, 708L); 544 message.addExtension(packedSfixed32ExtensionLite, 709); 545 message.addExtension(packedSfixed64ExtensionLite, 710L); 546 message.addExtension(packedFloatExtensionLite, 711F); 547 message.addExtension(packedDoubleExtensionLite, 712D); 548 message.addExtension(packedBoolExtensionLite, false); 549 message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); 550 } 551 } 552