diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 20:30:27 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-27 20:30:27 +0000 |
commit | 44473f80c0be3e8b565d59201ce1b1a9338399b1 (patch) | |
tree | c2d761d968245aa34b486452a9aefa90cf0eec2a | |
parent | f49eb338dbf489629e64d6ad563bd9407879d803 (diff) | |
download | chromium_src-44473f80c0be3e8b565d59201ce1b1a9338399b1.zip chromium_src-44473f80c0be3e8b565d59201ce1b1a9338399b1.tar.gz chromium_src-44473f80c0be3e8b565d59201ce1b1a9338399b1.tar.bz2 |
sync_unit_tests: add test for unknown field retention.
Retaining unknown fields is important for the sync protocol, so it's
good to test that it's working. In the future, when we hopefully have
a lite runtime with retention abilities, this test will make sure that
we haven't broken anything.
BUG=56579
TEST=sync_unit_tests
http://codereview.chromium.org/3384024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60701 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/protocol/sync_proto.gyp | 1 | ||||
-rw-r--r-- | chrome/browser/sync/protocol/test.proto | 24 | ||||
-rw-r--r-- | chrome/browser/sync/util/protobuf_unittest.cc | 35 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 |
4 files changed, 62 insertions, 0 deletions
diff --git a/chrome/browser/sync/protocol/sync_proto.gyp b/chrome/browser/sync/protocol/sync_proto.gyp index fad9d41..05be29f 100644 --- a/chrome/browser/sync/protocol/sync_proto.gyp +++ b/chrome/browser/sync/protocol/sync_proto.gyp @@ -23,6 +23,7 @@ 'password_specifics.proto', 'preference_specifics.proto', 'session_specifics.proto', + 'test.proto', 'theme_specifics.proto', 'typed_url_specifics.proto', ], diff --git a/chrome/browser/sync/protocol/test.proto b/chrome/browser/sync/protocol/test.proto new file mode 100644 index 0000000..e218e47 --- /dev/null +++ b/chrome/browser/sync/protocol/test.proto @@ -0,0 +1,24 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Protocol messages used only for testing. + +syntax = "proto2"; + +// TODO(agl): In the future we hope that the lite runtime will be able to +// handle unknown fields in messages. Until then, we use the full runtime. + +// option optimize_for = LITE_RUNTIME; +// option retain_unknown_fields = true; + +package sync_pb; + +message UnknownFieldsTestA { + required bool foo = 1; +} + +message UnknownFieldsTestB { + required bool foo = 1; + required bool bar = 2; +} diff --git a/chrome/browser/sync/util/protobuf_unittest.cc b/chrome/browser/sync/util/protobuf_unittest.cc new file mode 100644 index 0000000..bb8be8b --- /dev/null +++ b/chrome/browser/sync/util/protobuf_unittest.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string> +#include <vector> + +#include "chrome/browser/sync/protocol/test.pb.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +TEST(SyncProtobufTest, TestUnknownFields) { + // This tests ensures that we retain unknown fields in protocol buffers by + // serialising UnknownFieldsTestB, which is a superset of UnknownFieldsTestA, + // and checking we get back to the same message after parsing/serialising via + // UnknownFieldsTestA. + sync_pb::UnknownFieldsTestA a; + sync_pb::UnknownFieldsTestB b; + sync_pb::UnknownFieldsTestB b2; + + b.set_foo(true); + b.set_bar(true); + std::string serialized; + ASSERT_TRUE(b.SerializeToString(&serialized)); + ASSERT_TRUE(a.ParseFromString(serialized)); + ASSERT_TRUE(a.foo()); + std::string serialized2; + ASSERT_TRUE(a.SerializeToString(&serialized2)); + ASSERT_TRUE(b2.ParseFromString(serialized2)); + ASSERT_TRUE(b2.foo()); + ASSERT_TRUE(b2.bar()); +} + +} // namespace diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 17a6abb..2a1fce5 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2266,6 +2266,7 @@ 'target_name': 'sync_unit_tests', 'type': 'executable', 'sources': [ + '<(protoc_out_dir)/chrome/browser/sync/protocol/test.pb.cc', 'app/breakpad_mac_stubs.mm', 'browser/sync/engine/apply_updates_command_unittest.cc', 'browser/sync/engine/clear_data_command_unittest.cc', @@ -2294,6 +2295,7 @@ 'browser/sync/util/crypto_helpers_unittest.cc', 'browser/sync/util/data_encryption_unittest.cc', 'browser/sync/util/extensions_activity_monitor_unittest.cc', + 'browser/sync/util/protobuf_unittest.cc', 'browser/sync/util/user_settings_unittest.cc', 'test/file_test_utils.cc', 'test/sync/engine/mock_connection_manager.cc', |