update_engine: Replace NULL with nullptr
Replaced the usage of NULL with nullptr. This also makes it possible to
use standard gtest macros to compare pointers in Update Manager's unit tests.
So, there is no need in custom UMTEST_... macros which are replaced with the
gtest macros (see change in update_engine/update_manager/umtest_utils.h):
UMTEST_ASSERT_NULL(p) => ASSERT_EQ(nullptr, p)
UMTEST_ASSERT_NOT_NULL(p) => ASSERT_NE(nullptr, p)
UMTEST_EXPECT_NULL(p) => EXPECT_EQ(nullptr, p)
UMTEST_EXPECT_NOT_NULL(p) => EXPECT_NE(nullptr, p)
BUG=None
TEST=FEATURES=test emerge-link update_engine
USE="clang asan" FEATURES=test emerge-link update_engine
Change-Id: I77a42a1e9ce992bb2f9f263db5cf75fe6110a4ec
Reviewed-on: https://chromium-review.googlesource.com/215136
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/update_manager/boxed_value.h b/update_manager/boxed_value.h
index 4b8517f..6b547b6 100644
--- a/update_manager/boxed_value.h
+++ b/update_manager/boxed_value.h
@@ -43,7 +43,7 @@
// Creates an empty BoxedValue. Since the pointer can't be assigned from other
// BoxedValues or pointers, this is only useful in places where a default
// constructor is required, such as std::map::operator[].
- BoxedValue() : value_(NULL), deleter_(NULL), printer_(NULL) {}
+ BoxedValue() : value_(nullptr), deleter_(nullptr), printer_(nullptr) {}
// Creates a BoxedValue for the passed pointer |value|. The BoxedValue keeps
// the ownership of this pointer and can't be released.
@@ -60,9 +60,9 @@
BoxedValue(BoxedValue&& other) // NOLINT(build/c++11)
: value_(other.value_), deleter_(other.deleter_),
printer_(other.printer_) {
- other.value_ = NULL;
- other.deleter_ = NULL;
- other.printer_ = NULL;
+ other.value_ = nullptr;
+ other.deleter_ = nullptr;
+ other.printer_ = nullptr;
}
// Deletes the |value| passed on construction using the delete for the passed
diff --git a/update_manager/boxed_value_unittest.cc b/update_manager/boxed_value_unittest.cc
index 1b03cdd..dff6738 100644
--- a/update_manager/boxed_value_unittest.cc
+++ b/update_manager/boxed_value_unittest.cc
@@ -89,8 +89,8 @@
auto it = m.find(42);
ASSERT_NE(it, m.end());
- UMTEST_EXPECT_NOT_NULL(it->second.value());
- UMTEST_EXPECT_NULL(m[33].value());
+ EXPECT_NE(nullptr, it->second.value());
+ EXPECT_EQ(nullptr, m[33].value());
}
TEST(UmBoxedValueTest, StringToString) {
diff --git a/update_manager/evaluation_context.cc b/update_manager/evaluation_context.cc
index 5bee226..e334560 100644
--- a/update_manager/evaluation_context.cc
+++ b/update_manager/evaluation_context.cc
@@ -146,7 +146,7 @@
bool EvaluationContext::RunOnValueChangeOrTimeout(Closure callback) {
// Check that the method was not called more than once.
- if (callback_.get() != nullptr) {
+ if (callback_.get()) {
LOG(ERROR) << "RunOnValueChangeOrTimeout called more than once.";
return false;
}
diff --git a/update_manager/evaluation_context.h b/update_manager/evaluation_context.h
index e743669..a6d8f70 100644
--- a/update_manager/evaluation_context.h
+++ b/update_manager/evaluation_context.h
@@ -70,7 +70,7 @@
// returned object is valid during the life of the evaluation, even if the
// passed Variable changes it.
//
- // In case of error, a NULL value is returned.
+ // In case of error, a null value is returned.
template<typename T>
const T* GetValue(Variable<T>* var);
diff --git a/update_manager/evaluation_context_unittest.cc b/update_manager/evaluation_context_unittest.cc
index e193718..e59b160 100644
--- a/update_manager/evaluation_context_unittest.cc
+++ b/update_manager/evaluation_context_unittest.cc
@@ -84,9 +84,9 @@
if (eval_ctx_) {
base::WeakPtr<EvaluationContext> eval_ctx_weak_alias =
eval_ctx_->weak_ptr_factory_.GetWeakPtr();
- UMTEST_ASSERT_NOT_NULL(eval_ctx_weak_alias.get());
+ ASSERT_NE(nullptr, eval_ctx_weak_alias.get());
eval_ctx_ = nullptr;
- UMTEST_EXPECT_NULL(eval_ctx_weak_alias.get())
+ EXPECT_EQ(nullptr, eval_ctx_weak_alias.get())
<< "The evaluation context was not destroyed! This is likely a bug "
"in how the test was written, look for leaking handles to the EC, "
"possibly through closure objects.";
@@ -120,13 +120,12 @@
};
TEST_F(UmEvaluationContextTest, GetValueFails) {
- // FakeVariable is initialized as returning NULL.
- UMTEST_EXPECT_NULL(eval_ctx_->GetValue(&fake_int_var_));
+ // FakeVariable is initialized as returning null.
+ EXPECT_EQ(nullptr, eval_ctx_->GetValue(&fake_int_var_));
}
TEST_F(UmEvaluationContextTest, GetValueFailsWithInvalidVar) {
- UMTEST_EXPECT_NULL(eval_ctx_->GetValue(
- reinterpret_cast<Variable<int>*>(NULL)));
+ EXPECT_EQ(nullptr, eval_ctx_->GetValue(static_cast<Variable<int>*>(nullptr)));
}
TEST_F(UmEvaluationContextTest, GetValueReturns) {
@@ -134,7 +133,7 @@
fake_int_var_.reset(new int(42));
p_fake_int = eval_ctx_->GetValue(&fake_int_var_);
- UMTEST_ASSERT_NOT_NULL(p_fake_int);
+ ASSERT_NE(nullptr, p_fake_int);
EXPECT_EQ(42, *p_fake_int);
}
@@ -149,19 +148,19 @@
fake_int_var_.reset(new int(5));
p_fake_int = eval_ctx_->GetValue(&fake_int_var_);
- UMTEST_ASSERT_NOT_NULL(p_fake_int);
+ ASSERT_NE(nullptr, p_fake_int);
EXPECT_EQ(42, *p_fake_int);
}
TEST_F(UmEvaluationContextTest, GetValueCachesNull) {
const int* p_fake_int = eval_ctx_->GetValue(&fake_int_var_);
- UMTEST_EXPECT_NULL(p_fake_int);
+ EXPECT_EQ(nullptr, p_fake_int);
fake_int_var_.reset(new int(42));
// A second attempt to read the variable should not work because this
- // EvaluationContext already got a NULL value.
+ // EvaluationContext already got a null value.
p_fake_int = eval_ctx_->GetValue(&fake_int_var_);
- UMTEST_EXPECT_NULL(p_fake_int);
+ EXPECT_EQ(nullptr, p_fake_int);
}
TEST_F(UmEvaluationContextTest, GetValueMixedTypes) {
@@ -175,10 +174,10 @@
p_fake_int = eval_ctx_->GetValue(&fake_int_var_);
p_fake_string = eval_ctx_->GetValue(&fake_poll_var_);
- UMTEST_ASSERT_NOT_NULL(p_fake_int);
+ ASSERT_NE(nullptr, p_fake_int);
EXPECT_EQ(42, *p_fake_int);
- UMTEST_ASSERT_NOT_NULL(p_fake_string);
+ ASSERT_NE(nullptr, p_fake_string);
EXPECT_EQ("Hello world!", *p_fake_string);
}
@@ -328,7 +327,7 @@
// setup.
EXPECT_CALL(mock_var_async_, GetValue(default_timeout_, _))
.WillOnce(Return(nullptr));
- UMTEST_EXPECT_NULL(eval_ctx_->GetValue(&mock_var_async_));
+ EXPECT_EQ(nullptr, eval_ctx_->GetValue(&mock_var_async_));
}
TEST_F(UmEvaluationContextTest, TimeoutUpdatesWithMonotonicTime) {
@@ -339,7 +338,7 @@
EXPECT_CALL(mock_var_async_, GetValue(timeout, _))
.WillOnce(Return(nullptr));
- UMTEST_EXPECT_NULL(eval_ctx_->GetValue(&mock_var_async_));
+ EXPECT_EQ(nullptr, eval_ctx_->GetValue(&mock_var_async_));
}
TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesWallclock) {
diff --git a/update_manager/fake_variable.h b/update_manager/fake_variable.h
index 6024b75..2dae3db 100644
--- a/update_manager/fake_variable.h
+++ b/update_manager/fake_variable.h
@@ -26,7 +26,8 @@
// Sets the next value of this variable to the passed |p_value| pointer. Once
// returned by GetValue(), the pointer is released and has to be set again.
- // A value of NULL means that the GetValue() call will fail and return NULL.
+ // A value of null means that the GetValue() call will fail and return
+ // null.
void reset(const T* p_value) {
ptr_.reset(p_value);
}
@@ -40,11 +41,11 @@
// Variable<T> overrides.
// Returns the pointer set with reset(). The ownership of the object is passed
// to the caller and the pointer is release from the FakeVariable. A second
- // call to GetValue() without reset() will return NULL and set the error
+ // call to GetValue() without reset() will return null and set the error
// message.
virtual const T* GetValue(base::TimeDelta /* timeout */,
std::string* errmsg) {
- if (ptr_ == NULL && errmsg != NULL)
+ if (ptr_ == nullptr && errmsg != nullptr)
*errmsg = this->GetName() + " is an empty FakeVariable";
// Passes the pointer ownership to the caller.
return ptr_.release();
diff --git a/update_manager/generic_variables_unittest.cc b/update_manager/generic_variables_unittest.cc
index bbf3996..634acce 100644
--- a/update_manager/generic_variables_unittest.cc
+++ b/update_manager/generic_variables_unittest.cc
@@ -26,8 +26,8 @@
// Generate and validate a copy.
scoped_ptr<const int> copy_1(var.GetValue(
- UmTestUtils::DefaultTimeout(), NULL));
- UMTEST_ASSERT_NOT_NULL(copy_1.get());
+ UmTestUtils::DefaultTimeout(), nullptr));
+ ASSERT_NE(nullptr, copy_1.get());
EXPECT_EQ(5, *copy_1);
// Assign a different value to the source variable.
@@ -76,8 +76,8 @@
PollCopyVariable<CopyConstructorTestClass> var("var", source);
scoped_ptr<const CopyConstructorTestClass> copy(
- var.GetValue(UmTestUtils::DefaultTimeout(), NULL));
- UMTEST_ASSERT_NOT_NULL(copy.get());
+ var.GetValue(UmTestUtils::DefaultTimeout(), nullptr));
+ ASSERT_NE(nullptr, copy.get());
EXPECT_TRUE(copy->copied_);
}
@@ -117,7 +117,7 @@
scoped_ptr<const CopyConstructorTestClass> copy(
var.GetValue(UmTestUtils::DefaultTimeout(), nullptr));
EXPECT_EQ(6, test_obj.val_); // Check that the function was called.
- UMTEST_ASSERT_NOT_NULL(copy.get());
+ ASSERT_NE(nullptr, copy.get());
EXPECT_TRUE(copy->copied_);
EXPECT_EQ(12, copy->val_); // Check that copying occurred once.
}
diff --git a/update_manager/real_config_provider_unittest.cc b/update_manager/real_config_provider_unittest.cc
index fc20e36..93e657d 100644
--- a/update_manager/real_config_provider_unittest.cc
+++ b/update_manager/real_config_provider_unittest.cc
@@ -51,7 +51,7 @@
TEST_F(UmRealConfigProviderTest, InitTest) {
EXPECT_TRUE(provider_->Init());
- UMTEST_EXPECT_NOT_NULL(provider_->var_is_oobe_enabled());
+ EXPECT_NE(nullptr, provider_->var_is_oobe_enabled());
}
TEST_F(UmRealConfigProviderTest, NoFileFoundReturnsDefault) {
diff --git a/update_manager/real_random_provider.cc b/update_manager/real_random_provider.cc
index abbeed7..ea10de6 100644
--- a/update_manager/real_random_provider.cc
+++ b/update_manager/real_random_provider.cc
@@ -51,7 +51,7 @@
*errmsg = base::StringPrintf(
"Error reading from the random device: %s", kRandomDevice);
}
- return NULL;
+ return nullptr;
}
buf_rd += rd;
}
diff --git a/update_manager/real_random_provider_unittest.cc b/update_manager/real_random_provider_unittest.cc
index 55e17fa..b7e48f2 100644
--- a/update_manager/real_random_provider_unittest.cc
+++ b/update_manager/real_random_provider_unittest.cc
@@ -17,7 +17,7 @@
virtual void SetUp() {
// The provider initializes correctly.
provider_.reset(new RealRandomProvider());
- UMTEST_ASSERT_NOT_NULL(provider_.get());
+ ASSERT_NE(nullptr, provider_.get());
ASSERT_TRUE(provider_->Init());
provider_->var_seed();
@@ -28,14 +28,14 @@
TEST_F(UmRealRandomProviderTest, InitFinalize) {
// The provider initializes all variables with valid objects.
- UMTEST_EXPECT_NOT_NULL(provider_->var_seed());
+ EXPECT_NE(nullptr, provider_->var_seed());
}
TEST_F(UmRealRandomProviderTest, GetRandomValues) {
// Should not return the same random seed repeatedly.
scoped_ptr<const uint64_t> value(
provider_->var_seed()->GetValue(UmTestUtils::DefaultTimeout(), nullptr));
- UMTEST_ASSERT_NOT_NULL(value.get());
+ ASSERT_NE(nullptr, value.get());
// Test that at least the returned values are different. This test fails,
// by design, once every 2^320 runs.
@@ -44,7 +44,7 @@
scoped_ptr<const uint64_t> other_value(
provider_->var_seed()->GetValue(UmTestUtils::DefaultTimeout(),
nullptr));
- UMTEST_ASSERT_NOT_NULL(other_value.get());
+ ASSERT_NE(nullptr, other_value.get());
is_same_value = is_same_value && *other_value == *value;
}
EXPECT_FALSE(is_same_value);
diff --git a/update_manager/real_shill_provider.cc b/update_manager/real_shill_provider.cc
index dd8261c..609fd01 100644
--- a/update_manager/real_shill_provider.cc
+++ b/update_manager/real_shill_provider.cc
@@ -20,7 +20,7 @@
// the corresponding GValue, if found.
const char* GetStrProperty(GHashTable* hash_table, const char* key) {
auto gval = reinterpret_cast<GValue*>(g_hash_table_lookup(hash_table, key));
- return (gval ? g_value_get_string(gval) : NULL);
+ return (gval ? g_value_get_string(gval) : nullptr);
}
}; // namespace
@@ -65,7 +65,7 @@
bool RealShillProvider::Init() {
// Obtain a DBus connection.
- GError* error = NULL;
+ GError* error = nullptr;
connection_ = dbus_->BusGet(DBUS_BUS_SYSTEM, &error);
if (!connection_) {
LOG(ERROR) << "Failed to initialize DBus connection: "
@@ -82,12 +82,12 @@
G_TYPE_STRING, G_TYPE_VALUE);
dbus_->ProxyConnectSignal(manager_proxy_, shill::kMonitorPropertyChanged,
G_CALLBACK(HandlePropertyChangedStatic),
- this, NULL);
+ this, nullptr);
// Attempt to read initial connection status. Even if this fails because shill
// is not responding (e.g. it is down) we'll be notified via "PropertyChanged"
// signal as soon as it comes up, so this is not a critical step.
- GHashTable* hash_table = NULL;
+ GHashTable* hash_table = nullptr;
if (GetProperties(manager_proxy_, &hash_table)) {
GValue* value = reinterpret_cast<GValue*>(
g_hash_table_lookup(hash_table, shill::kDefaultServiceProperty));
@@ -106,7 +106,7 @@
bool RealShillProvider::GetProperties(DBusGProxy* proxy,
GHashTable** result_p) {
- GError* error = NULL;
+ GError* error = nullptr;
if (!dbus_->ProxyCall_0_1(proxy, shill::kGetPropertiesFunction, &error,
result_p)) {
LOG(ERROR) << "Calling shill via DBus proxy failed: "
@@ -118,7 +118,7 @@
bool RealShillProvider::ProcessDefaultService(GValue* value) {
// Decode the string from the boxed value.
- const char* default_service_path_str = NULL;
+ const char* default_service_path_str = nullptr;
if (!(value && (default_service_path_str = g_value_get_string(value))))
return false;
@@ -136,7 +136,7 @@
if (is_connected) {
DBusGProxy* service_proxy = GetProxy(default_service_path_.c_str(),
shill::kFlimflamServiceInterface);
- GHashTable* hash_table = NULL;
+ GHashTable* hash_table = nullptr;
if (GetProperties(service_proxy, &hash_table)) {
// Get the connection type.
const char* type_str = GetStrProperty(hash_table, shill::kTypeProperty);
diff --git a/update_manager/real_shill_provider.h b/update_manager/real_shill_provider.h
index 382aa1e..716a7dd 100644
--- a/update_manager/real_shill_provider.h
+++ b/update_manager/real_shill_provider.h
@@ -77,8 +77,8 @@
// The DBus interface (mockable), connection, and a shill manager proxy.
DBusWrapperInterface* const dbus_;
- DBusGConnection* connection_ = NULL;
- DBusGProxy* manager_proxy_ = NULL;
+ DBusGConnection* connection_ = nullptr;
+ DBusGProxy* manager_proxy_ = nullptr;
// A clock abstraction (mockable).
ClockInterface* const clock_;
diff --git a/update_manager/real_shill_provider_unittest.cc b/update_manager/real_shill_provider_unittest.cc
index 3468517..1cdc2a9 100644
--- a/update_manager/real_shill_provider_unittest.cc
+++ b/update_manager/real_shill_provider_unittest.cc
@@ -82,7 +82,7 @@
Shutdown();
provider_.reset(new RealShillProvider(&mock_dbus_, &fake_clock_));
- UMTEST_ASSERT_NOT_NULL(provider_.get());
+ ASSERT_NE(nullptr, provider_.get());
fake_clock_.SetWallclockTime(InitTime());
// A DBus connection should only be obtained once.
diff --git a/update_manager/real_system_provider_unittest.cc b/update_manager/real_system_provider_unittest.cc
index d744671..f78d339 100644
--- a/update_manager/real_system_provider_unittest.cc
+++ b/update_manager/real_system_provider_unittest.cc
@@ -25,9 +25,9 @@
};
TEST_F(UmRealSystemProviderTest, InitTest) {
- UMTEST_EXPECT_NOT_NULL(provider_->var_is_normal_boot_mode());
- UMTEST_EXPECT_NOT_NULL(provider_->var_is_official_build());
- UMTEST_EXPECT_NOT_NULL(provider_->var_is_oobe_complete());
+ EXPECT_NE(nullptr, provider_->var_is_normal_boot_mode());
+ EXPECT_NE(nullptr, provider_->var_is_official_build());
+ EXPECT_NE(nullptr, provider_->var_is_oobe_complete());
}
TEST_F(UmRealSystemProviderTest, IsOOBECompleteTrue) {
diff --git a/update_manager/real_time_provider_unittest.cc b/update_manager/real_time_provider_unittest.cc
index 6b236db..ac47d39 100644
--- a/update_manager/real_time_provider_unittest.cc
+++ b/update_manager/real_time_provider_unittest.cc
@@ -22,7 +22,7 @@
virtual void SetUp() {
// The provider initializes correctly.
provider_.reset(new RealTimeProvider(&fake_clock_));
- UMTEST_ASSERT_NOT_NULL(provider_.get());
+ ASSERT_NE(nullptr, provider_.get());
ASSERT_TRUE(provider_->Init());
}
diff --git a/update_manager/real_updater_provider.cc b/update_manager/real_updater_provider.cc
index c525b8f..004b51a 100644
--- a/update_manager/real_updater_provider.cc
+++ b/update_manager/real_updater_provider.cc
@@ -81,7 +81,7 @@
const Time* GetValue(TimeDelta /* timeout */, string* errmsg) override {
GetStatusHelper raw(system_state(), errmsg);
if (!raw.is_success())
- return NULL;
+ return nullptr;
return new Time(Time::FromTimeT(raw.last_checked_time()));
}
@@ -100,14 +100,14 @@
const double* GetValue(TimeDelta /* timeout */, string* errmsg) override {
GetStatusHelper raw(system_state(), errmsg);
if (!raw.is_success())
- return NULL;
+ return nullptr;
if (raw.progress() < 0.0 || raw.progress() > 1.0) {
if (errmsg) {
*errmsg = StringPrintf("Invalid progress value received: %f",
raw.progress());
}
- return NULL;
+ return nullptr;
}
return new double(raw.progress());
@@ -154,7 +154,7 @@
string* errmsg) {
GetStatusHelper raw(system_state(), errmsg);
if (!raw.is_success())
- return NULL;
+ return nullptr;
for (auto& key_val : curr_op_str_to_stage)
if (raw.update_status() == key_val.str)
@@ -162,7 +162,7 @@
if (errmsg)
*errmsg = string("Unknown update status: ") + raw.update_status();
- return NULL;
+ return nullptr;
}
// A variable reporting the version number that an update is updating to.
@@ -175,7 +175,7 @@
const string* GetValue(TimeDelta /* timeout */, string* errmsg) override {
GetStatusHelper raw(system_state(), errmsg);
if (!raw.is_success())
- return NULL;
+ return nullptr;
return new string(raw.new_version());
}
@@ -193,12 +193,12 @@
const int64_t* GetValue(TimeDelta /* timeout */, string* errmsg) override {
GetStatusHelper raw(system_state(), errmsg);
if (!raw.is_success())
- return NULL;
+ return nullptr;
if (raw.payload_size() < 0) {
if (errmsg)
*errmsg = string("Invalid payload size: %" PRId64, raw.payload_size());
- return NULL;
+ return nullptr;
}
return new int64_t(raw.payload_size());
@@ -226,7 +226,7 @@
&update_boottime)) {
if (errmsg)
*errmsg = "Update completed time could not be read";
- return NULL;
+ return nullptr;
}
chromeos_update_engine::ClockInterface* clock = system_state()->clock();
@@ -234,7 +234,7 @@
if (curr_boottime < update_boottime) {
if (errmsg)
*errmsg = "Update completed time more recent than current time";
- return NULL;
+ return nullptr;
}
TimeDelta duration_since_update = curr_boottime - update_boottime;
return new Time(clock->GetWallclockTime() - duration_since_update);
@@ -256,7 +256,7 @@
if (channel.empty()) {
if (errmsg)
*errmsg = "No current channel";
- return NULL;
+ return nullptr;
}
return new string(channel);
}
@@ -277,7 +277,7 @@
if (channel.empty()) {
if (errmsg)
*errmsg = "No new channel";
- return NULL;
+ return nullptr;
}
return new string(channel);
}
@@ -300,7 +300,7 @@
if (prefs && prefs->Exists(key_) && !prefs->GetBoolean(key_, &result)) {
if (errmsg)
*errmsg = string("Could not read boolean pref ") + key_;
- return NULL;
+ return nullptr;
}
return new bool(result);
}
diff --git a/update_manager/real_updater_provider_unittest.cc b/update_manager/real_updater_provider_unittest.cc
index 6e34fe4..6d614da 100644
--- a/update_manager/real_updater_provider_unittest.cc
+++ b/update_manager/real_updater_provider_unittest.cc
@@ -65,7 +65,7 @@
virtual void SetUp() {
fake_clock_ = fake_sys_state_.fake_clock();
provider_.reset(new RealUpdaterProvider(&fake_sys_state_));
- UMTEST_ASSERT_NOT_NULL(provider_.get());
+ ASSERT_NE(nullptr, provider_.get());
// Check that provider initializes correctly.
ASSERT_TRUE(provider_->Init());
}
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index 6aa1761..e9b576a 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -44,7 +44,7 @@
time_provider->Init() &&
updater_provider->Init())) {
LOG(ERROR) << "Error initializing providers";
- return NULL;
+ return nullptr;
}
return new RealState(config_provider.release(),
diff --git a/update_manager/umtest_utils.h b/update_manager/umtest_utils.h
index 3c9036e..4e2de8e 100644
--- a/update_manager/umtest_utils.h
+++ b/update_manager/umtest_utils.h
@@ -14,22 +14,6 @@
#include "update_engine/update_manager/policy.h"
#include "update_engine/update_manager/variable.h"
-// Convenience macros for checking null-ness of pointers.
-//
-// Purportedly, gtest should support pointer comparison when the first argument
-// is a pointer (e.g. NULL). It is therefore appropriate to use
-// {ASSERT,EXPECT}_{EQ,NE} for our purposes. However, gtest fails to realize
-// that NULL is a pointer when used with the _NE variants, unless we explicitly
-// cast it to a pointer type, and so we inject this casting.
-//
-// Note that checking nullness of the content of a scoped_ptr requires getting
-// the inner pointer value via get().
-#define UMTEST_ASSERT_NULL(p) ASSERT_EQ(NULL, p)
-#define UMTEST_ASSERT_NOT_NULL(p) ASSERT_NE(reinterpret_cast<void*>(NULL), p)
-#define UMTEST_EXPECT_NULL(p) EXPECT_EQ(NULL, p)
-#define UMTEST_EXPECT_NOT_NULL(p) EXPECT_NE(reinterpret_cast<void*>(NULL), p)
-
-
namespace chromeos_update_manager {
// A help class with common functionality for use in Update Manager testing.
@@ -43,18 +27,18 @@
// Calls GetValue on |variable| and expects its result to be |expected|.
template<typename T>
static void ExpectVariableHasValue(const T& expected, Variable<T>* variable) {
- UMTEST_ASSERT_NOT_NULL(variable);
+ ASSERT_NE(nullptr, variable);
scoped_ptr<const T> value(variable->GetValue(DefaultTimeout(), nullptr));
- UMTEST_ASSERT_NOT_NULL(value.get()) << "Variable: " << variable->GetName();
+ ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName();
EXPECT_EQ(expected, *value) << "Variable: " << variable->GetName();
}
// Calls GetValue on |variable| and expects its result to be null.
template<typename T>
static void ExpectVariableNotSet(Variable<T>* variable) {
- UMTEST_ASSERT_NOT_NULL(variable);
+ ASSERT_NE(nullptr, variable);
scoped_ptr<const T> value(variable->GetValue(DefaultTimeout(), nullptr));
- UMTEST_EXPECT_NULL(value.get()) << "Variable: " << variable->GetName();
+ EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName();
}
private:
diff --git a/update_manager/update_manager.h b/update_manager/update_manager.h
index 8cfd8f4..3355b60 100644
--- a/update_manager/update_manager.h
+++ b/update_manager/update_manager.h
@@ -44,8 +44,8 @@
// PolicyRequest() evaluates the given policy with the provided arguments and
// returns the result. The |policy_method| is the pointer-to-method of the
// Policy class for the policy request to call. The UpdateManager will call
- // this method on the right policy. The pointer |result| must not be NULL and
- // the remaining |args| depend on the arguments required by the passed
+ // this method on the right policy. The pointer |result| must not be null
+ // and the remaining |args| depend on the arguments required by the passed
// |policy_method|.
//
// When the policy request succeeds, the |result| is set and the method
diff --git a/update_manager/variable.h b/update_manager/variable.h
index e90d07e..ad2eefa 100644
--- a/update_manager/variable.h
+++ b/update_manager/variable.h
@@ -188,9 +188,9 @@
// should delete it.
//
// In case of and error getting the current value or the |timeout| timeout is
- // exceeded, a NULL value is returned and the |errmsg| is set.
+ // exceeded, a null value is returned and the |errmsg| is set.
//
- // The caller can pass a NULL value for |errmsg|, in which case the error
+ // The caller can pass a null value for |errmsg|, in which case the error
// message won't be set.
virtual const T* GetValue(base::TimeDelta timeout, std::string* errmsg) = 0;