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