blob: ffa4e2a7c27d2aa6d336bfe7f1e568cdfce10eed [file] [log] [blame]
Jon Skeet3cce11c2015-07-09 08:12:44 +01001#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,
Jon Skeet84ea2c72016-04-08 12:33:09 +010057 SingleForeignEnum = ForeignEnum.ForeignBar,
Jon Skeet3cce11c2015-07-09 08:12:44 +010058 SingleForeignMessage = new ForeignMessage { C = 10 },
Jon Skeet84ea2c72016-04-08 12:33:09 +010059 SingleImportEnum = ImportEnum.ImportBaz,
Jon Skeet3cce11c2015-07-09 08:12:44 +010060 SingleImportMessage = new ImportMessage { D = 20 },
61 SingleInt32 = 100,
62 SingleInt64 = 3210987654321,
Jon Skeet84ea2c72016-04-08 12:33:09 +010063 SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
Jon Skeet3cce11c2015-07-09 08:12:44 +010064 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 },
Jon Skeet84ea2c72016-04-08 12:33:09 +010079 RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
Jon Skeet3cce11c2015-07-09 08:12:44 +010080 RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
Jon Skeet84ea2c72016-04-08 12:33:09 +010081 RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
Jon Skeet3cce11c2015-07-09 08:12:44 +010082 RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
83 RepeatedInt32 = { 100, 200 },
84 RepeatedInt64 = { 3210987654321, Int64.MaxValue },
Jon Skeet84ea2c72016-04-08 12:33:09 +010085 RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
Jon Skeet3cce11c2015-07-09 08:12:44 +010086 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 },
Jon Skeet84ea2c72016-04-08 12:33:09 +010095 OneofString = "Oneof string"
Jon Skeet3cce11c2015-07-09 08:12:44 +010096 };
97 }
98 }
Jon Skeet84ea2c72016-04-08 12:33:09 +010099}