forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
agl@chromium.org
committed
Sep 27, 2010
1 parent
f49eb33
commit 44473f8
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters