Skip to content

Commit

Permalink
sync_unit_tests: add test for unknown field retention.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
agl@chromium.org committed Sep 27, 2010
1 parent f49eb33 commit 44473f8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions chrome/browser/sync/protocol/sync_proto.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'password_specifics.proto',
'preference_specifics.proto',
'session_specifics.proto',
'test.proto',
'theme_specifics.proto',
'typed_url_specifics.proto',
],
Expand Down
24 changes: 24 additions & 0 deletions chrome/browser/sync/protocol/test.proto
Original file line number Diff line number Diff line change
@@ -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;
}
35 changes: 35 additions & 0 deletions chrome/browser/sync/util/protobuf_unittest.cc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 44473f8

Please sign in to comment.