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
31// Author: kenton@google.com (Kenton Varda)
32
33#include <string>
34#include <iostream>
35
36#include <google/protobuf/test_util_lite.h>
37#include <google/protobuf/stubs/common.h>
38
39using namespace std;
40
41int main(int argc, char* argv[]) {
42  string data, packed_data;
43
44  {
45    protobuf_unittest::TestAllTypesLite message, message2, message3;
46    google::protobuf::TestUtilLite::ExpectClear(message);
47    google::protobuf::TestUtilLite::SetAllFields(&message);
48    message2.CopyFrom(message);
49    data = message.SerializeAsString();
50    message3.ParseFromString(data);
51    google::protobuf::TestUtilLite::ExpectAllFieldsSet(message);
52    google::protobuf::TestUtilLite::ExpectAllFieldsSet(message2);
53    google::protobuf::TestUtilLite::ExpectAllFieldsSet(message3);
54    google::protobuf::TestUtilLite::ModifyRepeatedFields(&message);
55    google::protobuf::TestUtilLite::ExpectRepeatedFieldsModified(message);
56    message.Clear();
57    google::protobuf::TestUtilLite::ExpectClear(message);
58  }
59
60  {
61    protobuf_unittest::TestAllExtensionsLite message, message2, message3;
62    google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
63    google::protobuf::TestUtilLite::SetAllExtensions(&message);
64    message2.CopyFrom(message);
65    string extensions_data = message.SerializeAsString();
66    GOOGLE_CHECK(extensions_data == data);
67    message3.ParseFromString(extensions_data);
68    google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message);
69    google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message2);
70    google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message3);
71    google::protobuf::TestUtilLite::ModifyRepeatedExtensions(&message);
72    google::protobuf::TestUtilLite::ExpectRepeatedExtensionsModified(message);
73    message.Clear();
74    google::protobuf::TestUtilLite::ExpectExtensionsClear(message);
75  }
76
77  {
78    protobuf_unittest::TestPackedTypesLite message, message2, message3;
79    google::protobuf::TestUtilLite::ExpectPackedClear(message);
80    google::protobuf::TestUtilLite::SetPackedFields(&message);
81    message2.CopyFrom(message);
82    packed_data = message.SerializeAsString();
83    message3.ParseFromString(packed_data);
84    google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message);
85    google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message2);
86    google::protobuf::TestUtilLite::ExpectPackedFieldsSet(message3);
87    google::protobuf::TestUtilLite::ModifyPackedFields(&message);
88    google::protobuf::TestUtilLite::ExpectPackedFieldsModified(message);
89    message.Clear();
90    google::protobuf::TestUtilLite::ExpectPackedClear(message);
91  }
92
93  {
94    protobuf_unittest::TestPackedExtensionsLite message, message2, message3;
95    google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
96    google::protobuf::TestUtilLite::SetPackedExtensions(&message);
97    message2.CopyFrom(message);
98    string packed_extensions_data = message.SerializeAsString();
99    GOOGLE_CHECK(packed_extensions_data == packed_data);
100    message3.ParseFromString(packed_extensions_data);
101    google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message);
102    google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message2);
103    google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message3);
104    google::protobuf::TestUtilLite::ModifyPackedExtensions(&message);
105    google::protobuf::TestUtilLite::ExpectPackedExtensionsModified(message);
106    message.Clear();
107    google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message);
108  }
109
110  cout << "PASS" << endl;
111  return 0;
112}
113