| 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 "sync/internal_api/public/base/model_type.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/test/values_test_util.h" | 10 #include "base/test/values_test_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 namespace syncable { | |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 class ModelTypeTest : public testing::Test {}; | 17 class ModelTypeTest : public testing::Test {}; |
| 19 | 18 |
| 20 TEST_F(ModelTypeTest, ModelTypeToValue) { | 19 TEST_F(ModelTypeTest, ModelTypeToValue) { |
| 21 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 20 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
| 22 i < syncable::MODEL_TYPE_COUNT; ++i) { | 21 i < syncer::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 = syncable::FIRST_REAL_MODEL_TYPE; | 33 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
| 35 i < syncable::MODEL_TYPE_COUNT; ++i) { | 34 i < syncer::MODEL_TYPE_COUNT; ++i) { |
| 36 ModelType model_type = ModelTypeFromInt(i); | 35 ModelType model_type = ModelTypeFromInt(i); |
| 37 scoped_ptr<StringValue> value(ModelTypeToValue(model_type)); | 36 scoped_ptr<StringValue> value(ModelTypeToValue(model_type)); |
| 38 EXPECT_EQ(model_type, ModelTypeFromValue(*value)); | 37 EXPECT_EQ(model_type, ModelTypeFromValue(*value)); |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 | 40 |
| 42 TEST_F(ModelTypeTest, ModelTypeSetToValue) { | 41 TEST_F(ModelTypeTest, ModelTypeSetToValue) { |
| 43 const ModelTypeSet model_types(syncable::BOOKMARKS, syncable::APPS); | 42 const ModelTypeSet model_types(syncer::BOOKMARKS, syncer::APPS); |
| 44 | 43 |
| 45 scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types)); | 44 scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types)); |
| 46 EXPECT_EQ(2u, value->GetSize()); | 45 EXPECT_EQ(2u, value->GetSize()); |
| 47 std::string types[2]; | 46 std::string types[2]; |
| 48 EXPECT_TRUE(value->GetString(0, &types[0])); | 47 EXPECT_TRUE(value->GetString(0, &types[0])); |
| 49 EXPECT_TRUE(value->GetString(1, &types[1])); | 48 EXPECT_TRUE(value->GetString(1, &types[1])); |
| 50 EXPECT_EQ("Bookmarks", types[0]); | 49 EXPECT_EQ("Bookmarks", types[0]); |
| 51 EXPECT_EQ("Apps", types[1]); | 50 EXPECT_EQ("Apps", types[1]); |
| 52 } | 51 } |
| 53 | 52 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 TEST_F(ModelTypeTest, IsRealDataType) { | 66 TEST_F(ModelTypeTest, IsRealDataType) { |
| 68 EXPECT_FALSE(IsRealDataType(UNSPECIFIED)); | 67 EXPECT_FALSE(IsRealDataType(UNSPECIFIED)); |
| 69 EXPECT_FALSE(IsRealDataType(MODEL_TYPE_COUNT)); | 68 EXPECT_FALSE(IsRealDataType(MODEL_TYPE_COUNT)); |
| 70 EXPECT_FALSE(IsRealDataType(TOP_LEVEL_FOLDER)); | 69 EXPECT_FALSE(IsRealDataType(TOP_LEVEL_FOLDER)); |
| 71 EXPECT_TRUE(IsRealDataType(FIRST_REAL_MODEL_TYPE)); | 70 EXPECT_TRUE(IsRealDataType(FIRST_REAL_MODEL_TYPE)); |
| 72 EXPECT_TRUE(IsRealDataType(BOOKMARKS)); | 71 EXPECT_TRUE(IsRealDataType(BOOKMARKS)); |
| 73 EXPECT_TRUE(IsRealDataType(APPS)); | 72 EXPECT_TRUE(IsRealDataType(APPS)); |
| 74 } | 73 } |
| 75 | 74 |
| 76 } // namespace | 75 } // namespace |
| 77 } // namespace syncable | |
| 78 } // namespace syncer | 76 } // namespace syncer |
| OLD | NEW |