| 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 #include "sync/internal_api/public/base/model_type.h" | 5 #include <memory> |
| 6 | |
| 7 #include <string> | 6 #include <string> |
| 8 | 7 |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 11 #include "base/test/values_test_util.h" | 9 #include "base/test/values_test_util.h" |
| 12 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "sync/internal_api/public/base/model_type.h" |
| 13 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 14 |
| 16 namespace syncer { | 15 namespace syncer { |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 class ModelTypeTest : public testing::Test {}; | 18 class ModelTypeTest : public testing::Test {}; |
| 20 | 19 |
| 21 TEST_F(ModelTypeTest, ModelTypeToValue) { | 20 TEST_F(ModelTypeTest, ModelTypeToValue) { |
| 22 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 21 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 23 ModelType model_type = ModelTypeFromInt(i); | 22 ModelType model_type = ModelTypeFromInt(i); |
| 24 base::ExpectStringValue(ModelTypeToString(model_type), | 23 base::ExpectStringValue(ModelTypeToString(model_type), |
| 25 ModelTypeToValue(model_type)); | 24 ModelTypeToValue(model_type)); |
| 26 } | 25 } |
| 27 base::ExpectStringValue("Top-level folder", | 26 base::ExpectStringValue("Top-level folder", |
| 28 ModelTypeToValue(TOP_LEVEL_FOLDER)); | 27 ModelTypeToValue(TOP_LEVEL_FOLDER)); |
| 29 base::ExpectStringValue("Unspecified", | 28 base::ExpectStringValue("Unspecified", |
| 30 ModelTypeToValue(UNSPECIFIED)); | 29 ModelTypeToValue(UNSPECIFIED)); |
| 31 } | 30 } |
| 32 | 31 |
| 33 TEST_F(ModelTypeTest, ModelTypeFromValue) { | 32 TEST_F(ModelTypeTest, ModelTypeFromValue) { |
| 34 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 33 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 35 ModelType model_type = ModelTypeFromInt(i); | 34 ModelType model_type = ModelTypeFromInt(i); |
| 36 scoped_ptr<base::StringValue> value(ModelTypeToValue(model_type)); | 35 std::unique_ptr<base::StringValue> value(ModelTypeToValue(model_type)); |
| 37 EXPECT_EQ(model_type, ModelTypeFromValue(*value)); | 36 EXPECT_EQ(model_type, ModelTypeFromValue(*value)); |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 TEST_F(ModelTypeTest, ModelTypeSetToValue) { | 40 TEST_F(ModelTypeTest, ModelTypeSetToValue) { |
| 42 const ModelTypeSet model_types(BOOKMARKS, APPS); | 41 const ModelTypeSet model_types(BOOKMARKS, APPS); |
| 43 | 42 |
| 44 scoped_ptr<base::ListValue> value(ModelTypeSetToValue(model_types)); | 43 std::unique_ptr<base::ListValue> value(ModelTypeSetToValue(model_types)); |
| 45 EXPECT_EQ(2u, value->GetSize()); | 44 EXPECT_EQ(2u, value->GetSize()); |
| 46 std::string types[2]; | 45 std::string types[2]; |
| 47 EXPECT_TRUE(value->GetString(0, &types[0])); | 46 EXPECT_TRUE(value->GetString(0, &types[0])); |
| 48 EXPECT_TRUE(value->GetString(1, &types[1])); | 47 EXPECT_TRUE(value->GetString(1, &types[1])); |
| 49 EXPECT_EQ("Bookmarks", types[0]); | 48 EXPECT_EQ("Bookmarks", types[0]); |
| 50 EXPECT_EQ("Apps", types[1]); | 49 EXPECT_EQ("Apps", types[1]); |
| 51 } | 50 } |
| 52 | 51 |
| 53 TEST_F(ModelTypeTest, ModelTypeSetFromValue) { | 52 TEST_F(ModelTypeTest, ModelTypeSetFromValue) { |
| 54 // Try empty set first. | 53 // Try empty set first. |
| 55 ModelTypeSet model_types; | 54 ModelTypeSet model_types; |
| 56 scoped_ptr<base::ListValue> value(ModelTypeSetToValue(model_types)); | 55 std::unique_ptr<base::ListValue> value(ModelTypeSetToValue(model_types)); |
| 57 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); | 56 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); |
| 58 | 57 |
| 59 // Now try with a few random types. | 58 // Now try with a few random types. |
| 60 model_types.Put(BOOKMARKS); | 59 model_types.Put(BOOKMARKS); |
| 61 model_types.Put(APPS); | 60 model_types.Put(APPS); |
| 62 value = ModelTypeSetToValue(model_types); | 61 value = ModelTypeSetToValue(model_types); |
| 63 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); | 62 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); |
| 64 } | 63 } |
| 65 | 64 |
| 66 TEST_F(ModelTypeTest, IsRealDataType) { | 65 TEST_F(ModelTypeTest, IsRealDataType) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_EQ(notified_model_type, model_type); | 186 EXPECT_EQ(notified_model_type, model_type); |
| 188 } else { | 187 } else { |
| 189 EXPECT_FALSE(ProtocolTypes().Has(model_type)); | 188 EXPECT_FALSE(ProtocolTypes().Has(model_type)); |
| 190 EXPECT_TRUE(notification_type.empty()); | 189 EXPECT_TRUE(notification_type.empty()); |
| 191 } | 190 } |
| 192 } | 191 } |
| 193 } | 192 } |
| 194 | 193 |
| 195 } // namespace | 194 } // namespace |
| 196 } // namespace syncer | 195 } // namespace syncer |
| OLD | NEW |