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 "components/sync/api/sync_error.h" | |
6 | |
7 #include "base/location.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace syncer { | |
11 | |
12 namespace { | |
13 | |
14 using std::string; | |
15 | |
16 typedef testing::Test SyncErrorTest; | |
17 | |
18 TEST_F(SyncErrorTest, Unset) { | |
19 SyncError error; | |
20 EXPECT_FALSE(error.IsSet()); | |
21 } | |
22 | |
23 TEST_F(SyncErrorTest, Default) { | |
24 tracked_objects::Location location = FROM_HERE; | |
25 std::string msg = "test"; | |
26 ModelType type = PREFERENCES; | |
27 SyncError error(location, SyncError::DATATYPE_ERROR, msg, type); | |
28 ASSERT_TRUE(error.IsSet()); | |
29 EXPECT_EQ(location.line_number(), error.location().line_number()); | |
30 EXPECT_EQ("datatype error was encountered: ", error.GetMessagePrefix()); | |
31 EXPECT_EQ(msg, error.message()); | |
32 EXPECT_EQ(type, error.model_type()); | |
33 EXPECT_EQ(SyncError::SYNC_ERROR_SEVERITY_ERROR, error.GetSeverity()); | |
34 } | |
35 | |
36 TEST_F(SyncErrorTest, LowSeverity) { | |
37 tracked_objects::Location location = FROM_HERE; | |
38 std::string msg = "test"; | |
39 ModelType type = PREFERENCES; | |
40 SyncError error(location, SyncError::DATATYPE_POLICY_ERROR, msg, type); | |
41 ASSERT_TRUE(error.IsSet()); | |
42 EXPECT_EQ(location.line_number(), error.location().line_number()); | |
43 EXPECT_EQ("disabled due to configuration constraints: ", | |
44 error.GetMessagePrefix()); | |
45 EXPECT_EQ(msg, error.message()); | |
46 EXPECT_EQ(type, error.model_type()); | |
47 EXPECT_EQ(SyncError::SYNC_ERROR_SEVERITY_INFO, error.GetSeverity()); | |
48 } | |
49 | |
50 TEST_F(SyncErrorTest, Reset) { | |
51 tracked_objects::Location location = FROM_HERE; | |
52 std::string msg = "test"; | |
53 ModelType type = PREFERENCES; | |
54 | |
55 SyncError error; | |
56 EXPECT_FALSE(error.IsSet()); | |
57 | |
58 error.Reset(location, msg, type); | |
59 ASSERT_TRUE(error.IsSet()); | |
60 EXPECT_EQ(location.line_number(), error.location().line_number()); | |
61 EXPECT_EQ(msg, error.message()); | |
62 EXPECT_EQ(type, error.model_type()); | |
63 | |
64 tracked_objects::Location location2 = FROM_HERE; | |
65 std::string msg2 = "test"; | |
66 ModelType type2 = PREFERENCES; | |
67 error.Reset(location2, msg2, type2); | |
68 ASSERT_TRUE(error.IsSet()); | |
69 EXPECT_EQ(location2.line_number(), error.location().line_number()); | |
70 EXPECT_EQ(msg2, error.message()); | |
71 EXPECT_EQ(type2, error.model_type()); | |
72 } | |
73 | |
74 TEST_F(SyncErrorTest, Copy) { | |
75 tracked_objects::Location location = FROM_HERE; | |
76 std::string msg = "test"; | |
77 ModelType type = PREFERENCES; | |
78 | |
79 SyncError error1; | |
80 EXPECT_FALSE(error1.IsSet()); | |
81 SyncError error2(error1); | |
82 EXPECT_FALSE(error2.IsSet()); | |
83 | |
84 error1.Reset(location, msg, type); | |
85 ASSERT_TRUE(error1.IsSet()); | |
86 EXPECT_EQ(location.line_number(), error1.location().line_number()); | |
87 EXPECT_EQ(msg, error1.message()); | |
88 EXPECT_EQ(type, error1.model_type()); | |
89 | |
90 SyncError error3(error1); | |
91 ASSERT_TRUE(error3.IsSet()); | |
92 EXPECT_EQ(error1.location().line_number(), error3.location().line_number()); | |
93 EXPECT_EQ(error1.message(), error3.message()); | |
94 EXPECT_EQ(error1.model_type(), error3.model_type()); | |
95 | |
96 SyncError error4; | |
97 EXPECT_FALSE(error4.IsSet()); | |
98 SyncError error5(error4); | |
99 EXPECT_FALSE(error5.IsSet()); | |
100 } | |
101 | |
102 TEST_F(SyncErrorTest, Assign) { | |
103 tracked_objects::Location location = FROM_HERE; | |
104 std::string msg = "test"; | |
105 ModelType type = PREFERENCES; | |
106 | |
107 SyncError error1; | |
108 EXPECT_FALSE(error1.IsSet()); | |
109 SyncError error2; | |
110 error2 = error1; | |
111 EXPECT_FALSE(error2.IsSet()); | |
112 | |
113 error1.Reset(location, msg, type); | |
114 ASSERT_TRUE(error1.IsSet()); | |
115 EXPECT_EQ(location.line_number(), error1.location().line_number()); | |
116 EXPECT_EQ(msg, error1.message()); | |
117 EXPECT_EQ(type, error1.model_type()); | |
118 | |
119 error2 = error1; | |
120 ASSERT_TRUE(error2.IsSet()); | |
121 EXPECT_EQ(error1.location().line_number(), error2.location().line_number()); | |
122 EXPECT_EQ(error1.message(), error2.message()); | |
123 EXPECT_EQ(error1.model_type(), error2.model_type()); | |
124 | |
125 error2 = SyncError(); | |
126 EXPECT_FALSE(error2.IsSet()); | |
127 } | |
128 | |
129 TEST_F(SyncErrorTest, ToString) { | |
130 tracked_objects::Location location = FROM_HERE; | |
131 std::string msg = "test"; | |
132 ModelType type = PREFERENCES; | |
133 std::string expected = std::string(ModelTypeToString(type)) + | |
134 " datatype error was encountered: " + msg; | |
135 LOG(INFO) << "Expect " << expected; | |
136 SyncError error(location, SyncError::DATATYPE_ERROR, msg, type); | |
137 EXPECT_TRUE(error.IsSet()); | |
138 EXPECT_NE(string::npos, error.ToString().find(expected)); | |
139 | |
140 SyncError error2; | |
141 EXPECT_FALSE(error2.IsSet()); | |
142 EXPECT_EQ(std::string(), error2.ToString()); | |
143 | |
144 error2 = error; | |
145 EXPECT_TRUE(error2.IsSet()); | |
146 EXPECT_NE(string::npos, error.ToString().find(expected)); | |
147 } | |
148 | |
149 } // namespace | |
150 | |
151 } // namespace syncer | |
OLD | NEW |