C++11: Also convert NULL to nullptr in unit tests (!117)

Closes !117 - Require C++11 compilation
This commit is contained in:
Mike Fleetwood 2023-09-12 14:37:09 +01:00 committed by Curtis Gedak
parent 40665913bf
commit 3b469273de
5 changed files with 27 additions and 27 deletions

View File

@ -69,10 +69,10 @@ std::string binary_string_to_print(size_t offset, const char* s, size_t len)
// Re-execute current executable using xvfb-run so that it provides a virtual X11 display.
static void exec_using_xvfb_run(int argc, char** argv)
{
// argc+2 = Space for "xvfb-run" command, existing argc strings plus NULL pointer.
// argc+2 = Space for "xvfb-run" command, existing argc strings plus nullptr.
size_t size = sizeof(char*) * (argc+2);
char** new_argv = (char**)malloc(size);
if (new_argv == NULL)
if (new_argv == nullptr)
{
fprintf(stderr, "Failed to allocate %lu bytes of memory. errno=%d,%s\n",
(unsigned long)size, errno, strerror(errno));
@ -80,14 +80,14 @@ static void exec_using_xvfb_run(int argc, char** argv)
}
new_argv[0] = strdup("xvfb-run");
if (new_argv[0] == NULL)
if (new_argv[0] == nullptr)
{
fprintf(stderr, "Failed to allocate %lu bytes of memory. errno=%d,%s\n",
(unsigned long)strlen(new_argv[0])+1, errno, strerror(errno));
exit(EXIT_FAILURE);
}
// Copy argv pointers including final NULL pointer.
// Copy argv pointers including final nullptr.
for (size_t i = 0; i <= (unsigned)argc; i++)
new_argv[i+1] = argv[i];
@ -102,7 +102,7 @@ static void exec_using_xvfb_run(int argc, char** argv)
void ensure_x11_display(int argc, char** argv)
{
const char* display = getenv("DISPLAY");
if (display == NULL)
if (display == nullptr)
{
printf("DISPLAY environment variable unset. Executing 'xvfb-run %s ...'\n", argv[0]);
exec_using_xvfb_run(argc, argv);

View File

@ -148,7 +148,7 @@ static std::string get_block_name( unsigned want )
static std::string get_link_name()
{
DIR * dir = opendir( "/dev/disk/by-id" );
if ( dir == NULL )
if (dir == nullptr)
{
ADD_FAILURE() << __func__ << "(): Failed to open directory '/dev/disk/by-id'";
return "";
@ -180,8 +180,8 @@ static std::string get_link_name()
// Follow symbolic link return real path.
static std::string follow_link_name( std::string link )
{
char * rpath = realpath( link.c_str(), NULL );
if ( rpath == NULL )
char* rpath = realpath(link.c_str(), nullptr);
if (rpath == nullptr)
{
ADD_FAILURE() << __func__ << "(): Failed to resolve symbolic link '" << link << "'";
return "";

View File

@ -86,7 +86,7 @@ void EraseFileSystemSignaturesTest::create_image_file(Byte_Value size)
m_partition.Reset();
PedDevice* lp_device = ped_device_get(s_image_name);
ASSERT_TRUE(lp_device != NULL);
ASSERT_TRUE(lp_device != nullptr);
m_partition.set_unpartitioned(s_image_name,
lp_device->path,
@ -96,7 +96,7 @@ void EraseFileSystemSignaturesTest::create_image_file(Byte_Value size)
false);
ped_device_destroy(lp_device);
lp_device = NULL;
lp_device = nullptr;
}
@ -155,7 +155,7 @@ const char* first_non_zero_byte(const char* buf, size_t size)
buf++;
size--;
}
return NULL;
return nullptr;
}
@ -183,7 +183,7 @@ bool EraseFileSystemSignaturesTest::image_contains_all_zeros()
return false;
}
const char* p = first_non_zero_byte(buf, bytes_read);
if (p != NULL)
if (p != nullptr)
{
ADD_FAILURE() << __func__ << "(): First non-zero bytes:\n"
<< binary_string_to_print(offset + (p - buf), p, buf + bytes_read - p);

View File

@ -79,7 +79,7 @@ static bool mem_is_zero( const char * mem, size_t len )
class PasswordRAMStoreTest : public ::testing::Test
{
protected:
PasswordRAMStoreTest() : looked_up_pw( NULL ) {};
PasswordRAMStoreTest() : looked_up_pw(nullptr) {};
static void SetUpTestCase();
@ -93,7 +93,7 @@ protected:
};
// Initialise test case class static member.
const char * PasswordRAMStoreTest::protected_mem = NULL;
const char * PasswordRAMStoreTest::protected_mem = nullptr;
const size_t ProtectedMemSize = 4096; // [Implementation knowledge: size]
@ -101,7 +101,7 @@ const size_t ProtectedMemSize = 4096; // [Implementation knowledge: size]
void PasswordRAMStoreTest::SetUpTestCase()
{
protected_mem = PasswordRAMStore::get_protected_mem();
ASSERT_TRUE( protected_mem != NULL ) << __func__ << "(): No locked virtual memory for password RAM store";
ASSERT_TRUE(protected_mem != nullptr) << __func__ << "(): No locked virtual memory for password RAM store";
}
TEST_F( PasswordRAMStoreTest, Initialisation )
@ -114,7 +114,7 @@ TEST_F( PasswordRAMStoreTest, UnknownPasswordLookup )
{
// Test lookup of non-existent password fails.
looked_up_pw = PasswordRAMStore::lookup( "key-unknown" );
EXPECT_TRUE( looked_up_pw == NULL );
EXPECT_TRUE(looked_up_pw == nullptr);
}
TEST_F( PasswordRAMStoreTest, UnknownPasswordErasure )
@ -270,7 +270,7 @@ TEST_F( PasswordRAMStoreTest, TooLongPassword )
EXPECT_TRUE( mem_is_zero( protected_mem, ProtectedMemSize ) );
looked_up_pw = PasswordRAMStore::lookup( "key-too-long" );
EXPECT_TRUE( looked_up_pw == NULL );
EXPECT_TRUE(looked_up_pw == nullptr);
EXPECT_FALSE(PasswordRAMStore::erase("key-too-long"));
EXPECT_TRUE( mem_is_zero( protected_mem, ProtectedMemSize ) );

View File

@ -194,12 +194,12 @@ protected:
};
SupportedFileSystems* SupportedFileSystemsTest::s_supported_filesystems = NULL;
SupportedFileSystems* SupportedFileSystemsTest::s_supported_filesystems = nullptr;
const char* SupportedFileSystemsTest::s_image_name = "test_SupportedFileSystems.img";
SupportedFileSystemsTest::SupportedFileSystemsTest()
: m_fstype(GetParam()), m_fs_object(NULL), m_require_loopdev(false),
: m_fstype(GetParam()), m_fs_object(nullptr), m_require_loopdev(false),
// Initialise top-level operation detail object with description ...
m_operation_detail("Operation details:", STATUS_NONE)
{
@ -208,11 +208,11 @@ SupportedFileSystemsTest::SupportedFileSystemsTest()
void SupportedFileSystemsTest::SetUp()
{
ASSERT_TRUE(s_supported_filesystems != NULL) << __func__ << "(): TEST_BUG: File system interfaces not loaded";
ASSERT_TRUE(s_supported_filesystems != nullptr) << __func__ << "(): TEST_BUG: File system interfaces not loaded";
// Lookup file system interface object.
m_fs_object = s_supported_filesystems->get_fs_object(m_fstype);
ASSERT_TRUE(m_fs_object != NULL) << __func__ << "(): TEST_BUG: Interface object not found for file system "
ASSERT_TRUE(m_fs_object != nullptr) << __func__ << "(): TEST_BUG: Interface object not found for file system "
<< test_fsname(m_fstype);
}
@ -243,7 +243,7 @@ void SupportedFileSystemsTest::TearDown()
unlink(s_image_name);
m_fs_object = NULL;
m_fs_object = nullptr;
}
@ -279,7 +279,7 @@ std::vector<FSType> SupportedFileSystemsTest::get_supported_fstypes()
// Create the supported file system interface object.
void SupportedFileSystemsTest::setup_supported_filesystems()
{
if (s_supported_filesystems == NULL)
if (s_supported_filesystems == nullptr)
{
s_supported_filesystems = new SupportedFileSystems();
@ -294,7 +294,7 @@ void SupportedFileSystemsTest::setup_supported_filesystems()
void SupportedFileSystemsTest::teardown_supported_filesystems()
{
delete s_supported_filesystems;
s_supported_filesystems = NULL;
s_supported_filesystems = nullptr;
}
@ -361,7 +361,7 @@ void SupportedFileSystemsTest::reload_partition()
// Use libparted to get the sector size etc. of the image file.
PedDevice* lp_device = ped_device_get(m_dev_name.c_str());
ASSERT_TRUE(lp_device != NULL);
ASSERT_TRUE(lp_device != nullptr);
// Prepare partition object spanning whole of the image file.
m_partition.set_unpartitioned(m_dev_name,
@ -372,7 +372,7 @@ void SupportedFileSystemsTest::reload_partition()
false);
ped_device_destroy(lp_device);
lp_device = NULL;
lp_device = nullptr;
}