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/api/sync_error.h" | 5 #include "sync/api/sync_error.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 | 24 |
25 TEST_F(SyncErrorTest, Default) { | 25 TEST_F(SyncErrorTest, Default) { |
26 tracked_objects::Location location = FROM_HERE; | 26 tracked_objects::Location location = FROM_HERE; |
27 std::string msg = "test"; | 27 std::string msg = "test"; |
28 ModelType type = PREFERENCES; | 28 ModelType type = PREFERENCES; |
29 SyncError error(location, msg, type); | 29 SyncError error(location, msg, type); |
30 ASSERT_TRUE(error.IsSet()); | 30 ASSERT_TRUE(error.IsSet()); |
31 EXPECT_EQ(location.line_number(), error.location().line_number()); | 31 EXPECT_EQ(location.line_number(), error.location().line_number()); |
32 EXPECT_EQ(msg, error.message()); | 32 EXPECT_EQ(msg, error.message()); |
33 EXPECT_EQ(type, error.type()); | 33 EXPECT_EQ(type, error.model_type()); |
34 } | 34 } |
35 | 35 |
36 TEST_F(SyncErrorTest, Reset) { | 36 TEST_F(SyncErrorTest, Reset) { |
37 tracked_objects::Location location = FROM_HERE; | 37 tracked_objects::Location location = FROM_HERE; |
38 std::string msg = "test"; | 38 std::string msg = "test"; |
39 ModelType type = PREFERENCES; | 39 ModelType type = PREFERENCES; |
40 | 40 |
41 SyncError error; | 41 SyncError error; |
42 EXPECT_FALSE(error.IsSet()); | 42 EXPECT_FALSE(error.IsSet()); |
43 | 43 |
44 error.Reset(location, msg, type); | 44 error.Reset(location, msg, type); |
45 ASSERT_TRUE(error.IsSet()); | 45 ASSERT_TRUE(error.IsSet()); |
46 EXPECT_EQ(location.line_number(), error.location().line_number()); | 46 EXPECT_EQ(location.line_number(), error.location().line_number()); |
47 EXPECT_EQ(msg, error.message()); | 47 EXPECT_EQ(msg, error.message()); |
48 EXPECT_EQ(type, error.type()); | 48 EXPECT_EQ(type, error.model_type()); |
49 | 49 |
50 tracked_objects::Location location2 = FROM_HERE; | 50 tracked_objects::Location location2 = FROM_HERE; |
51 std::string msg2 = "test"; | 51 std::string msg2 = "test"; |
52 ModelType type2 = PREFERENCES; | 52 ModelType type2 = PREFERENCES; |
53 error.Reset(location2, msg2, type2); | 53 error.Reset(location2, msg2, type2); |
54 ASSERT_TRUE(error.IsSet()); | 54 ASSERT_TRUE(error.IsSet()); |
55 EXPECT_EQ(location2.line_number(), error.location().line_number()); | 55 EXPECT_EQ(location2.line_number(), error.location().line_number()); |
56 EXPECT_EQ(msg2, error.message()); | 56 EXPECT_EQ(msg2, error.message()); |
57 EXPECT_EQ(type2, error.type()); | 57 EXPECT_EQ(type2, error.model_type()); |
58 } | 58 } |
59 | 59 |
60 TEST_F(SyncErrorTest, Copy) { | 60 TEST_F(SyncErrorTest, Copy) { |
61 tracked_objects::Location location = FROM_HERE; | 61 tracked_objects::Location location = FROM_HERE; |
62 std::string msg = "test"; | 62 std::string msg = "test"; |
63 ModelType type = PREFERENCES; | 63 ModelType type = PREFERENCES; |
64 | 64 |
65 SyncError error1; | 65 SyncError error1; |
66 EXPECT_FALSE(error1.IsSet()); | 66 EXPECT_FALSE(error1.IsSet()); |
67 SyncError error2(error1); | 67 SyncError error2(error1); |
68 EXPECT_FALSE(error2.IsSet()); | 68 EXPECT_FALSE(error2.IsSet()); |
69 | 69 |
70 error1.Reset(location, msg, type); | 70 error1.Reset(location, msg, type); |
71 ASSERT_TRUE(error1.IsSet()); | 71 ASSERT_TRUE(error1.IsSet()); |
72 EXPECT_EQ(location.line_number(), error1.location().line_number()); | 72 EXPECT_EQ(location.line_number(), error1.location().line_number()); |
73 EXPECT_EQ(msg, error1.message()); | 73 EXPECT_EQ(msg, error1.message()); |
74 EXPECT_EQ(type, error1.type()); | 74 EXPECT_EQ(type, error1.model_type()); |
75 | 75 |
76 SyncError error3(error1); | 76 SyncError error3(error1); |
77 ASSERT_TRUE(error3.IsSet()); | 77 ASSERT_TRUE(error3.IsSet()); |
78 EXPECT_EQ(error1.location().line_number(), error3.location().line_number()); | 78 EXPECT_EQ(error1.location().line_number(), error3.location().line_number()); |
79 EXPECT_EQ(error1.message(), error3.message()); | 79 EXPECT_EQ(error1.message(), error3.message()); |
80 EXPECT_EQ(error1.type(), error3.type()); | 80 EXPECT_EQ(error1.model_type(), error3.model_type()); |
81 | 81 |
82 SyncError error4; | 82 SyncError error4; |
83 EXPECT_FALSE(error4.IsSet()); | 83 EXPECT_FALSE(error4.IsSet()); |
84 SyncError error5(error4); | 84 SyncError error5(error4); |
85 EXPECT_FALSE(error5.IsSet()); | 85 EXPECT_FALSE(error5.IsSet()); |
86 } | 86 } |
87 | 87 |
88 TEST_F(SyncErrorTest, Assign) { | 88 TEST_F(SyncErrorTest, Assign) { |
89 tracked_objects::Location location = FROM_HERE; | 89 tracked_objects::Location location = FROM_HERE; |
90 std::string msg = "test"; | 90 std::string msg = "test"; |
91 ModelType type = PREFERENCES; | 91 ModelType type = PREFERENCES; |
92 | 92 |
93 SyncError error1; | 93 SyncError error1; |
94 EXPECT_FALSE(error1.IsSet()); | 94 EXPECT_FALSE(error1.IsSet()); |
95 SyncError error2; | 95 SyncError error2; |
96 error2 = error1; | 96 error2 = error1; |
97 EXPECT_FALSE(error2.IsSet()); | 97 EXPECT_FALSE(error2.IsSet()); |
98 | 98 |
99 error1.Reset(location, msg, type); | 99 error1.Reset(location, msg, type); |
100 ASSERT_TRUE(error1.IsSet()); | 100 ASSERT_TRUE(error1.IsSet()); |
101 EXPECT_EQ(location.line_number(), error1.location().line_number()); | 101 EXPECT_EQ(location.line_number(), error1.location().line_number()); |
102 EXPECT_EQ(msg, error1.message()); | 102 EXPECT_EQ(msg, error1.message()); |
103 EXPECT_EQ(type, error1.type()); | 103 EXPECT_EQ(type, error1.model_type()); |
104 | 104 |
105 error2 = error1; | 105 error2 = error1; |
106 ASSERT_TRUE(error2.IsSet()); | 106 ASSERT_TRUE(error2.IsSet()); |
107 EXPECT_EQ(error1.location().line_number(), error2.location().line_number()); | 107 EXPECT_EQ(error1.location().line_number(), error2.location().line_number()); |
108 EXPECT_EQ(error1.message(), error2.message()); | 108 EXPECT_EQ(error1.message(), error2.message()); |
109 EXPECT_EQ(error1.type(), error2.type()); | 109 EXPECT_EQ(error1.model_type(), error2.model_type()); |
110 | 110 |
111 error2 = SyncError(); | 111 error2 = SyncError(); |
112 EXPECT_FALSE(error2.IsSet()); | 112 EXPECT_FALSE(error2.IsSet()); |
113 } | 113 } |
114 | 114 |
115 TEST_F(SyncErrorTest, ToString) { | 115 TEST_F(SyncErrorTest, ToString) { |
116 tracked_objects::Location location = FROM_HERE; | 116 tracked_objects::Location location = FROM_HERE; |
117 std::string msg = "test"; | 117 std::string msg = "test"; |
118 ModelType type = PREFERENCES; | 118 ModelType type = PREFERENCES; |
119 std::string expected = "Preferences, Sync Error: test"; | 119 std::string expected = "Preferences, Sync Error: test"; |
120 SyncError error(location, msg, type); | 120 SyncError error(location, msg, type); |
121 EXPECT_TRUE(error.IsSet()); | 121 EXPECT_TRUE(error.IsSet()); |
122 EXPECT_NE(string::npos, error.ToString().find(expected)); | 122 EXPECT_NE(string::npos, error.ToString().find(expected)); |
123 | 123 |
124 SyncError error2; | 124 SyncError error2; |
125 EXPECT_FALSE(error2.IsSet()); | 125 EXPECT_FALSE(error2.IsSet()); |
126 EXPECT_EQ(std::string(), error2.ToString()); | 126 EXPECT_EQ(std::string(), error2.ToString()); |
127 | 127 |
128 error2 = error; | 128 error2 = error; |
129 EXPECT_TRUE(error2.IsSet()); | 129 EXPECT_TRUE(error2.IsSet()); |
130 EXPECT_NE(string::npos, error.ToString().find(expected)); | 130 EXPECT_NE(string::npos, error.ToString().find(expected)); |
131 } | 131 } |
132 | 132 |
133 } // namespace | 133 } // namespace |
134 | 134 |
135 } // namespace syncer | 135 } // namespace syncer |
OLD | NEW |