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