1#region Copyright notice and license 2// Protocol Buffers - Google's data interchange format 3// Copyright 2015 Google Inc. All rights reserved. 4// https://developers.google.com/protocol-buffers/ 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: 9// 10// * Redistributions of source code must retain the above copyright 11// notice, this list of conditions and the following disclaimer. 12// * Redistributions in binary form must reproduce the above 13// copyright notice, this list of conditions and the following disclaimer 14// in the documentation and/or other materials provided with the 15// distribution. 16// * Neither the name of Google Inc. nor the names of its 17// contributors may be used to endorse or promote products derived from 18// this software without specific prior written permission. 19// 20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31#endregion 32 33using System; 34using Google.Protobuf.TestProtos; 35 36namespace Google.Protobuf 37{ 38 /// <summary> 39 /// Helper methods to create sample instances of types generated from unit test messages. 40 /// </summary> 41 public class SampleMessages 42 { 43 /// <summary> 44 /// Creates a new sample TestAllTypes message with all fields populated. 45 /// The "oneof" field is populated with the string property (OneofString). 46 /// </summary> 47 public static TestAllTypes CreateFullTestAllTypes() 48 { 49 return new TestAllTypes 50 { 51 SingleBool = true, 52 SingleBytes = ByteString.CopyFrom(1, 2, 3, 4), 53 SingleDouble = 23.5, 54 SingleFixed32 = 23, 55 SingleFixed64 = 1234567890123, 56 SingleFloat = 12.25f, 57 SingleForeignEnum = ForeignEnum.ForeignBar, 58 SingleForeignMessage = new ForeignMessage { C = 10 }, 59 SingleImportEnum = ImportEnum.ImportBaz, 60 SingleImportMessage = new ImportMessage { D = 20 }, 61 SingleInt32 = 100, 62 SingleInt64 = 3210987654321, 63 SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo, 64 SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 }, 65 SinglePublicImportMessage = new PublicImportMessage { E = 54 }, 66 SingleSfixed32 = -123, 67 SingleSfixed64 = -12345678901234, 68 SingleSint32 = -456, 69 SingleSint64 = -12345678901235, 70 SingleString = "test", 71 SingleUint32 = UInt32.MaxValue, 72 SingleUint64 = UInt64.MaxValue, 73 RepeatedBool = { true, false }, 74 RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) }, 75 RepeatedDouble = { -12.25, 23.5 }, 76 RepeatedFixed32 = { UInt32.MaxValue, 23 }, 77 RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 }, 78 RepeatedFloat = { 100f, 12.25f }, 79 RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar }, 80 RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } }, 81 RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified }, 82 RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } }, 83 RepeatedInt32 = { 100, 200 }, 84 RepeatedInt64 = { 3210987654321, Int64.MaxValue }, 85 RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg }, 86 RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } }, 87 RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } }, 88 RepeatedSfixed32 = { -123, 123 }, 89 RepeatedSfixed64 = { -12345678901234, 12345678901234 }, 90 RepeatedSint32 = { -456, 100 }, 91 RepeatedSint64 = { -12345678901235, 123 }, 92 RepeatedString = { "foo", "bar" }, 93 RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue }, 94 RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue }, 95 OneofString = "Oneof string" 96 }; 97 } 98 } 99}