1ffe3c632Sopenharmony_ci#region Copyright notice and license 2ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format 3ffe3c632Sopenharmony_ci// Copyright 2015 Google Inc. All rights reserved. 4ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/ 5ffe3c632Sopenharmony_ci// 6ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 7ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are 8ffe3c632Sopenharmony_ci// met: 9ffe3c632Sopenharmony_ci// 10ffe3c632Sopenharmony_ci// * Redistributions of source code must retain the above copyright 11ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 12ffe3c632Sopenharmony_ci// * Redistributions in binary form must reproduce the above 13ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 14ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the 15ffe3c632Sopenharmony_ci// distribution. 16ffe3c632Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 17ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from 18ffe3c632Sopenharmony_ci// this software without specific prior written permission. 19ffe3c632Sopenharmony_ci// 20ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31ffe3c632Sopenharmony_ci#endregion 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_ciusing System; 34ffe3c632Sopenharmony_ciusing Google.Protobuf.TestProtos; 35ffe3c632Sopenharmony_ciusing Proto2 = Google.Protobuf.TestProtos.Proto2; 36ffe3c632Sopenharmony_ci 37ffe3c632Sopenharmony_ciusing static Google.Protobuf.TestProtos.Proto2.UnittestExtensions; 38ffe3c632Sopenharmony_ci 39ffe3c632Sopenharmony_cinamespace Google.Protobuf 40ffe3c632Sopenharmony_ci{ 41ffe3c632Sopenharmony_ci /// <summary> 42ffe3c632Sopenharmony_ci /// Helper methods to create sample instances of types generated from unit test messages. 43ffe3c632Sopenharmony_ci /// </summary> 44ffe3c632Sopenharmony_ci public class SampleMessages 45ffe3c632Sopenharmony_ci { 46ffe3c632Sopenharmony_ci /// <summary> 47ffe3c632Sopenharmony_ci /// Creates a new sample TestAllTypes message with all fields populated. 48ffe3c632Sopenharmony_ci /// The "oneof" field is populated with the string property (OneofString). 49ffe3c632Sopenharmony_ci /// </summary> 50ffe3c632Sopenharmony_ci public static TestAllTypes CreateFullTestAllTypes() 51ffe3c632Sopenharmony_ci { 52ffe3c632Sopenharmony_ci return new TestAllTypes 53ffe3c632Sopenharmony_ci { 54ffe3c632Sopenharmony_ci SingleBool = true, 55ffe3c632Sopenharmony_ci SingleBytes = ByteString.CopyFrom(1, 2, 3, 4), 56ffe3c632Sopenharmony_ci SingleDouble = 23.5, 57ffe3c632Sopenharmony_ci SingleFixed32 = 23, 58ffe3c632Sopenharmony_ci SingleFixed64 = 1234567890123, 59ffe3c632Sopenharmony_ci SingleFloat = 12.25f, 60ffe3c632Sopenharmony_ci SingleForeignEnum = ForeignEnum.ForeignBar, 61ffe3c632Sopenharmony_ci SingleForeignMessage = new ForeignMessage { C = 10 }, 62ffe3c632Sopenharmony_ci SingleImportEnum = ImportEnum.ImportBaz, 63ffe3c632Sopenharmony_ci SingleImportMessage = new ImportMessage { D = 20 }, 64ffe3c632Sopenharmony_ci SingleInt32 = 100, 65ffe3c632Sopenharmony_ci SingleInt64 = 3210987654321, 66ffe3c632Sopenharmony_ci SingleNestedEnum = TestProtos.TestAllTypes.Types.NestedEnum.Foo, 67ffe3c632Sopenharmony_ci SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 }, 68ffe3c632Sopenharmony_ci SinglePublicImportMessage = new PublicImportMessage { E = 54 }, 69ffe3c632Sopenharmony_ci SingleSfixed32 = -123, 70ffe3c632Sopenharmony_ci SingleSfixed64 = -12345678901234, 71ffe3c632Sopenharmony_ci SingleSint32 = -456, 72ffe3c632Sopenharmony_ci SingleSint64 = -12345678901235, 73ffe3c632Sopenharmony_ci SingleString = "test", 74ffe3c632Sopenharmony_ci SingleUint32 = UInt32.MaxValue, 75ffe3c632Sopenharmony_ci SingleUint64 = UInt64.MaxValue, 76ffe3c632Sopenharmony_ci RepeatedBool = { true, false }, 77ffe3c632Sopenharmony_ci RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) }, 78ffe3c632Sopenharmony_ci RepeatedDouble = { -12.25, 23.5 }, 79ffe3c632Sopenharmony_ci RepeatedFixed32 = { UInt32.MaxValue, 23 }, 80ffe3c632Sopenharmony_ci RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 }, 81ffe3c632Sopenharmony_ci RepeatedFloat = { 100f, 12.25f }, 82ffe3c632Sopenharmony_ci RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar }, 83ffe3c632Sopenharmony_ci RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } }, 84ffe3c632Sopenharmony_ci RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified }, 85ffe3c632Sopenharmony_ci RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } }, 86ffe3c632Sopenharmony_ci RepeatedInt32 = { 100, 200 }, 87ffe3c632Sopenharmony_ci RepeatedInt64 = { 3210987654321, Int64.MaxValue }, 88ffe3c632Sopenharmony_ci RepeatedNestedEnum = { TestProtos.TestAllTypes.Types.NestedEnum.Foo, TestProtos.TestAllTypes.Types.NestedEnum.Neg }, 89ffe3c632Sopenharmony_ci RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } }, 90ffe3c632Sopenharmony_ci RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } }, 91ffe3c632Sopenharmony_ci RepeatedSfixed32 = { -123, 123 }, 92ffe3c632Sopenharmony_ci RepeatedSfixed64 = { -12345678901234, 12345678901234 }, 93ffe3c632Sopenharmony_ci RepeatedSint32 = { -456, 100 }, 94ffe3c632Sopenharmony_ci RepeatedSint64 = { -12345678901235, 123 }, 95ffe3c632Sopenharmony_ci RepeatedString = { "foo", "bar" }, 96ffe3c632Sopenharmony_ci RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue }, 97ffe3c632Sopenharmony_ci RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue }, 98ffe3c632Sopenharmony_ci OneofString = "Oneof string" 99ffe3c632Sopenharmony_ci }; 100ffe3c632Sopenharmony_ci } 101ffe3c632Sopenharmony_ci 102ffe3c632Sopenharmony_ci public static Proto2.TestAllTypes CreateFullTestAllTypesProto2() 103ffe3c632Sopenharmony_ci { 104ffe3c632Sopenharmony_ci return new Proto2.TestAllTypes 105ffe3c632Sopenharmony_ci { 106ffe3c632Sopenharmony_ci OptionalBool = true, 107ffe3c632Sopenharmony_ci OptionalBytes = ByteString.CopyFrom(1, 2, 3, 4), 108ffe3c632Sopenharmony_ci OptionalDouble = 23.5, 109ffe3c632Sopenharmony_ci OptionalFixed32 = 23, 110ffe3c632Sopenharmony_ci OptionalFixed64 = 1234567890123, 111ffe3c632Sopenharmony_ci OptionalFloat = 12.25f, 112ffe3c632Sopenharmony_ci OptionalForeignEnum = Proto2.ForeignEnum.ForeignBar, 113ffe3c632Sopenharmony_ci OptionalForeignMessage = new Proto2.ForeignMessage { C = 10 }, 114ffe3c632Sopenharmony_ci OptionalImportEnum = Proto2.ImportEnum.ImportBaz, 115ffe3c632Sopenharmony_ci OptionalImportMessage = new Proto2.ImportMessage { D = 20 }, 116ffe3c632Sopenharmony_ci OptionalInt32 = 100, 117ffe3c632Sopenharmony_ci OptionalInt64 = 3210987654321, 118ffe3c632Sopenharmony_ci OptionalNestedEnum = Proto2.TestAllTypes.Types.NestedEnum.Foo, 119ffe3c632Sopenharmony_ci OptionalNestedMessage = new Proto2.TestAllTypes.Types.NestedMessage { Bb = 35 }, 120ffe3c632Sopenharmony_ci OptionalPublicImportMessage = new Proto2.PublicImportMessage { E = 54 }, 121ffe3c632Sopenharmony_ci OptionalSfixed32 = -123, 122ffe3c632Sopenharmony_ci OptionalSfixed64 = -12345678901234, 123ffe3c632Sopenharmony_ci OptionalSint32 = -456, 124ffe3c632Sopenharmony_ci OptionalSint64 = -12345678901235, 125ffe3c632Sopenharmony_ci OptionalString = "test", 126ffe3c632Sopenharmony_ci OptionalUint32 = UInt32.MaxValue, 127ffe3c632Sopenharmony_ci OptionalUint64 = UInt64.MaxValue, 128ffe3c632Sopenharmony_ci OptionalGroup = new Proto2.TestAllTypes.Types.OptionalGroup { A = 10 }, 129ffe3c632Sopenharmony_ci RepeatedBool = { true, false }, 130ffe3c632Sopenharmony_ci RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) }, 131ffe3c632Sopenharmony_ci RepeatedDouble = { -12.25, 23.5 }, 132ffe3c632Sopenharmony_ci RepeatedFixed32 = { UInt32.MaxValue, 23 }, 133ffe3c632Sopenharmony_ci RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 }, 134ffe3c632Sopenharmony_ci RepeatedFloat = { 100f, 12.25f }, 135ffe3c632Sopenharmony_ci RepeatedForeignEnum = { Proto2.ForeignEnum.ForeignFoo, Proto2.ForeignEnum.ForeignBar }, 136ffe3c632Sopenharmony_ci RepeatedForeignMessage = { new Proto2.ForeignMessage(), new Proto2.ForeignMessage { C = 10 } }, 137ffe3c632Sopenharmony_ci RepeatedImportEnum = { Proto2.ImportEnum.ImportBaz, Proto2.ImportEnum.ImportFoo }, 138ffe3c632Sopenharmony_ci RepeatedImportMessage = { new Proto2.ImportMessage { D = 20 }, new Proto2.ImportMessage { D = 25 } }, 139ffe3c632Sopenharmony_ci RepeatedInt32 = { 100, 200 }, 140ffe3c632Sopenharmony_ci RepeatedInt64 = { 3210987654321, Int64.MaxValue }, 141ffe3c632Sopenharmony_ci RepeatedNestedEnum = { Proto2.TestAllTypes.Types.NestedEnum.Foo, Proto2.TestAllTypes.Types.NestedEnum.Neg }, 142ffe3c632Sopenharmony_ci RepeatedNestedMessage = { new Proto2.TestAllTypes.Types.NestedMessage { Bb = 35 }, new Proto2.TestAllTypes.Types.NestedMessage { Bb = 10 } }, 143ffe3c632Sopenharmony_ci RepeatedSfixed32 = { -123, 123 }, 144ffe3c632Sopenharmony_ci RepeatedSfixed64 = { -12345678901234, 12345678901234 }, 145ffe3c632Sopenharmony_ci RepeatedSint32 = { -456, 100 }, 146ffe3c632Sopenharmony_ci RepeatedSint64 = { -12345678901235, 123 }, 147ffe3c632Sopenharmony_ci RepeatedString = { "foo", "bar" }, 148ffe3c632Sopenharmony_ci RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue }, 149ffe3c632Sopenharmony_ci RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue }, 150ffe3c632Sopenharmony_ci RepeatedGroup = { new Proto2.TestAllTypes.Types.RepeatedGroup { A = 10 }, new Proto2.TestAllTypes.Types.RepeatedGroup { A = 20 } }, 151ffe3c632Sopenharmony_ci OneofString = "Oneof string" 152ffe3c632Sopenharmony_ci }; 153ffe3c632Sopenharmony_ci } 154ffe3c632Sopenharmony_ci 155ffe3c632Sopenharmony_ci public static Proto2.TestAllExtensions CreateFullTestAllExtensions() 156ffe3c632Sopenharmony_ci { 157ffe3c632Sopenharmony_ci var message = new Proto2.TestAllExtensions(); 158ffe3c632Sopenharmony_ci message.SetExtension(OptionalBoolExtension, true); 159ffe3c632Sopenharmony_ci message.SetExtension(OptionalBytesExtension, ByteString.CopyFrom(1, 2, 3, 4)); 160ffe3c632Sopenharmony_ci message.SetExtension(OptionalDoubleExtension, 23.5); 161ffe3c632Sopenharmony_ci message.SetExtension(OptionalFixed32Extension, 23u); 162ffe3c632Sopenharmony_ci message.SetExtension(OptionalFixed64Extension, 1234567890123u); 163ffe3c632Sopenharmony_ci message.SetExtension(OptionalFloatExtension, 12.25f); 164ffe3c632Sopenharmony_ci message.SetExtension(OptionalForeignEnumExtension, Proto2.ForeignEnum.ForeignBar); 165ffe3c632Sopenharmony_ci message.SetExtension(OptionalForeignMessageExtension, new Proto2.ForeignMessage { C = 10 }); 166ffe3c632Sopenharmony_ci message.SetExtension(OptionalImportEnumExtension, Proto2.ImportEnum.ImportBaz); 167ffe3c632Sopenharmony_ci message.SetExtension(OptionalImportMessageExtension, new Proto2.ImportMessage { D = 20 }); 168ffe3c632Sopenharmony_ci message.SetExtension(OptionalInt32Extension, 100); 169ffe3c632Sopenharmony_ci message.SetExtension(OptionalInt64Extension, 3210987654321); 170ffe3c632Sopenharmony_ci message.SetExtension(OptionalNestedEnumExtension, Proto2.TestAllTypes.Types.NestedEnum.Foo); 171ffe3c632Sopenharmony_ci message.SetExtension(OptionalNestedMessageExtension, new Proto2.TestAllTypes.Types.NestedMessage { Bb = 35 }); 172ffe3c632Sopenharmony_ci message.SetExtension(OptionalPublicImportMessageExtension, new Proto2.PublicImportMessage { E = 54 }); 173ffe3c632Sopenharmony_ci message.SetExtension(OptionalSfixed32Extension, -123); 174ffe3c632Sopenharmony_ci message.SetExtension(OptionalSfixed64Extension, -12345678901234); 175ffe3c632Sopenharmony_ci message.SetExtension(OptionalSint32Extension, -456); 176ffe3c632Sopenharmony_ci message.SetExtension(OptionalSint64Extension, -12345678901235); 177ffe3c632Sopenharmony_ci message.SetExtension(OptionalStringExtension, "test"); 178ffe3c632Sopenharmony_ci message.SetExtension(OptionalUint32Extension, UInt32.MaxValue); 179ffe3c632Sopenharmony_ci message.SetExtension(OptionalUint64Extension, UInt64.MaxValue); 180ffe3c632Sopenharmony_ci message.SetExtension(OptionalGroupExtension, new Proto2.OptionalGroup_extension { A = 10 }); 181ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedBoolExtension).AddRange(new[] { true, false }); 182ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedBytesExtension).AddRange(new[] { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) }); 183ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedDoubleExtension).AddRange(new[] { -12.25, 23.5 }); 184ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedFixed32Extension).AddRange(new[] { UInt32.MaxValue, 23u }); 185ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedFixed64Extension).AddRange(new[] { UInt64.MaxValue, 1234567890123ul }); 186ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedFloatExtension).AddRange(new[] { 100f, 12.25f }); 187ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedForeignEnumExtension).AddRange(new[] { Proto2.ForeignEnum.ForeignFoo, Proto2.ForeignEnum.ForeignBar }); 188ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedForeignMessageExtension).AddRange(new[] { new Proto2.ForeignMessage(), new Proto2.ForeignMessage { C = 10 } }); 189ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedImportEnumExtension).AddRange(new[] { Proto2.ImportEnum.ImportBaz, Proto2.ImportEnum.ImportFoo }); 190ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedImportMessageExtension).AddRange(new[] { new Proto2.ImportMessage { D = 20 }, new Proto2.ImportMessage { D = 25 } }); 191ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedInt32Extension).AddRange(new[] { 100, 200 }); 192ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedInt64Extension).AddRange(new[] { 3210987654321, Int64.MaxValue }); 193ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedNestedEnumExtension).AddRange(new[] { Proto2.TestAllTypes.Types.NestedEnum.Foo, Proto2.TestAllTypes.Types.NestedEnum.Neg }); 194ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedNestedMessageExtension).AddRange(new[] { new Proto2.TestAllTypes.Types.NestedMessage { Bb = 35 }, new Proto2.TestAllTypes.Types.NestedMessage { Bb = 10 } }); 195ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedSfixed32Extension).AddRange(new[] { -123, 123 }); 196ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedSfixed64Extension).AddRange(new[] { -12345678901234, 12345678901234 }); 197ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedSint32Extension).AddRange(new[] { -456, 100 }); 198ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedSint64Extension).AddRange(new[] { -12345678901235, 123 }); 199ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedStringExtension).AddRange(new[] { "foo", "bar" }); 200ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedUint32Extension).AddRange(new[] { UInt32.MaxValue, UInt32.MinValue }); 201ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedUint64Extension).AddRange(new[] { UInt64.MaxValue, UInt32.MinValue }); 202ffe3c632Sopenharmony_ci message.GetOrInitializeExtension(RepeatedGroupExtension).AddRange(new[] { new Proto2.RepeatedGroup_extension { A = 10 }, new Proto2.RepeatedGroup_extension { A = 20 } }); 203ffe3c632Sopenharmony_ci message.SetExtension(OneofStringExtension, "Oneof string"); 204ffe3c632Sopenharmony_ci return message; 205ffe3c632Sopenharmony_ci } 206ffe3c632Sopenharmony_ci } 207ffe3c632Sopenharmony_ci}