• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using System;
11 using Google.Protobuf.TestProtos;
12 
13 namespace Google.Protobuf
14 {
15     /// <summary>
16     /// Helper methods to create sample instances of types generated from unit test messages.
17     /// </summary>
18     public class SampleMessages
19     {
20         /// <summary>
21         /// Creates a new sample TestAllTypes message with all fields populated.
22         /// The "oneof" field is populated with the string property (OneofString).
23         /// </summary>
CreateFullTestAllTypes()24         public static TestAllTypes CreateFullTestAllTypes()
25         {
26             return new TestAllTypes
27             {
28                 SingleBool = true,
29                 SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
30                 SingleDouble = 23.5,
31                 SingleFixed32 = 23,
32                 SingleFixed64 = 1234567890123,
33                 SingleFloat = 12.25f,
34                 SingleForeignEnum = ForeignEnum.ForeignBar,
35                 SingleForeignMessage = new ForeignMessage { C = 10 },
36                 SingleImportEnum = ImportEnum.ImportBaz,
37                 SingleImportMessage = new ImportMessage { D = 20 },
38                 SingleInt32 = 100,
39                 SingleInt64 = 3210987654321,
40                 SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
41                 SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
42                 SinglePublicImportMessage = new PublicImportMessage { E = 54 },
43                 SingleSfixed32 = -123,
44                 SingleSfixed64 = -12345678901234,
45                 SingleSint32 = -456,
46                 SingleSint64 = -12345678901235,
47                 SingleString = "test",
48                 SingleUint32 = UInt32.MaxValue,
49                 SingleUint64 = UInt64.MaxValue,
50                 RepeatedBool = { true, false },
51                 RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) },
52                 RepeatedDouble = { -12.25, 23.5 },
53                 RepeatedFixed32 = { UInt32.MaxValue, 23 },
54                 RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 },
55                 RepeatedFloat = { 100f, 12.25f },
56                 RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
57                 RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
58                 RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
59                 RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
60                 RepeatedInt32 = { 100, 200 },
61                 RepeatedInt64 = { 3210987654321, Int64.MaxValue },
62                 RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
63                 RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
64                 RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
65                 RepeatedSfixed32 = { -123, 123 },
66                 RepeatedSfixed64 = { -12345678901234, 12345678901234 },
67                 RepeatedSint32 = { -456, 100 },
68                 RepeatedSint64 = { -12345678901235, 123 },
69                 RepeatedString = { "foo", "bar" },
70                 RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue },
71                 RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue },
72                 OneofString = "Oneof string"
73             };
74         }
75     }
76 }