Skip to content

Commit

Permalink
update_engine: Replace NULL with nullptr
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Alex Deymo <[email protected]>
Commit-Queue: Alex Vakulenko <[email protected]>
  • Loading branch information
Alex Vakulenko authored and chrome-internal-fetch committed Sep 1, 2014
1 parent f3e2801 commit 88b591f
Show file tree
Hide file tree
Showing 96 changed files with 750 additions and 758 deletions.
2 changes: 1 addition & 1 deletion action.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace chromeos_update_engine {
// It is handy to have a non-templated base class of all Actions.
class AbstractAction {
public:
AbstractAction() : processor_(NULL) {}
AbstractAction() : processor_(nullptr) {}

// Begin performing the action. Since this code is asynchronous, when this
// method returns, it means only that the action has started, not necessarily
Expand Down
12 changes: 6 additions & 6 deletions action_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ using std::string;
namespace chromeos_update_engine {

ActionProcessor::ActionProcessor()
: current_action_(NULL), delegate_(NULL) {}
: current_action_(nullptr), delegate_(nullptr) {}

ActionProcessor::~ActionProcessor() {
if (IsRunning()) {
StopProcessing();
}
for (std::deque<AbstractAction*>::iterator it = actions_.begin();
it != actions_.end(); ++it) {
(*it)->SetProcessor(NULL);
(*it)->SetProcessor(nullptr);
}
}

Expand All @@ -45,10 +45,10 @@ void ActionProcessor::StopProcessing() {
CHECK(current_action_);
current_action_->TerminateProcessing();
CHECK(current_action_);
current_action_->SetProcessor(NULL);
current_action_->SetProcessor(nullptr);
LOG(INFO) << "ActionProcessor::StopProcessing: aborted "
<< current_action_->Type();
current_action_ = NULL;
current_action_ = nullptr;
if (delegate_)
delegate_->ProcessingStopped(this);
}
Expand All @@ -60,8 +60,8 @@ void ActionProcessor::ActionComplete(AbstractAction* actionptr,
delegate_->ActionCompleted(this, actionptr, code);
string old_type = current_action_->Type();
current_action_->ActionCompleted(code);
current_action_->SetProcessor(NULL);
current_action_ = NULL;
current_action_->SetProcessor(nullptr);
current_action_ = nullptr;
if (actions_.empty()) {
LOG(INFO) << "ActionProcessor::ActionComplete: finished last action of"
" type " << old_type;
Expand Down
6 changes: 3 additions & 3 deletions action_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class ActionProcessor {
void StopProcessing();

// Returns true iff an Action is currently processing.
bool IsRunning() const { return NULL != current_action_; }
bool IsRunning() const { return nullptr != current_action_; }

// Adds another Action to the end of the queue.
virtual void EnqueueAction(AbstractAction* action);

// Sets/gets the current delegate. Set to NULL to remove a delegate.
// Sets/gets the current delegate. Set to null to remove a delegate.
ActionProcessorDelegate* delegate() const { return delegate_; }
void set_delegate(ActionProcessorDelegate *delegate) {
delegate_ = delegate;
Expand All @@ -70,7 +70,7 @@ class ActionProcessor {
// A pointer to the currently processing Action, if any.
AbstractAction* current_action_;

// A pointer to the delegate, or NULL if none.
// A pointer to the delegate, or null if none.
ActionProcessorDelegate *delegate_;
DISALLOW_COPY_AND_ASSIGN(ActionProcessor);
};
Expand Down
14 changes: 7 additions & 7 deletions action_processor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ TEST(ActionProcessorTest, DelegateTest) {
action_processor.EnqueueAction(&action);
action_processor.StartProcessing();
action.CompleteAction();
action_processor.set_delegate(NULL);
action_processor.set_delegate(nullptr);
EXPECT_TRUE(delegate.processing_done_called_);
EXPECT_TRUE(delegate.action_completed_called_);
}
Expand All @@ -119,11 +119,11 @@ TEST(ActionProcessorTest, StopProcessingTest) {
action_processor.EnqueueAction(&action);
action_processor.StartProcessing();
action_processor.StopProcessing();
action_processor.set_delegate(NULL);
action_processor.set_delegate(nullptr);
EXPECT_TRUE(delegate.processing_stopped_called_);
EXPECT_FALSE(delegate.action_completed_called_);
EXPECT_FALSE(action_processor.IsRunning());
EXPECT_EQ(NULL, action_processor.current_action());
EXPECT_EQ(nullptr, action_processor.current_action());
}

TEST(ActionProcessorTest, ChainActionsTest) {
Expand All @@ -138,7 +138,7 @@ TEST(ActionProcessorTest, ChainActionsTest) {
EXPECT_EQ(&action2, action_processor.current_action());
EXPECT_TRUE(action_processor.IsRunning());
action2.CompleteAction();
EXPECT_EQ(NULL, action_processor.current_action());
EXPECT_EQ(nullptr, action_processor.current_action());
EXPECT_FALSE(action_processor.IsRunning());
}

Expand All @@ -150,9 +150,9 @@ TEST(ActionProcessorTest, DtorTest) {
action_processor.EnqueueAction(&action2);
action_processor.StartProcessing();
}
EXPECT_EQ(NULL, action1.processor());
EXPECT_EQ(nullptr, action1.processor());
EXPECT_FALSE(action1.IsRunning());
EXPECT_EQ(NULL, action2.processor());
EXPECT_EQ(nullptr, action2.processor());
EXPECT_FALSE(action2.IsRunning());
}

Expand All @@ -171,7 +171,7 @@ TEST(ActionProcessorTest, DefaultDelegateTest) {
action_processor.StartProcessing();
action_processor.StopProcessing();

action_processor.set_delegate(NULL);
action_processor.set_delegate(nullptr);
}

} // namespace chromeos_update_engine
4 changes: 2 additions & 2 deletions bzip_extent_writer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ TEST_F(BzipExtentWriterTest, ChunkedTest) {
const vector<char>::size_type kDecompressedLength = 2048 * 1024; // 2 MiB
string decompressed_path;
ASSERT_TRUE(utils::MakeTempFile("BzipExtentWriterTest-decompressed-XXXXXX",
&decompressed_path, NULL));
&decompressed_path, nullptr));
string compressed_path;
ASSERT_TRUE(utils::MakeTempFile("BzipExtentWriterTest-compressed-XXXXXX",
&compressed_path, NULL));
&compressed_path, nullptr));
const size_t kChunkSize = 3;

vector<Extent> extents;
Expand Down
8 changes: 4 additions & 4 deletions certificate_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ bool OpenSSLWrapper::GetCertificateDigest(X509_STORE_CTX* x509_ctx,
}

// static
SystemState* CertificateChecker::system_state_ = NULL;
SystemState* CertificateChecker::system_state_ = nullptr;

// static
OpenSSLWrapper* CertificateChecker::openssl_wrapper_ = NULL;
OpenSSLWrapper* CertificateChecker::openssl_wrapper_ = nullptr;

// static
CURLcode CertificateChecker::ProcessSSLContext(CURL* curl_handle,
Expand Down Expand Up @@ -103,8 +103,8 @@ bool CertificateChecker::CheckCertificateChange(
static const char kUMAActionCertChanged[] =
"Updater.ServerCertificateChanged";
static const char kUMAActionCertFailed[] = "Updater.ServerCertificateFailed";
TEST_AND_RETURN_FALSE(system_state_ != NULL);
TEST_AND_RETURN_FALSE(system_state_->prefs() != NULL);
TEST_AND_RETURN_FALSE(system_state_ != nullptr);
TEST_AND_RETURN_FALSE(system_state_->prefs() != nullptr);
TEST_AND_RETURN_FALSE(server_to_check != kNone);

// If pre-verification failed, we are not interested in the current
Expand Down
14 changes: 7 additions & 7 deletions certificate_checker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CertificateCheckerTest : public testing::Test {

// check certificate change, new
TEST_F(CertificateCheckerTest, NewCertificate) {
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(NULL, _, _, _))
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(nullptr, _, _, _))
.WillOnce(DoAll(
SetArgumentPointee<1>(depth_),
SetArgumentPointee<2>(length_),
Expand All @@ -83,12 +83,12 @@ TEST_F(CertificateCheckerTest, NewCertificate) {
EXPECT_CALL(*prefs_, SetString(cert_key_, digest_hex_))
.WillOnce(Return(true));
ASSERT_TRUE(CertificateChecker::CheckCertificateChange(
server_to_check_, 1, NULL));
server_to_check_, 1, nullptr));
}

// check certificate change, unchanged
TEST_F(CertificateCheckerTest, SameCertificate) {
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(NULL, _, _, _))
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(nullptr, _, _, _))
.WillOnce(DoAll(
SetArgumentPointee<1>(depth_),
SetArgumentPointee<2>(length_),
Expand All @@ -100,12 +100,12 @@ TEST_F(CertificateCheckerTest, SameCertificate) {
Return(true)));
EXPECT_CALL(*prefs_, SetString(_, _)).Times(0);
ASSERT_TRUE(CertificateChecker::CheckCertificateChange(
server_to_check_, 1, NULL));
server_to_check_, 1, nullptr));
}

// check certificate change, changed
TEST_F(CertificateCheckerTest, ChangedCertificate) {
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(NULL, _, _, _))
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(nullptr, _, _, _))
.WillOnce(DoAll(
SetArgumentPointee<1>(depth_),
SetArgumentPointee<2>(length_),
Expand All @@ -121,7 +121,7 @@ TEST_F(CertificateCheckerTest, ChangedCertificate) {
EXPECT_CALL(*prefs_, SetString(cert_key_, digest_hex_))
.WillOnce(Return(true));
ASSERT_TRUE(CertificateChecker::CheckCertificateChange(
server_to_check_, 1, NULL));
server_to_check_, 1, nullptr));
}

// check certificate change, failed
Expand All @@ -132,7 +132,7 @@ TEST_F(CertificateCheckerTest, FailedCertificate) {
EXPECT_CALL(*prefs_, GetString(_, _)).Times(0);
EXPECT_CALL(openssl_wrapper_, GetCertificateDigest(_, _, _, _)).Times(0);
ASSERT_FALSE(CertificateChecker::CheckCertificateChange(
server_to_check_, 0, NULL));
server_to_check_, 0, nullptr));
}

