SampleMessages.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. using System;
  33. using Google.Protobuf.TestProtos;
  34. namespace Google.Protobuf
  35. {
  36. /// <summary>
  37. /// Helper methods to create sample instances of types generated from unit test messages.
  38. /// </summary>
  39. public class SampleMessages
  40. {
  41. /// <summary>
  42. /// Creates a new sample TestAllTypes message with all fields populated.
  43. /// The "oneof" field is populated with the string property (OneofString).
  44. /// </summary>
  45. public static TestAllTypes CreateFullTestAllTypes()
  46. {
  47. return new TestAllTypes
  48. {
  49. SingleBool = true,
  50. SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
  51. SingleDouble = 23.5,
  52. SingleFixed32 = 23,
  53. SingleFixed64 = 1234567890123,
  54. SingleFloat = 12.25f,
  55. SingleForeignEnum = ForeignEnum.ForeignBar,
  56. SingleForeignMessage = new ForeignMessage { C = 10 },
  57. SingleImportEnum = ImportEnum.ImportBaz,
  58. SingleImportMessage = new ImportMessage { D = 20 },
  59. SingleInt32 = 100,
  60. SingleInt64 = 3210987654321,
  61. SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
  62. SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
  63. SinglePublicImportMessage = new PublicImportMessage { E = 54 },
  64. SingleSfixed32 = -123,
  65. SingleSfixed64 = -12345678901234,
  66. SingleSint32 = -456,
  67. SingleSint64 = -12345678901235,
  68. SingleString = "test",
  69. SingleUint32 = UInt32.MaxValue,
  70. SingleUint64 = UInt64.MaxValue,
  71. RepeatedBool = { true, false },
  72. RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) },
  73. RepeatedDouble = { -12.25, 23.5 },
  74. RepeatedFixed32 = { UInt32.MaxValue, 23 },
  75. RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 },
  76. RepeatedFloat = { 100f, 12.25f },
  77. RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
  78. RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
  79. RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
  80. RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
  81. RepeatedInt32 = { 100, 200 },
  82. RepeatedInt64 = { 3210987654321, Int64.MaxValue },
  83. RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
  84. RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
  85. RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
  86. RepeatedSfixed32 = { -123, 123 },
  87. RepeatedSfixed64 = { -12345678901234, 12345678901234 },
  88. RepeatedSint32 = { -456, 100 },
  89. RepeatedSint64 = { -12345678901235, 123 },
  90. RepeatedString = { "foo", "bar" },
  91. RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue },
  92. RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue },
  93. OneofString = "Oneof string"
  94. };
  95. }
  96. }
  97. }