/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/lite_unittest.cc

http://github.com/tomahawk-player/tomahawk · C++ · 112 lines · 72 code · 10 blank · 30 comment · 2 complexity · 7eb9cdb4b3e680f598d0af87e98330e5 MD5 · raw file

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. #include <string>
  32. #include <iostream>
  33. #include <google/protobuf/test_util_lite.h>
  34. #include <google/protobuf/stubs/common.h>
  35. using namespace std;
  36. int main(int argc, char* argv[]) {
  37. string data, packed_data;
  38. {
  39. protobuf_unittest::TestAllTypesLite message, message2, message3;
  40. google::protobuf::TestUtilLite::ExpectClear(message);
  41. google::protobuf::TestUtilLite::SetAllFields(&message);
  42. message2.CopyFrom(message);
  43. data = message.SerializeAsString();
  44. message3.ParseFromString(data);
  45. google::protobuf::TestUtilLite::ExpectAllFieldsSet(message);
  46. google::protobuf::TestUtilLite::ExpectAllFieldsSet(message2);
  47. google::protobuf::TestUtilLite::ExpectAllFieldsSet(message3);
  48. google::protobuf::TestUtilLite::ModifyRepeatedFields(&message);
  49. google::protobuf::TestUtilLite::ExpectRepeatedFieldsModified(message);
  50. message.Clear();
  51. google::protobuf::TestUtilLite::ExpectClear(message);
  52. }
  53. {
  54. protobuf_unittest::TestAllExtensionsLite message, message2, message3;
  55. google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
  56. google::protobuf::TestUtilLite::SetAllExtensions(&message);
  57. message2.CopyFrom(message);
  58. string extensions_data = message.SerializeAsString();
  59. GOOGLE_CHECK(extensions_data == data);
  60. message3.ParseFromString(extensions_data);
  61. google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message);
  62. google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message2);
  63. google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message3);
  64. google::protobuf::TestUtilLite::ModifyRepeatedExtensions(&message);
  65. google::protobuf::TestUtilLite::ExpectRepeatedExtensionsModified(message);
  66. message.Clear();
  67. google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
  68. }
  69. {
  70. protobuf_unittest::TestPackedTypesLite message, message2, message3;
  71. google::protobuf::TestUtilLite::ExpectPackedClear(message);
  72. google::protobuf::TestUtilLite::SetPackedFields(&message);
  73. message2.CopyFrom(message);
  74. packed_data = message.SerializeAsString();
  75. message3.ParseFromString(packed_data);
  76. google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message);
  77. google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message2);
  78. google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message3);
  79. google::protobuf::TestUtilLite::ModifyPackedFields(&message);
  80. google::protobuf::TestUtilLite::ExpectPackedFieldsModified(message);
  81. message.Clear();
  82. google::protobuf::TestUtilLite::ExpectPackedClear(message);
  83. }
  84. {
  85. protobuf_unittest::TestPackedExtensionsLite message, message2, message3;
  86. google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
  87. google::protobuf::TestUtilLite::SetPackedExtensions(&message);
  88. message2.CopyFrom(message);
  89. string packed_extensions_data = message.SerializeAsString();
  90. GOOGLE_CHECK(packed_extensions_data == packed_data);
  91. message3.ParseFromString(packed_extensions_data);
  92. google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message);
  93. google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message2);
  94. google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message3);
  95. google::protobuf::TestUtilLite::ModifyPackedExtensions(&message);
  96. google::protobuf::TestUtilLite::ExpectPackedExtensionsModified(message);
  97. message.Clear();
  98. google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
  99. }
  100. cout << "PASS" << endl;
  101. return 0;
  102. }