Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: chrome/browser/sync/test/engine/proto_extension_validator.h

Issue 9460047: sync: remove use of protobuf extensions in protocol to reduce static init overhead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fred's review Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // A test utility that makes it easy to assert the exact presence of
6 // protobuf extensions in an extensible message. Example code:
7 //
8 // sync_pb::EntitySpecifics value; // Set up a test value.
9 // value.MutableExtension(sync_pb::bookmark);
10 //
11 // ProtoExtensionValidator<sync_pb::EntitySpecifics> good_expectation(value);
12 // good_expectation.ExpectHasExtension(sync_pb::bookmark);
13 // good_expectation.ExpectHasNoOtherFieldsOrExtensions();
14 //
15 // ProtoExtensionValidator<sync_pb::EntitySpecifics> bad_expectation(value);
16 // bad_expectation.ExpectHasExtension(sync_pb::preference); // Fails, no pref
17 // bad_expectation.ExpectHasNoOtherFieldsOrExtensions(); // Fails, bookmark
18
19 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_PROTO_EXTENSION_VALIDATOR_H_
20 #define CHROME_BROWSER_SYNC_TEST_ENGINE_PROTO_EXTENSION_VALIDATOR_H_
21 #pragma once
22
23 #include "base/string_util.h"
24 #include "chrome/browser/sync/test/engine/syncer_command_test.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26
27 namespace browser_sync {
28
29 template<typename MessageType>
30 class ProtoExtensionValidator {
31 public:
32 explicit ProtoExtensionValidator(const MessageType& proto)
33 : proto_(proto) {
34 }
35 template<typename ExtensionTokenType>
36 void ExpectHasExtension(ExtensionTokenType token) {
37 EXPECT_TRUE(proto_.HasExtension(token))
38 << "Proto failed to contain expected extension";
39 proto_.ClearExtension(token);
40 EXPECT_FALSE(proto_.HasExtension(token));
41 }
42 void ExpectNoOtherFieldsOrExtensions() {
43 EXPECT_EQ(MessageType::default_instance().SerializeAsString(),
44 proto_.SerializeAsString())
45 << "Proto contained additional unexpected extensions.";
46 }
47
48 private:
49 MessageType proto_;
50 DISALLOW_COPY_AND_ASSIGN(ProtoExtensionValidator);
51 };
52
53 } // namespace browser_sync
54
55 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_PROTO_EXTENSION_VALIDATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/engine/mock_connection_manager.cc ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698