// flush send report
Expand Down
20 changes: 10 additions & 10 deletions chrome_browser_proxy_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ const int kTimeout = 5; // seconds

ChromeBrowserProxyResolver::ChromeBrowserProxyResolver(
DBusWrapperInterface* dbus)
: dbus_(dbus), proxy_(NULL), timeout_(kTimeout) {}
: dbus_(dbus), proxy_(nullptr), timeout_(kTimeout) {}

bool ChromeBrowserProxyResolver::Init() {
if (proxy_)
return true; // Already initialized.

// Set up signal handler. Code lifted from libcros.
GError* g_error = NULL;
GError* g_error = nullptr;
DBusGConnection* bus = dbus_->BusGet(DBUS_BUS_SYSTEM, &g_error);
TEST_AND_RETURN_FALSE(bus);
DBusConnection* connection = dbus_->ConnectionGetConnection(bus);
Expand All @@ -75,7 +75,7 @@ bool ChromeBrowserProxyResolver::Init() {
connection,
&ChromeBrowserProxyResolver::StaticFilterMessage,
this,
NULL));
nullptr));

proxy_ = dbus_->ProxyNewForName(bus, kLibCrosServiceName, kLibCrosServicePath,
kLibCrosServiceInterface);
Expand All @@ -92,7 +92,7 @@ bool ChromeBrowserProxyResolver::Init() {
ChromeBrowserProxyResolver::~ChromeBrowserProxyResolver() {
// Remove DBus connection filters and Kill proxy object.
if (proxy_) {
GError* gerror = NULL;
GError* gerror = nullptr;
DBusGConnection* gbus = dbus_->BusGet(DBUS_BUS_SYSTEM, &gerror);
if (gbus) {
DBusConnection* connection = dbus_->ConnectionGetConnection(gbus);
Expand All @@ -108,14 +108,14 @@ ChromeBrowserProxyResolver::~ChromeBrowserProxyResolver() {
for (TimeoutsMap::iterator it = timers_.begin(), e = timers_.end(); it != e;
++it) {
g_source_destroy(it->second);
it->second = NULL;
it->second = nullptr;
}
}

bool ChromeBrowserProxyResolver::GetProxiesForUrl(const string& url,
ProxiesResolvedFn callback,
void* data) {
GError* error = NULL;
GError* error = nullptr;
guint timeout = timeout_;
if (proxy_) {
if (!dbus_->ProxyCall_3_0(proxy_,
Expand Down Expand Up @@ -146,7 +146,7 @@ bool ChromeBrowserProxyResolver::GetProxiesForUrl(const string& url,
GSource* timer = g_timeout_source_new_seconds(timeout);
g_source_set_callback(
timer, utils::GlibRunClosure, closure, utils::GlibDestroyClosure);
g_source_attach(timer, NULL);
g_source_attach(timer, nullptr);
timers_.insert(make_pair(url, timer));
return true;
}
Expand All @@ -161,9 +161,9 @@ DBusHandlerResult ChromeBrowserProxyResolver::FilterMessage(
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
// Get args
char* source_url = NULL;
char* proxy_list = NULL;
char* error = NULL;
char* source_url = nullptr;
char* proxy_list = nullptr;
char* error = nullptr;
DBusError arg_error;
dbus_error_init(&arg_error);
if (!dbus_->DBusMessageGetArgs_3(message, &arg_error,
Expand Down
23 changes: 12 additions & 11 deletions connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool GetFlimFlamProxy(DBusWrapperInterface* dbus_iface,
DBusGProxy** out_proxy) {
DBusGConnection* bus;
DBusGProxy* proxy;
GError* error = NULL;
GError* error = nullptr;

bus = dbus_iface->BusGet(DBUS_BUS_SYSTEM, &error);
if (!bus) {
Expand All @@ -52,7 +52,7 @@ bool GetProperties(DBusWrapperInterface* dbus_iface,
const char* interface,
GHashTable** out_hash_table) {
DBusGProxy* proxy;
GError* error = NULL;
GError* error = nullptr;

TEST_AND_RETURN_FALSE(GetFlimFlamProxy(dbus_iface,
path,
Expand All @@ -76,7 +76,7 @@ bool GetProperties(DBusWrapperInterface* dbus_iface,
// there's no network up.
// Returns true on success.
bool GetDefaultServicePath(DBusWrapperInterface* dbus_iface, string* out_path) {
GHashTable* hash_table = NULL;
GHashTable* hash_table = nullptr;

TEST_AND_RETURN_FALSE(GetProperties(dbus_iface,
shill::kFlimflamServicePath,
Expand All @@ -85,7 +85,7 @@ bool GetDefaultServicePath(DBusWrapperInterface* dbus_iface, string* out_path) {

GValue* value = reinterpret_cast<GValue*>(g_hash_table_lookup(hash_table,
"Services"));
GPtrArray* array = NULL;
GPtrArray* array = nullptr;
bool success = false;
if (G_VALUE_HOLDS(value, DBUS_TYPE_G_OBJECT_PATH_ARRAY) &&
(array = reinterpret_cast<GPtrArray*>(g_value_get_boxed(value))) &&
Expand Down Expand Up @@ -129,7 +129,7 @@ bool GetServicePathProperties(DBusWrapperInterface* dbus_iface,
const string& path,
NetworkConnectionType* out_type,
NetworkTethering* out_tethering) {
GHashTable* hash_table = NULL;
GHashTable* hash_table = nullptr;

TEST_AND_RETURN_FALSE(GetProperties(dbus_iface,
path.c_str(),
Expand All @@ -140,11 +140,11 @@ bool GetServicePathProperties(DBusWrapperInterface* dbus_iface,
GValue* value =
reinterpret_cast<GValue*>(g_hash_table_lookup(hash_table,
shill::kTetheringProperty));
const char* tethering_str = NULL;
const char* tethering_str = nullptr;

if (value != NULL)
if (value != nullptr)
tethering_str = g_value_get_string(value);
if (tethering_str != NULL) {
if (tethering_str != nullptr) {
*out_tethering = ParseTethering(tethering_str);
} else {
// Set to Unknown if not present.
Expand All @@ -154,14 +154,15 @@ bool GetServicePathProperties(DBusWrapperInterface* dbus_iface,
// Populate the out_type property.
value = reinterpret_cast<GValue*>(g_hash_table_lookup(hash_table,
shill::kTypeProperty));
const char* type_str = NULL;
const char* type_str = nullptr;
bool success = false;
if (value != NULL && (type_str = g_value_get_string(value)) != NULL) {
if (value != nullptr && (type_str = g_value_get_string(value)) != nullptr) {
success = true;
if (!strcmp(type_str, shill::kTypeVPN)) {
value = reinterpret_cast<GValue*>(
g_hash_table_lookup(hash_table, shill::kPhysicalTechnologyProperty));
if (value != NULL && (type_str = g_value_get_string(value)) != NULL) {
if (value != nullptr &&
(type_str = g_value_get_string(value)) != nullptr) {
*out_type = ParseConnectionType(type_str);
} else {
LOG(ERROR) << "No PhysicalTechnology property found for a VPN"
Expand Down
Loading

0 comments on commit 88b591f

Please sign in to comment.