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