OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/sync/syncable/model_type.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/test/values_test_util.h" | |
11 #include "base/values.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace syncable { | |
15 namespace { | |
16 | |
17 class ModelTypeTest : public testing::Test {}; | |
18 | |
19 TEST_F(ModelTypeTest, ModelTypeToValue) { | |
20 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
21 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
22 ModelType model_type = ModelTypeFromInt(i); | |
23 base::ExpectStringValue(ModelTypeToString(model_type), | |
24 ModelTypeToValue(model_type)); | |
25 } | |
26 base::ExpectStringValue("Top-level folder", | |
27 ModelTypeToValue(TOP_LEVEL_FOLDER)); | |
28 base::ExpectStringValue("Unspecified", | |
29 ModelTypeToValue(UNSPECIFIED)); | |
30 } | |
31 | |
32 TEST_F(ModelTypeTest, ModelTypeFromValue) { | |
33 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
34 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
35 ModelType model_type = ModelTypeFromInt(i); | |
36 scoped_ptr<StringValue> value(ModelTypeToValue(model_type)); | |
37 EXPECT_EQ(model_type, ModelTypeFromValue(*value)); | |
38 } | |
39 } | |
40 | |
41 TEST_F(ModelTypeTest, ModelTypeSetToValue) { | |
42 const ModelTypeSet model_types(syncable::BOOKMARKS, syncable::APPS); | |
43 | |
44 scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types)); | |
45 EXPECT_EQ(2u, value->GetSize()); | |
46 std::string types[2]; | |
47 EXPECT_TRUE(value->GetString(0, &types[0])); | |
48 EXPECT_TRUE(value->GetString(1, &types[1])); | |
49 EXPECT_EQ("Bookmarks", types[0]); | |
50 EXPECT_EQ("Apps", types[1]); | |
51 } | |
52 | |
53 TEST_F(ModelTypeTest, ModelTypeSetFromValue) { | |
54 // Try empty set first. | |
55 ModelTypeSet model_types; | |
56 scoped_ptr<ListValue> value(ModelTypeSetToValue(model_types)); | |
57 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); | |
58 | |
59 // Now try with a few random types. | |
60 model_types.Put(BOOKMARKS); | |
61 model_types.Put(APPS); | |
62 value.reset(ModelTypeSetToValue(model_types)); | |
63 EXPECT_TRUE(model_types.Equals(ModelTypeSetFromValue(*value))); | |
64 } | |
65 | |
66 TEST_F(ModelTypeTest, IsRealDataType) { | |
67 EXPECT_FALSE(IsRealDataType(UNSPECIFIED)); | |
68 EXPECT_FALSE(IsRealDataType(MODEL_TYPE_COUNT)); | |
69 EXPECT_FALSE(IsRealDataType(TOP_LEVEL_FOLDER)); | |
70 EXPECT_TRUE(IsRealDataType(FIRST_REAL_MODEL_TYPE)); | |
71 EXPECT_TRUE(IsRealDataType(BOOKMARKS)); | |
72 EXPECT_TRUE(IsRealDataType(APPS)); | |
73 } | |
74 | |
75 } // namespace | |
76 } // namespace syncable | |
OLD | NEW |