OLD | NEW |
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/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const T& specifics(T::default_instance()); | 45 const T& specifics(T::default_instance()); |
46 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); | 46 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); |
47 // We can't do much but make sure that this doesn't crash. | 47 // We can't do much but make sure that this doesn't crash. |
48 } | 48 } |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { | 51 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { |
52 // If this number changes, that means we added or removed a data | 52 // If this number changes, that means we added or removed a data |
53 // type. Don't forget to add a unit test for {New | 53 // type. Don't forget to add a unit test for {New |
54 // type}SpecificsToValue below. | 54 // type}SpecificsToValue below. |
55 EXPECT_EQ(25, MODEL_TYPE_COUNT); | 55 EXPECT_EQ(26, MODEL_TYPE_COUNT); |
56 | 56 |
57 // We'd also like to check if we changed any field in our messages. | 57 // We'd also like to check if we changed any field in our messages. |
58 // However, that's hard to do: sizeof could work, but it's | 58 // However, that's hard to do: sizeof could work, but it's |
59 // platform-dependent. default_instance().ByteSize() won't change | 59 // platform-dependent. default_instance().ByteSize() won't change |
60 // for most changes, since most of our fields are optional. So we | 60 // for most changes, since most of our fields are optional. So we |
61 // just settle for comments in the proto files. | 61 // just settle for comments in the proto files. |
62 } | 62 } |
63 | 63 |
64 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { | 64 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { |
65 TestSpecificsToValue(EncryptedDataToValue); | 65 TestSpecificsToValue(EncryptedDataToValue); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 SET_FIELD(priority_preference); | 237 SET_FIELD(priority_preference); |
238 SET_FIELD(search_engine); | 238 SET_FIELD(search_engine); |
239 SET_FIELD(session); | 239 SET_FIELD(session); |
240 SET_FIELD(synced_notification); | 240 SET_FIELD(synced_notification); |
241 SET_FIELD(theme); | 241 SET_FIELD(theme); |
242 SET_FIELD(typed_url); | 242 SET_FIELD(typed_url); |
243 | 243 |
244 #undef SET_FIELD | 244 #undef SET_FIELD |
245 | 245 |
246 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); | 246 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); |
247 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE, | 247 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE - |
| 248 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1), |
248 static_cast<int>(value->size())); | 249 static_cast<int>(value->size())); |
249 } | 250 } |
250 | 251 |
251 namespace { | 252 namespace { |
252 // Returns whether the given value has specifics under the entries in the given | 253 // Returns whether the given value has specifics under the entries in the given |
253 // path. | 254 // path. |
254 bool ValueHasSpecifics(const DictionaryValue& value, | 255 bool ValueHasSpecifics(const DictionaryValue& value, |
255 const std::string& path) { | 256 const std::string& path) { |
256 const ListValue* entities_list = NULL; | 257 const ListValue* entities_list = NULL; |
257 const DictionaryValue* entry_dictionary = NULL; | 258 const DictionaryValue* entry_dictionary = NULL; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 306 |
306 scoped_ptr<DictionaryValue> value_without_specifics( | 307 scoped_ptr<DictionaryValue> value_without_specifics( |
307 ClientToServerResponseToValue(message, false /* include_specifics */)); | 308 ClientToServerResponseToValue(message, false /* include_specifics */)); |
308 EXPECT_FALSE(value_without_specifics->empty()); | 309 EXPECT_FALSE(value_without_specifics->empty()); |
309 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), | 310 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), |
310 "get_updates.entries")); | 311 "get_updates.entries")); |
311 } | 312 } |
312 | 313 |
313 } // namespace | 314 } // namespace |
314 } // namespace syncer | 315 } // namespace syncer |
OLD | NEW |