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

Side by Side Diff: sync/protocol/proto_value_conversions_unittest.cc

Issue 674633002: sync: add WIFI_CREDENTIALS protobuf, ModelType, and preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@local-master
Patch Set: fix error in get commit message Created 6 years, 1 month 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
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Keep this file in sync with the .proto files in this directory. 5 // Keep this file in sync with the .proto files in this directory.
6 6
7 #include "sync/protocol/proto_value_conversions.h" 7 #include "sync/protocol/proto_value_conversions.h"
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 17 matching lines...) Expand all
28 #include "sync/protocol/managed_user_specifics.pb.h" 28 #include "sync/protocol/managed_user_specifics.pb.h"
29 #include "sync/protocol/nigori_specifics.pb.h" 29 #include "sync/protocol/nigori_specifics.pb.h"
30 #include "sync/protocol/password_specifics.pb.h" 30 #include "sync/protocol/password_specifics.pb.h"
31 #include "sync/protocol/preference_specifics.pb.h" 31 #include "sync/protocol/preference_specifics.pb.h"
32 #include "sync/protocol/priority_preference_specifics.pb.h" 32 #include "sync/protocol/priority_preference_specifics.pb.h"
33 #include "sync/protocol/search_engine_specifics.pb.h" 33 #include "sync/protocol/search_engine_specifics.pb.h"
34 #include "sync/protocol/session_specifics.pb.h" 34 #include "sync/protocol/session_specifics.pb.h"
35 #include "sync/protocol/sync.pb.h" 35 #include "sync/protocol/sync.pb.h"
36 #include "sync/protocol/theme_specifics.pb.h" 36 #include "sync/protocol/theme_specifics.pb.h"
37 #include "sync/protocol/typed_url_specifics.pb.h" 37 #include "sync/protocol/typed_url_specifics.pb.h"
38 #include "sync/protocol/wifi_credential_specifics.pb.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 40
40 namespace syncer { 41 namespace syncer {
41 namespace { 42 namespace {
42 43
43 class ProtoValueConversionsTest : public testing::Test { 44 class ProtoValueConversionsTest : public testing::Test {
44 protected: 45 protected:
45 template <class T> 46 template <class T>
46 void TestSpecificsToValue( 47 void TestSpecificsToValue(
47 base::DictionaryValue* (*specifics_to_value)(const T&)) { 48 base::DictionaryValue* (*specifics_to_value)(const T&)) {
48 const T& specifics(T::default_instance()); 49 const T& specifics(T::default_instance());
49 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics)); 50 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics));
50 // We can't do much but make sure that this doesn't crash. 51 // We can't do much but make sure that this doesn't crash.
51 } 52 }
52 }; 53 };
53 54
54 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { 55 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
55 // If this number changes, that means we added or removed a data 56 // If this number changes, that means we added or removed a data
56 // type. Don't forget to add a unit test for {New 57 // type. Don't forget to add a unit test for {New
57 // type}SpecificsToValue below. 58 // type}SpecificsToValue below.
58 EXPECT_EQ(32, MODEL_TYPE_COUNT); 59 EXPECT_EQ(33, MODEL_TYPE_COUNT);
59 60
60 // We'd also like to check if we changed any field in our messages. 61 // We'd also like to check if we changed any field in our messages.
61 // However, that's hard to do: sizeof could work, but it's 62 // However, that's hard to do: sizeof could work, but it's
62 // platform-dependent. default_instance().ByteSize() won't change 63 // platform-dependent. default_instance().ByteSize() won't change
63 // for most changes, since most of our fields are optional. So we 64 // for most changes, since most of our fields are optional. So we
64 // just settle for comments in the proto files. 65 // just settle for comments in the proto files.
65 } 66 }
66 67
67 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { 68 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) {
68 TestSpecificsToValue(EncryptedDataToValue); 69 TestSpecificsToValue(EncryptedDataToValue);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 258 }
258 259
259 TEST_F(ProtoValueConversionsTest, DictionarySpecificsToValue) { 260 TEST_F(ProtoValueConversionsTest, DictionarySpecificsToValue) {
260 TestSpecificsToValue(DictionarySpecificsToValue); 261 TestSpecificsToValue(DictionarySpecificsToValue);
261 } 262 }
262 263
263 TEST_F(ProtoValueConversionsTest, ArticleSpecificsToValue) { 264 TEST_F(ProtoValueConversionsTest, ArticleSpecificsToValue) {
264 TestSpecificsToValue(ArticleSpecificsToValue); 265 TestSpecificsToValue(ArticleSpecificsToValue);
265 } 266 }
266 267
268 TEST_F(ProtoValueConversionsTest, WifiCredentialSpecificsToValue) {
269 TestSpecificsToValue(WifiCredentialSpecificsToValue);
270 }
271
267 // TODO(akalin): Figure out how to better test EntitySpecificsToValue. 272 // TODO(akalin): Figure out how to better test EntitySpecificsToValue.
268 273
269 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) { 274 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
270 sync_pb::EntitySpecifics specifics; 275 sync_pb::EntitySpecifics specifics;
271 // Touch the extensions to make sure it shows up in the generated 276 // Touch the extensions to make sure it shows up in the generated
272 // value. 277 // value.
273 #define SET_FIELD(key) (void)specifics.mutable_##key() 278 #define SET_FIELD(key) (void)specifics.mutable_##key()
274 279
275 SET_FIELD(app); 280 SET_FIELD(app);
276 SET_FIELD(app_list); 281 SET_FIELD(app_list);
(...skipping 17 matching lines...) Expand all
294 SET_FIELD(nigori); 299 SET_FIELD(nigori);
295 SET_FIELD(password); 300 SET_FIELD(password);
296 SET_FIELD(preference); 301 SET_FIELD(preference);
297 SET_FIELD(priority_preference); 302 SET_FIELD(priority_preference);
298 SET_FIELD(search_engine); 303 SET_FIELD(search_engine);
299 SET_FIELD(session); 304 SET_FIELD(session);
300 SET_FIELD(synced_notification); 305 SET_FIELD(synced_notification);
301 SET_FIELD(synced_notification_app_info); 306 SET_FIELD(synced_notification_app_info);
302 SET_FIELD(theme); 307 SET_FIELD(theme);
303 SET_FIELD(typed_url); 308 SET_FIELD(typed_url);
309 SET_FIELD(wifi_credential);
304 310
305 #undef SET_FIELD 311 #undef SET_FIELD
306 312
307 scoped_ptr<base::DictionaryValue> value(EntitySpecificsToValue(specifics)); 313 scoped_ptr<base::DictionaryValue> value(EntitySpecificsToValue(specifics));
308 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE - 314 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE -
309 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1), 315 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1),
310 static_cast<int>(value->size())); 316 static_cast<int>(value->size()));
311 } 317 }
312 318
313 namespace { 319 namespace {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 377 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
372 "get_updates.entries")); 378 "get_updates.entries"));
373 } 379 }
374 380
375 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) { 381 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) {
376 TestSpecificsToValue(AttachmentIdProtoToValue); 382 TestSpecificsToValue(AttachmentIdProtoToValue);
377 } 383 }
378 384
379 } // namespace 385 } // namespace
380 } // namespace syncer 386 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698