| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "chrome/browser/sync/api/sync_error.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/tracked.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using std::string; | |
| 13 using syncable::ModelType; | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 typedef testing::Test SyncErrorTest; | |
| 18 | |
| 19 TEST_F(SyncErrorTest, Unset) { | |
| 20 SyncError error; | |
| 21 EXPECT_FALSE(error.IsSet()); | |
| 22 } | |
| 23 | |
| 24 TEST_F(SyncErrorTest, Default) { | |
| 25 tracked_objects::Location location = FROM_HERE; | |
| 26 std::string msg = "test"; | |
| 27 ModelType type = syncable::PREFERENCES; | |
| 28 SyncError error(location, msg, type); | |
| 29 EXPECT_TRUE(error.IsSet()); | |
| 30 EXPECT_EQ(location.line_number(), error.location().line_number()); | |
| 31 EXPECT_EQ(msg, error.message()); | |
| 32 EXPECT_EQ(type, error.type()); | |
| 33 } | |
| 34 | |
| 35 TEST_F(SyncErrorTest, Reset) { | |
| 36 tracked_objects::Location location = FROM_HERE; | |
| 37 std::string msg = "test"; | |
| 38 ModelType type = syncable::PREFERENCES; | |
| 39 | |
| 40 SyncError error; | |
| 41 EXPECT_FALSE(error.IsSet()); | |
| 42 | |
| 43 error.Reset(location, msg, type); | |
| 44 EXPECT_TRUE(error.IsSet()); | |
| 45 EXPECT_EQ(location.line_number(), error.location().line_number()); | |
| 46 EXPECT_EQ(msg, error.message()); | |
| 47 EXPECT_EQ(type, error.type()); | |
| 48 | |
| 49 tracked_objects::Location location2 = FROM_HERE; | |
| 50 std::string msg2 = "test"; | |
| 51 ModelType type2 = syncable::PREFERENCES; | |
| 52 error.Reset(location2, msg2, type2); | |
| 53 EXPECT_TRUE(error.IsSet()); | |
| 54 EXPECT_EQ(location2.line_number(), error.location().line_number()); | |
| 55 EXPECT_EQ(msg2, error.message()); | |
| 56 EXPECT_EQ(type2, error.type()); | |
| 57 } | |
| 58 | |
| 59 TEST_F(SyncErrorTest, Copy) { | |
| 60 tracked_objects::Location location = FROM_HERE; | |
| 61 std::string msg = "test"; | |
| 62 ModelType type = syncable::PREFERENCES; | |
| 63 | |
| 64 SyncError error1; | |
| 65 EXPECT_FALSE(error1.IsSet()); | |
| 66 SyncError error2(error1); | |
| 67 EXPECT_FALSE(error2.IsSet()); | |
| 68 | |
| 69 error1.Reset(location, msg, type); | |
| 70 EXPECT_TRUE(error1.IsSet()); | |
| 71 EXPECT_EQ(location.line_number(), error1.location().line_number()); | |
| 72 EXPECT_EQ(msg, error1.message()); | |
| 73 EXPECT_EQ(type, error1.type()); | |
| 74 | |
| 75 SyncError error3(error1); | |
| 76 EXPECT_TRUE(error3.IsSet()); | |
| 77 EXPECT_EQ(error1.location().line_number(), error3.location().line_number()); | |
| 78 EXPECT_EQ(error1.message(), error3.message()); | |
| 79 EXPECT_EQ(error1.type(), error3.type()); | |
| 80 | |
| 81 SyncError error4; | |
| 82 EXPECT_FALSE(error4.IsSet()); | |
| 83 SyncError error5(error4); | |
| 84 EXPECT_FALSE(error5.IsSet()); | |
| 85 } | |
| 86 | |
| 87 TEST_F(SyncErrorTest, Assign) { | |
| 88 tracked_objects::Location location = FROM_HERE; | |
| 89 std::string msg = "test"; | |
| 90 ModelType type = syncable::PREFERENCES; | |
| 91 | |
| 92 SyncError error1; | |
| 93 EXPECT_FALSE(error1.IsSet()); | |
| 94 SyncError error2; | |
| 95 error2 = error1; | |
| 96 EXPECT_FALSE(error2.IsSet()); | |
| 97 | |
| 98 error1.Reset(location, msg, type); | |
| 99 EXPECT_TRUE(error1.IsSet()); | |
| 100 EXPECT_EQ(location.line_number(), error1.location().line_number()); | |
| 101 EXPECT_EQ(msg, error1.message()); | |
| 102 EXPECT_EQ(type, error1.type()); | |
| 103 | |
| 104 error2 = error1; | |
| 105 EXPECT_TRUE(error2.IsSet()); | |
| 106 EXPECT_EQ(error1.location().line_number(), error2.location().line_number()); | |
| 107 EXPECT_EQ(error1.message(), error2.message()); | |
| 108 EXPECT_EQ(error1.type(), error2.type()); | |
| 109 | |
| 110 error2 = SyncError(); | |
| 111 EXPECT_FALSE(error2.IsSet()); | |
| 112 } | |
| 113 | |
| 114 } // namespace | |
| OLD | NEW |