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