Standardize on static constexpr for arrays when possible

This uses “static” at function scope to avoid making local copies, even
in cases where the compiler can’t see that the local copy is
unnecessary. “constexpr” adds additional safety in that it prevents
global state from being initialized from any runtime dependencies, which
would be undesirable.

At namespace scope, “constexpr” is also used where appropriate.

For the most part, this was a mechanical transformation for things
matching '(^| )const [^=]*\['.

Similar transformations could be applied to non-arrays in some cases,
but there’s limited practical impact in most non-array cases relative to
arrays, there are far more use sites, and much more manual intervention
would be required.

Change-Id: I3513b739ee8b0be026f8285475cddc5f9cc81152
Reviewed-on: https://chromium-review.googlesource.com/583997
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
This commit is contained in:
Mark Mentovai 2017-07-25 13:34:04 -04:00
parent 01b347732e
commit 281be63d00
88 changed files with 445 additions and 421 deletions

View File

@ -42,29 +42,30 @@ namespace crashpad {
namespace { namespace {
const char kWriteDirectory[] = "new"; constexpr char kWriteDirectory[] = "new";
const char kUploadPendingDirectory[] = "pending"; constexpr char kUploadPendingDirectory[] = "pending";
const char kCompletedDirectory[] = "completed"; constexpr char kCompletedDirectory[] = "completed";
const char kSettings[] = "settings.dat"; constexpr char kSettings[] = "settings.dat";
const char* const kReportDirectories[] = { constexpr const char* kReportDirectories[] = {
kWriteDirectory, kWriteDirectory,
kUploadPendingDirectory, kUploadPendingDirectory,
kCompletedDirectory, kCompletedDirectory,
}; };
const char kCrashReportFileExtension[] = "dmp"; constexpr char kCrashReportFileExtension[] = "dmp";
const char kXattrUUID[] = "uuid"; constexpr char kXattrUUID[] = "uuid";
const char kXattrCollectorID[] = "id"; constexpr char kXattrCollectorID[] = "id";
const char kXattrCreationTime[] = "creation_time"; constexpr char kXattrCreationTime[] = "creation_time";
const char kXattrIsUploaded[] = "uploaded"; constexpr char kXattrIsUploaded[] = "uploaded";
const char kXattrLastUploadTime[] = "last_upload_time"; constexpr char kXattrLastUploadTime[] = "last_upload_time";
const char kXattrUploadAttemptCount[] = "upload_count"; constexpr char kXattrUploadAttemptCount[] = "upload_count";
const char kXattrIsUploadExplicitlyRequested[] = "upload_explicitly_requested"; constexpr char kXattrIsUploadExplicitlyRequested[] =
"upload_explicitly_requested";
const char kXattrDatabaseInitialized[] = "initialized"; constexpr char kXattrDatabaseInitialized[] = "initialized";
// Ensures that the node at |path| is a directory. If the |path| refers to a // Ensures that the node at |path| is a directory. If the |path| refers to a
// file, rather than a directory, returns false. Otherwise, returns true, // file, rather than a directory, returns false. Otherwise, returns true,

View File

@ -51,7 +51,7 @@ class CrashReportDatabaseTest : public testing::Test {
CrashReportDatabase::NewReport* new_report = nullptr; CrashReportDatabase::NewReport* new_report = nullptr;
ASSERT_EQ(db_->PrepareNewCrashReport(&new_report), ASSERT_EQ(db_->PrepareNewCrashReport(&new_report),
CrashReportDatabase::kNoError); CrashReportDatabase::kNoError);
const char kTest[] = "test"; static constexpr char kTest[] = "test";
ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest)));
UUID uuid; UUID uuid;

View File

@ -36,12 +36,12 @@ namespace crashpad {
namespace { namespace {
const wchar_t kReportsDirectory[] = L"reports"; constexpr wchar_t kReportsDirectory[] = L"reports";
const wchar_t kMetadataFileName[] = L"metadata"; constexpr wchar_t kMetadataFileName[] = L"metadata";
const wchar_t kSettings[] = L"settings.dat"; constexpr wchar_t kSettings[] = L"settings.dat";
const wchar_t kCrashReportFileExtension[] = L"dmp"; constexpr wchar_t kCrashReportFileExtension[] = L"dmp";
const uint32_t kMetadataFileHeaderMagic = 'CPAD'; const uint32_t kMetadataFileHeaderMagic = 'CPAD';
const uint32_t kMetadataFileVersion = 1; const uint32_t kMetadataFileVersion = 1;

View File

@ -28,7 +28,7 @@
namespace { namespace {
static const uint32_t kCrashpadInfoVersion = 1; constexpr uint32_t kCrashpadInfoVersion = 1;
} // namespace } // namespace

View File

@ -147,7 +147,7 @@ class StaticCondition final : public PruneCondition {
}; };
TEST(PruneCrashReports, BinaryCondition) { TEST(PruneCrashReports, BinaryCondition) {
const struct { static constexpr struct {
const char* name; const char* name;
BinaryPruneCondition::Operator op; BinaryPruneCondition::Operator op;
bool lhs_value; bool lhs_value;

View File

@ -41,7 +41,7 @@ class SettingsTest : public testing::Test {
FilePermissions::kWorldReadable)); FilePermissions::kWorldReadable));
ASSERT_TRUE(handle.is_valid()); ASSERT_TRUE(handle.is_valid());
const char kBuf[] = "test bad file"; static constexpr char kBuf[] = "test bad file";
ASSERT_TRUE(LoggingWriteFile(handle.get(), kBuf, sizeof(kBuf))); ASSERT_TRUE(LoggingWriteFile(handle.get(), kBuf, sizeof(kBuf)));
handle.reset(); handle.reset();
} }

View File

@ -196,7 +196,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) {
// Look up the handler for EXC_CRASH exceptions in the same way that the // Look up the handler for EXC_CRASH exceptions in the same way that the
// kernel would: try a thread handler, then a task handler, and finally a host // kernel would: try a thread handler, then a task handler, and finally a host
// handler. 10.9.5 xnu-2422.115.4/osfmk/kern/exception.c exception_triage(). // handler. 10.9.5 xnu-2422.115.4/osfmk/kern/exception.c exception_triage().
const ExceptionPorts::TargetType kTargetTypes[] = { static constexpr ExceptionPorts::TargetType kTargetTypes[] = {
ExceptionPorts::kTargetTypeThread, ExceptionPorts::kTargetTypeThread,
ExceptionPorts::kTargetTypeTask, ExceptionPorts::kTargetTypeTask,

View File

@ -307,14 +307,14 @@ class TestSimulateCrashMac final : public MachMultiprocess,
}; };
TEST(SimulateCrash, SimulateCrash) { TEST(SimulateCrash, SimulateCrash) {
const TestSimulateCrashMac::ExceptionPortsTarget kTargets[] = { static constexpr TestSimulateCrashMac::ExceptionPortsTarget kTargets[] = {
TestSimulateCrashMac::kExceptionPortsTargetNone, TestSimulateCrashMac::kExceptionPortsTargetNone,
TestSimulateCrashMac::kExceptionPortsTargetTask, TestSimulateCrashMac::kExceptionPortsTargetTask,
TestSimulateCrashMac::kExceptionPortsTargetThread, TestSimulateCrashMac::kExceptionPortsTargetThread,
TestSimulateCrashMac::kExceptionPortsTargetBoth, TestSimulateCrashMac::kExceptionPortsTargetBoth,
}; };
const exception_behavior_t kBehaviors[] = { static constexpr exception_behavior_t kBehaviors[] = {
EXCEPTION_DEFAULT, EXCEPTION_DEFAULT,
EXCEPTION_STATE, EXCEPTION_STATE,
EXCEPTION_STATE_IDENTITY, EXCEPTION_STATE_IDENTITY,
@ -323,7 +323,7 @@ TEST(SimulateCrash, SimulateCrash) {
EXCEPTION_STATE_IDENTITY | kMachExceptionCodes, EXCEPTION_STATE_IDENTITY | kMachExceptionCodes,
}; };
const thread_state_flavor_t kFlavors[] = { static constexpr thread_state_flavor_t kFlavors[] = {
#if defined(ARCH_CPU_X86_FAMILY) #if defined(ARCH_CPU_X86_FAMILY)
x86_THREAD_STATE, x86_THREAD_STATE,
x86_FLOAT_STATE, x86_FLOAT_STATE,

View File

@ -361,7 +361,7 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport(
HTTPMultipartBuilder http_multipart_builder; HTTPMultipartBuilder http_multipart_builder;
http_multipart_builder.SetGzipEnabled(upload_gzip_); http_multipart_builder.SetGzipEnabled(upload_gzip_);
const char kMinidumpKey[] = "upload_file_minidump"; static constexpr char kMinidumpKey[] = "upload_file_minidump";
for (const auto& kv : parameters) { for (const auto& kv : parameters) {
if (kv.first == kMinidumpKey) { if (kv.first == kMinidumpKey) {

View File

@ -115,7 +115,7 @@ void CrashWithExtendedHandler::ValidateGeneratedDump() {
ASSERT_TRUE(reader.ReadExactly(data.data(), data.size())); ASSERT_TRUE(reader.ReadExactly(data.data(), data.size()));
static const char kExpectedData[] = "Injected extension stream!"; static constexpr char kExpectedData[] = "Injected extension stream!";
EXPECT_EQ(memcmp(kExpectedData, data.data(), sizeof(kExpectedData)), 0); EXPECT_EQ(memcmp(kExpectedData, data.data(), sizeof(kExpectedData)), 0);
} }
} }

View File

@ -39,7 +39,7 @@ class TestUserStreamDataSource : public crashpad::UserStreamDataSource {
std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource>
TestUserStreamDataSource::ProduceStreamData( TestUserStreamDataSource::ProduceStreamData(
crashpad::ProcessSnapshot* process_snapshot) { crashpad::ProcessSnapshot* process_snapshot) {
static const char kTestData[] = "Injected extension stream!"; static constexpr char kTestData[] = "Injected extension stream!";
return base::WrapUnique(new crashpad::test::BufferExtensionStreamDataSource( return base::WrapUnique(new crashpad::test::BufferExtensionStreamDataSource(
0xCAFEBABE, kTestData, sizeof(kTestData))); 0xCAFEBABE, kTestData, sizeof(kTestData)));

View File

@ -436,7 +436,7 @@ int HandlerMain(int argc,
kOptionVersion = -3, kOptionVersion = -3,
}; };
const option long_options[] = { static constexpr option long_options[] = {
{"annotation", required_argument, nullptr, kOptionAnnotation}, {"annotation", required_argument, nullptr, kOptionAnnotation},
{"database", required_argument, nullptr, kOptionDatabase}, {"database", required_argument, nullptr, kOptionDatabase},
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
@ -714,7 +714,7 @@ int HandlerMain(int argc,
base::GlobalHistogramAllocator* histogram_allocator = nullptr; base::GlobalHistogramAllocator* histogram_allocator = nullptr;
if (!options.metrics_dir.empty()) { if (!options.metrics_dir.empty()) {
static const char kMetricsName[] = "CrashpadMetrics"; static constexpr char kMetricsName[] = "CrashpadMetrics";
const size_t kMetricsFileSize = 1 << 20; const size_t kMetricsFileSize = 1 << 20;
if (base::GlobalHistogramAllocator::CreateWithActiveFileInDir( if (base::GlobalHistogramAllocator::CreateWithActiveFileInDir(
options.metrics_dir, kMetricsFileSize, 0, kMetricsName)) { options.metrics_dir, kMetricsFileSize, 0, kMetricsName)) {

View File

@ -63,20 +63,20 @@ void AllocateMemoryOfVariousProtections() {
const size_t kPageSize = system_info.dwPageSize; const size_t kPageSize = system_info.dwPageSize;
const uint32_t kPageTypes[] = { static constexpr uint32_t kPageTypes[] = {
PAGE_NOACCESS, PAGE_NOACCESS,
PAGE_READONLY, PAGE_READONLY,
PAGE_READWRITE, PAGE_READWRITE,
PAGE_EXECUTE, PAGE_EXECUTE,
PAGE_EXECUTE_READ, PAGE_EXECUTE_READ,
PAGE_EXECUTE_READWRITE, PAGE_EXECUTE_READWRITE,
// PAGE_NOACCESS is invalid with PAGE_GUARD. // PAGE_NOACCESS is invalid with PAGE_GUARD.
PAGE_READONLY | PAGE_GUARD, PAGE_READONLY | PAGE_GUARD,
PAGE_READWRITE | PAGE_GUARD, PAGE_READWRITE | PAGE_GUARD,
PAGE_EXECUTE | PAGE_GUARD, PAGE_EXECUTE | PAGE_GUARD,
PAGE_EXECUTE_READ | PAGE_GUARD, PAGE_EXECUTE_READ | PAGE_GUARD,
PAGE_EXECUTE_READWRITE | PAGE_GUARD, PAGE_EXECUTE_READWRITE | PAGE_GUARD,
}; };
// All of these allocations are leaked, we want to view them in windbg via // All of these allocations are leaked, we want to view them in windbg via

View File

@ -130,10 +130,10 @@ TEST(MinidumpCrashpadInfoWriter, SimpleAnnotations) {
auto crashpad_info_writer = auto crashpad_info_writer =
base::WrapUnique(new MinidumpCrashpadInfoWriter()); base::WrapUnique(new MinidumpCrashpadInfoWriter());
const char kKey[] = static constexpr char kKey[] =
"a thing that provides a means of gaining access to or understanding " "a thing that provides a means of gaining access to or understanding "
"something"; "something";
const char kValue[] = static constexpr char kValue[] =
"the numerical amount denoted by an algebraic term; a magnitude, " "the numerical amount denoted by an algebraic term; a magnitude, "
"quantity, or number"; "quantity, or number";
auto simple_string_dictionary_writer = auto simple_string_dictionary_writer =
@ -230,9 +230,9 @@ TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) {
ASSERT_TRUE( ASSERT_TRUE(
client_id.InitializeFromString("fedcba98-7654-3210-0123-456789abcdef")); client_id.InitializeFromString("fedcba98-7654-3210-0123-456789abcdef"));
const char kKey[] = "version"; static constexpr char kKey[] = "version";
const char kValue[] = "40.0.2214.111"; static constexpr char kValue[] = "40.0.2214.111";
const char kEntry[] = "This is a simple annotation in a list."; static constexpr char kEntry[] = "This is a simple annotation in a list.";
// Test with a useless module, one that doesnt carry anything that would // Test with a useless module, one that doesnt carry anything that would
// require MinidumpCrashpadInfo or any child object. // require MinidumpCrashpadInfo or any child object.

View File

@ -134,7 +134,7 @@ TEST(MinidumpFileWriter, AddUserExtensionStream) {
const time_t kTimestamp = 0x155d2fb8; const time_t kTimestamp = 0x155d2fb8;
minidump_file.SetTimestamp(kTimestamp); minidump_file.SetTimestamp(kTimestamp);
static const uint8_t kStreamData[] = "Hello World!"; static constexpr uint8_t kStreamData[] = "Hello World!";
const size_t kStreamSize = arraysize(kStreamData); const size_t kStreamSize = arraysize(kStreamData);
const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d); const MinidumpStreamType kStreamType = static_cast<MinidumpStreamType>(0x4d);
@ -270,7 +270,7 @@ TEST(MinidumpFileWriter, ThreeStreams) {
std::string expected_stream0(kStream0Size, kStream0Value); std::string expected_stream0(kStream0Size, kStream0Value);
EXPECT_EQ(memcmp(stream0_data, expected_stream0.c_str(), kStream0Size), 0); EXPECT_EQ(memcmp(stream0_data, expected_stream0.c_str(), kStream0Size), 0);
const int kZeroes[16] = {}; static constexpr int kZeroes[16] = {};
ASSERT_GE(sizeof(kZeroes), kStream1Padding); ASSERT_GE(sizeof(kZeroes), kStream1Padding);
EXPECT_EQ(memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding), 0); EXPECT_EQ(memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding), 0);

View File

@ -101,25 +101,25 @@ std::string MinidumpMiscInfoDebugBuildString() {
// plus a UTF-16 NUL terminator. Dont let strings get longer than this, or // plus a UTF-16 NUL terminator. Dont let strings get longer than this, or
// they will be truncated and a message will be logged. // they will be truncated and a message will be logged.
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
const char kOS[] = "mac"; static constexpr char kOS[] = "mac";
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
const char kOS[] = "android"; static constexpr char kOS[] = "android";
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
const char kOS[] = "linux"; static constexpr char kOS[] = "linux";
#elif defined(OS_WIN) #elif defined(OS_WIN)
const char kOS[] = "win"; static constexpr char kOS[] = "win";
#else #else
#error define kOS for this operating system #error define kOS for this operating system
#endif #endif
#if defined(ARCH_CPU_X86) #if defined(ARCH_CPU_X86)
const char kCPU[] = "i386"; static constexpr char kCPU[] = "i386";
#elif defined(ARCH_CPU_X86_64) #elif defined(ARCH_CPU_X86_64)
const char kCPU[] = "amd64"; static constexpr char kCPU[] = "amd64";
#elif defined(ARCH_CPU_ARMEL) #elif defined(ARCH_CPU_ARMEL)
const char kCPU[] = "arm"; static constexpr char kCPU[] = "arm";
#elif defined(ARCH_CPU_ARM64) #elif defined(ARCH_CPU_ARM64)
const char kCPU[] = "arm64"; static constexpr char kCPU[] = "arm64";
#else #else
#error define kCPU for this CPU #error define kCPU for this CPU
#endif #endif

View File

@ -368,10 +368,10 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
const uint32_t kTimeZoneId = 2; const uint32_t kTimeZoneId = 2;
const int32_t kBias = 300; const int32_t kBias = 300;
const char kStandardName[] = "EST"; static constexpr char kStandardName[] = "EST";
const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0}; const SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0};
const int32_t kStandardBias = 0; const int32_t kStandardBias = 0;
const char kDaylightName[] = "EDT"; static constexpr char kDaylightName[] = "EDT";
const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0}; const SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0};
const int32_t kDaylightBias = -60; const int32_t kDaylightBias = -60;
@ -482,8 +482,8 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
MinidumpFileWriter minidump_file_writer; MinidumpFileWriter minidump_file_writer;
auto misc_info_writer = base::WrapUnique(new MinidumpMiscInfoWriter()); auto misc_info_writer = base::WrapUnique(new MinidumpMiscInfoWriter());
const char kBuildString[] = "build string"; static constexpr char kBuildString[] = "build string";
const char kDebugBuildString[] = "debug build string"; static constexpr char kDebugBuildString[] = "debug build string";
misc_info_writer->SetBuildString(kBuildString, kDebugBuildString); misc_info_writer->SetBuildString(kBuildString, kDebugBuildString);
@ -622,13 +622,13 @@ TEST(MinidumpMiscInfoWriter, Everything) {
const uint32_t kProtectedProcess = 1; const uint32_t kProtectedProcess = 1;
const uint32_t kTimeZoneId = 2; const uint32_t kTimeZoneId = 2;
const int32_t kBias = 300; const int32_t kBias = 300;
const char kStandardName[] = "EST"; static constexpr char kStandardName[] = "EST";
const int32_t kStandardBias = 0; const int32_t kStandardBias = 0;
const char kDaylightName[] = "EDT"; static constexpr char kDaylightName[] = "EDT";
const int32_t kDaylightBias = -60; const int32_t kDaylightBias = -60;
const SYSTEMTIME kSystemTimeZero = {}; const SYSTEMTIME kSystemTimeZero = {};
const char kBuildString[] = "build string"; static constexpr char kBuildString[] = "build string";
const char kDebugBuildString[] = "debug build string"; static constexpr char kDebugBuildString[] = "debug build string";
misc_info_writer->SetProcessID(kProcessId); misc_info_writer->SetProcessID(kProcessId);
misc_info_writer->SetProcessTimes( misc_info_writer->SetProcessTimes(
@ -711,14 +711,15 @@ TEST(MinidumpMiscInfoWriter, Everything) {
TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) { TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
MINIDUMP_MISC_INFO_4 expect_misc_info = {}; MINIDUMP_MISC_INFO_4 expect_misc_info = {};
const char kStandardTimeName[] = "EST"; static constexpr char kStandardTimeName[] = "EST";
const char kDaylightTimeName[] = "EDT"; static constexpr char kDaylightTimeName[] = "EDT";
const char kOSVersionFull[] = static constexpr char kOSVersionFull[] =
"Mac OS X 10.9.5 (13F34); " "Mac OS X 10.9.5 (13F34); "
"Darwin 13.4.0 Darwin Kernel Version 13.4.0: " "Darwin 13.4.0 Darwin Kernel Version 13.4.0: "
"Sun Aug 17 19:50:11 PDT 2014; " "Sun Aug 17 19:50:11 PDT 2014; "
"root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"; "root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64";
const char kMachineDescription[] = "MacBookPro11,3 (Mac-2BD1B31983FE1663)"; static constexpr char kMachineDescription[] =
"MacBookPro11,3 (Mac-2BD1B31983FE1663)";
base::string16 standard_time_name_utf16 = base::string16 standard_time_name_utf16 =
base::UTF8ToUTF16(kStandardTimeName); base::UTF8ToUTF16(kStandardTimeName);
base::string16 daylight_time_name_utf16 = base::string16 daylight_time_name_utf16 =

View File

@ -109,9 +109,9 @@ TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) {
TEST(MinidumpModuleCrashpadInfoWriter, FullModule) { TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
const uint32_t kMinidumpModuleListIndex = 1; const uint32_t kMinidumpModuleListIndex = 1;
const char kKey[] = "key"; static constexpr char kKey[] = "key";
const char kValue[] = "value"; static constexpr char kValue[] = "value";
const char kEntry[] = "entry"; static constexpr char kEntry[] = "entry";
std::vector<std::string> vector(1, std::string(kEntry)); std::vector<std::string> vector(1, std::string(kEntry));
StringFile string_file; StringFile string_file;
@ -195,14 +195,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) { TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
const uint32_t kMinidumpModuleListIndex0 = 0; const uint32_t kMinidumpModuleListIndex0 = 0;
const char kKey0[] = "key"; static constexpr char kKey0[] = "key";
const char kValue0[] = "value"; static constexpr char kValue0[] = "value";
const uint32_t kMinidumpModuleListIndex1 = 2; const uint32_t kMinidumpModuleListIndex1 = 2;
const uint32_t kMinidumpModuleListIndex2 = 5; const uint32_t kMinidumpModuleListIndex2 = 5;
const char kKey2A[] = "K"; static constexpr char kKey2A[] = "K";
const char kValue2A[] = "VVV"; static constexpr char kValue2A[] = "VVV";
const char kKey2B[] = "river"; static constexpr char kKey2B[] = "river";
const char kValue2B[] = "hudson"; static constexpr char kValue2B[] = "hudson";
StringFile string_file; StringFile string_file;
@ -339,14 +339,14 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
} }
TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) { TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
const char kKey0A[] = "k"; static constexpr char kKey0A[] = "k";
const char kValue0A[] = "value"; static constexpr char kValue0A[] = "value";
const char kKey0B[] = "hudson"; static constexpr char kKey0B[] = "hudson";
const char kValue0B[] = "estuary"; static constexpr char kValue0B[] = "estuary";
const char kKey2[] = "k"; static constexpr char kKey2[] = "k";
const char kValue2[] = "different_value"; static constexpr char kValue2[] = "different_value";
const char kEntry3A[] = "list"; static constexpr char kEntry3A[] = "list";
const char kEntry3B[] = "erine"; static constexpr char kEntry3B[] = "erine";
std::vector<const ModuleSnapshot*> module_snapshots; std::vector<const ModuleSnapshot*> module_snapshots;

View File

@ -271,7 +271,7 @@ TEST(MinidumpModuleWriter, EmptyModule) {
MinidumpFileWriter minidump_file_writer; MinidumpFileWriter minidump_file_writer;
auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter());
const char kModuleName[] = "test_executable"; static constexpr char kModuleName[] = "test_executable";
auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); auto module_writer = base::WrapUnique(new MinidumpModuleWriter());
module_writer->SetName(kModuleName); module_writer->SetName(kModuleName);
@ -310,7 +310,7 @@ TEST(MinidumpModuleWriter, OneModule) {
MinidumpFileWriter minidump_file_writer; MinidumpFileWriter minidump_file_writer;
auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter());
const char kModuleName[] = "statically_linked"; static constexpr char kModuleName[] = "statically_linked";
const uint64_t kModuleBase = 0x10da69000; const uint64_t kModuleBase = 0x10da69000;
const uint32_t kModuleSize = 0x1000; const uint32_t kModuleSize = 0x1000;
const uint32_t kChecksum = 0x76543210; const uint32_t kChecksum = 0x76543210;
@ -326,15 +326,15 @@ TEST(MinidumpModuleWriter, OneModule) {
const uint32_t kFileOS = VOS_DOS; const uint32_t kFileOS = VOS_DOS;
const uint32_t kFileType = VFT_DRV; const uint32_t kFileType = VFT_DRV;
const uint32_t kFileSubtype = VFT2_DRV_KEYBOARD; const uint32_t kFileSubtype = VFT2_DRV_KEYBOARD;
const char kPDBName[] = "statical.pdb"; static constexpr char kPDBName[] = "statical.pdb";
const uint8_t kPDBUUIDBytes[16] = static constexpr uint8_t kPDBUUIDBytes[16] =
{0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
0x08, 0x19, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f}; 0x08, 0x19, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f};
UUID pdb_uuid; UUID pdb_uuid;
pdb_uuid.InitializeFromBytes(kPDBUUIDBytes); pdb_uuid.InitializeFromBytes(kPDBUUIDBytes);
const uint32_t kPDBAge = 1; const uint32_t kPDBAge = 1;
const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME; const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME;
const char kDebugName[] = "statical.dbg"; static constexpr char kDebugName[] = "statical.dbg";
const bool kDebugUTF16 = false; const bool kDebugUTF16 = false;
auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); auto module_writer = base::WrapUnique(new MinidumpModuleWriter());
@ -419,12 +419,12 @@ TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) {
MinidumpFileWriter minidump_file_writer; MinidumpFileWriter minidump_file_writer;
auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter());
const char kModuleName[] = "dinosaur"; static constexpr char kModuleName[] = "dinosaur";
const char kPDBName[] = "d1n05.pdb"; static constexpr char kPDBName[] = "d1n05.pdb";
const time_t kPDBTimestamp = 0x386d4380; const time_t kPDBTimestamp = 0x386d4380;
const uint32_t kPDBAge = 1; const uint32_t kPDBAge = 1;
const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME; const uint32_t kDebugType = IMAGE_DEBUG_MISC_EXENAME;
const char kDebugName[] = "d1n05.dbg"; static constexpr char kDebugName[] = "d1n05.dbg";
const bool kDebugUTF16 = true; const bool kDebugUTF16 = true;
auto module_writer = base::WrapUnique(new MinidumpModuleWriter()); auto module_writer = base::WrapUnique(new MinidumpModuleWriter());
@ -480,25 +480,25 @@ TEST(MinidumpModuleWriter, ThreeModules) {
MinidumpFileWriter minidump_file_writer; MinidumpFileWriter minidump_file_writer;
auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter()); auto module_list_writer = base::WrapUnique(new MinidumpModuleListWriter());
const char kModuleName0[] = "main"; static constexpr char kModuleName0[] = "main";
const uint64_t kModuleBase0 = 0x100101000; const uint64_t kModuleBase0 = 0x100101000;
const uint32_t kModuleSize0 = 0xf000; const uint32_t kModuleSize0 = 0xf000;
const char kPDBName0[] = "main"; static constexpr char kPDBName0[] = "main";
const uint8_t kPDBUUIDBytes0[16] = static constexpr uint8_t kPDBUUIDBytes0[16] =
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11,
0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}; 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99};
UUID pdb_uuid_0; UUID pdb_uuid_0;
pdb_uuid_0.InitializeFromBytes(kPDBUUIDBytes0); pdb_uuid_0.InitializeFromBytes(kPDBUUIDBytes0);
const uint32_t kPDBAge0 = 0; const uint32_t kPDBAge0 = 0;
const char kModuleName1[] = "ld.so"; static constexpr char kModuleName1[] = "ld.so";
const uint64_t kModuleBase1 = 0x200202000; const uint64_t kModuleBase1 = 0x200202000;
const uint32_t kModuleSize1 = 0x1e000; const uint32_t kModuleSize1 = 0x1e000;
const char kModuleName2[] = "libc.so"; static constexpr char kModuleName2[] = "libc.so";
const uint64_t kModuleBase2 = 0x300303000; const uint64_t kModuleBase2 = 0x300303000;
const uint32_t kModuleSize2 = 0x2d000; const uint32_t kModuleSize2 = 0x2d000;
const char kPDBName2[] = "libc.so"; static constexpr char kPDBName2[] = "libc.so";
const time_t kPDBTimestamp2 = 0x386d4380; const time_t kPDBTimestamp2 = 0x386d4380;
const uint32_t kPDBAge2 = 2; const uint32_t kPDBAge2 = 2;
@ -668,7 +668,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
expect_modules[0].VersionInfo.dwFileType = VFT_APP; expect_modules[0].VersionInfo.dwFileType = VFT_APP;
module_paths[0] = "/usr/bin/true"; module_paths[0] = "/usr/bin/true";
module_pdbs[0] = "true"; module_pdbs[0] = "true";
const uint8_t kUUIDBytes0[16] = static constexpr uint8_t kUUIDBytes0[16] =
{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
uuids[0].InitializeFromBytes(kUUIDBytes0); uuids[0].InitializeFromBytes(kUUIDBytes0);
@ -684,7 +684,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
expect_modules[1].VersionInfo.dwFileType = VFT_DLL; expect_modules[1].VersionInfo.dwFileType = VFT_DLL;
module_paths[1] = "/usr/lib/libSystem.B.dylib"; module_paths[1] = "/usr/lib/libSystem.B.dylib";
module_pdbs[1] = "libSystem.B.dylib.pdb"; module_pdbs[1] = "libSystem.B.dylib.pdb";
const uint8_t kUUIDBytes1[16] = static constexpr uint8_t kUUIDBytes1[16] =
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uuids[1].InitializeFromBytes(kUUIDBytes1); uuids[1].InitializeFromBytes(kUUIDBytes1);
@ -700,7 +700,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN; expect_modules[2].VersionInfo.dwFileType = VFT_UNKNOWN;
module_paths[2] = "/usr/lib/dyld"; module_paths[2] = "/usr/lib/dyld";
module_pdbs[2] = "/usr/lib/dyld.pdb"; module_pdbs[2] = "/usr/lib/dyld.pdb";
const uint8_t kUUIDBytes2[16] = static constexpr uint8_t kUUIDBytes2[16] =
{0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0}; 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0};
uuids[2].InitializeFromBytes(kUUIDBytes2); uuids[2].InitializeFromBytes(kUUIDBytes2);

View File

@ -76,7 +76,7 @@ TEST(MinidumpRVAListWriter, OneChild) {
TEST(MinidumpRVAListWriter, ThreeChildren) { TEST(MinidumpRVAListWriter, ThreeChildren) {
TestMinidumpRVAListWriter list_writer; TestMinidumpRVAListWriter list_writer;
const uint32_t kValues[] = { 0x80000000, 0x55555555, 0x66006600 }; static constexpr uint32_t kValues[] = {0x80000000, 0x55555555, 0x66006600};
list_writer.AddChild(kValues[0]); list_writer.AddChild(kValues[0]);
list_writer.AddChild(kValues[1]); list_writer.AddChild(kValues[1]);

View File

@ -49,7 +49,7 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
base::string16()); base::string16());
} }
const struct { static constexpr struct {
size_t input_length; size_t input_length;
const char* input_string; const char* input_string;
size_t output_length; size_t output_length;
@ -106,7 +106,7 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) { TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
StringFile string_file; StringFile string_file;
const char* kTestData[] = { static constexpr const char* kTestData[] = {
"\200", // continuation byte "\200", // continuation byte
"\300", // start byte followed by EOF "\300", // start byte followed by EOF
"\310\177", // start byte without continuation "\310\177", // start byte without continuation
@ -160,7 +160,7 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
std::string()); std::string());
} }
const struct { static constexpr struct {
size_t length; size_t length;
const char* string; const char* string;
} kTestData[] = { } kTestData[] = {

View File

@ -129,9 +129,9 @@ TEST(MinidumpSystemInfoWriter, X86_Win) {
const uint32_t kOSVersionMajor = 6; const uint32_t kOSVersionMajor = 6;
const uint32_t kOSVersionMinor = 1; const uint32_t kOSVersionMinor = 1;
const uint32_t kOSVersionBuild = 7601; const uint32_t kOSVersionBuild = 7601;
const char kCSDVersion[] = "Service Pack 1"; static constexpr char kCSDVersion[] = "Service Pack 1";
const uint16_t kSuiteMask = VER_SUITE_SINGLEUSERTS; const uint16_t kSuiteMask = VER_SUITE_SINGLEUSERTS;
const char kCPUVendor[] = "AuthenticAMD"; static constexpr char kCPUVendor[] = "AuthenticAMD";
const uint32_t kCPUVersion = 0x00100f62; const uint32_t kCPUVersion = 0x00100f62;
const uint32_t kCPUFeatures = 0x078bfbff; const uint32_t kCPUFeatures = 0x078bfbff;
const uint32_t kAMDFeatures = 0xefd3fbff; const uint32_t kAMDFeatures = 0xefd3fbff;
@ -200,8 +200,8 @@ TEST(MinidumpSystemInfoWriter, AMD64_Mac) {
const uint32_t kOSVersionMajor = 10; const uint32_t kOSVersionMajor = 10;
const uint32_t kOSVersionMinor = 9; const uint32_t kOSVersionMinor = 9;
const uint32_t kOSVersionBuild = 4; const uint32_t kOSVersionBuild = 4;
const char kCSDVersion[] = "13E28"; static constexpr char kCSDVersion[] = "13E28";
const uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000}; static constexpr uint64_t kCPUFeatures[2] = {0x10427f4c, 0x00000000};
system_info_writer->SetCPUArchitecture(kCPUArchitecture); system_info_writer->SetCPUArchitecture(kCPUArchitecture);
system_info_writer->SetCPULevelAndRevision(kCPULevel, kCPURevision); system_info_writer->SetCPULevelAndRevision(kCPULevel, kCPURevision);
@ -248,7 +248,7 @@ TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) {
auto system_info_writer = base::WrapUnique(new MinidumpSystemInfoWriter()); auto system_info_writer = base::WrapUnique(new MinidumpSystemInfoWriter());
const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86; const MinidumpCPUArchitecture kCPUArchitecture = kMinidumpCPUArchitectureX86;
const uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'}; static constexpr uint32_t kCPUVendor[] = {'uneG', 'Ieni', 'letn'};
system_info_writer->SetCPUArchitecture(kCPUArchitecture); system_info_writer->SetCPUArchitecture(kCPUArchitecture);
system_info_writer->SetCPUX86Vendor( system_info_writer->SetCPUX86Vendor(
@ -313,8 +313,8 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) {
expect_system_info.Cpu.X86CpuInfo.VersionInformation = kCPUSignature; expect_system_info.Cpu.X86CpuInfo.VersionInformation = kCPUSignature;
expect_system_info.Cpu.X86CpuInfo.FeatureInformation = expect_system_info.Cpu.X86CpuInfo.FeatureInformation =
kCPUX86Features & 0xffffffff; kCPUX86Features & 0xffffffff;
const char kCPUVendor[] = "GenuineIntel"; static constexpr char kCPUVendor[] = "GenuineIntel";
const char kOSVersionBuild[] = "13F34"; static constexpr char kOSVersionBuild[] = "13F34";
TestSystemSnapshot system_snapshot; TestSystemSnapshot system_snapshot;
system_snapshot.SetCPUArchitecture(kCPUArchitectureX86); system_snapshot.SetCPUArchitecture(kCPUArchitectureX86);
@ -408,7 +408,7 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_AMD64) {
(1 << PF_RDRAND_INSTRUCTION_AVAILABLE) | (1 << PF_RDRAND_INSTRUCTION_AVAILABLE) |
(UINT64_C(1) << PF_RDTSCP_INSTRUCTION_AVAILABLE); (UINT64_C(1) << PF_RDTSCP_INSTRUCTION_AVAILABLE);
expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1] = 0; expect_system_info.Cpu.OtherCpuInfo.ProcessorFeatures[1] = 0;
const char kOSVersionBuild[] = "13F34"; static constexpr char kOSVersionBuild[] = "13F34";
TestSystemSnapshot system_snapshot; TestSystemSnapshot system_snapshot;
system_snapshot.SetCPUArchitecture(kCPUArchitectureX86_64); system_snapshot.SetCPUArchitecture(kCPUArchitectureX86_64);

View File

@ -74,7 +74,7 @@ TEST(MinidumpUnloadedModuleWriter, EmptyModule) {
auto unloaded_module_list_writer = auto unloaded_module_list_writer =
base::WrapUnique(new MinidumpUnloadedModuleListWriter()); base::WrapUnique(new MinidumpUnloadedModuleListWriter());
const char kModuleName[] = "test_dll"; static constexpr char kModuleName[] = "test_dll";
auto unloaded_module_writer = auto unloaded_module_writer =
base::WrapUnique(new MinidumpUnloadedModuleWriter()); base::WrapUnique(new MinidumpUnloadedModuleWriter());
@ -113,7 +113,7 @@ TEST(MinidumpUnloadedModuleWriter, OneModule) {
auto unloaded_module_list_writer = auto unloaded_module_list_writer =
base::WrapUnique(new MinidumpUnloadedModuleListWriter()); base::WrapUnique(new MinidumpUnloadedModuleListWriter());
const char kModuleName[] = "statically_linked"; static constexpr char kModuleName[] = "statically_linked";
const uint64_t kModuleBase = 0x10da69000; const uint64_t kModuleBase = 0x10da69000;
const uint32_t kModuleSize = 0x1000; const uint32_t kModuleSize = 0x1000;
const uint32_t kChecksum = 0x76543210; const uint32_t kChecksum = 0x76543210;

View File

@ -248,7 +248,7 @@ bool MinidumpWritable::WritePaddingAndObject(FileWriterInterface* file_writer) {
// The number of elements in kZeroes must be at least one less than the // The number of elements in kZeroes must be at least one less than the
// maximum Alignment() ever encountered. // maximum Alignment() ever encountered.
const uint8_t kZeroes[kMaximumAlignment - 1] = {}; static constexpr uint8_t kZeroes[kMaximumAlignment - 1] = {};
DCHECK_LE(leading_pad_bytes_, arraysize(kZeroes)); DCHECK_LE(leading_pad_bytes_, arraysize(kZeroes));
if (leading_pad_bytes_) { if (leading_pad_bytes_) {

View File

@ -81,7 +81,7 @@ TEST(ProcessReader, SelfBasic) {
EXPECT_EQ(process_reader.ProcessID(), getpid()); EXPECT_EQ(process_reader.ProcessID(), getpid());
EXPECT_EQ(process_reader.ParentProcessID(), getppid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid());
const char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[arraysize(kTestMemory)]; char buffer[arraysize(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
reinterpret_cast<LinuxVMAddress>(kTestMemory), reinterpret_cast<LinuxVMAddress>(kTestMemory),
@ -90,7 +90,7 @@ TEST(ProcessReader, SelfBasic) {
EXPECT_STREQ(kTestMemory, buffer); EXPECT_STREQ(kTestMemory, buffer);
} }
const char kTestMemory[] = "Read me from another process"; constexpr char kTestMemory[] = "Read me from another process";
class BasicChildTest : public Multiprocess { class BasicChildTest : public Multiprocess {
public: public:

View File

@ -212,7 +212,8 @@ class TestMachOImageAnnotationsReader final
// dyld exposes its error_string at least as far back as Mac OS X 10.4. // dyld exposes its error_string at least as far back as Mac OS X 10.4.
if (test_type_ == kCrashDyld) { if (test_type_ == kCrashDyld) {
const char kExpectedAnnotation[] = "could not load inserted library"; static constexpr char kExpectedAnnotation[] =
"could not load inserted library";
size_t expected_annotation_length = strlen(kExpectedAnnotation); size_t expected_annotation_length = strlen(kExpectedAnnotation);
bool found = false; bool found = false;
for (const std::string& annotation : all_annotations_vector) { for (const std::string& annotation : all_annotations_vector) {

View File

@ -53,7 +53,7 @@ TEST(MachOImageSegmentReader, SegmentNameString) {
// Segment names defined in <mach-o/loader.h>. All of these should come // Segment names defined in <mach-o/loader.h>. All of these should come
// through SegmentNameString() cleanly and without truncation. // through SegmentNameString() cleanly and without truncation.
const char* kSegmentTestData[] = { static constexpr const char* kSegmentTestData[] = {
SEG_TEXT, SEG_TEXT,
SEG_DATA, SEG_DATA,
SEG_OBJC, SEG_OBJC,
@ -91,7 +91,7 @@ TEST(MachOImageSegmentReader, SectionNameString) {
// Section names defined in <mach-o/loader.h>. All of these should come // Section names defined in <mach-o/loader.h>. All of these should come
// through SectionNameString() cleanly and without truncation. // through SectionNameString() cleanly and without truncation.
const char* kSectionTestData[] = { static constexpr const char* kSectionTestData[] = {
SECT_TEXT, SECT_TEXT,
SECT_FVMLIB_INIT0, SECT_FVMLIB_INIT0,
SECT_FVMLIB_INIT1, SECT_FVMLIB_INIT1,
@ -115,12 +115,11 @@ TEST(MachOImageSegmentReader, SectionNameString) {
} }
TEST(MachOImageSegmentReader, SegmentAndSectionNameString) { TEST(MachOImageSegmentReader, SegmentAndSectionNameString) {
struct SegmentAndSectionTestData { static constexpr struct {
const char* segment; const char* segment;
const char* section; const char* section;
const char* output; const char* output;
}; } kSegmentAndSectionTestData[] = {
const SegmentAndSectionTestData kSegmentAndSectionTestData[] = {
{"segment", "section", "segment,section"}, {"segment", "section", "segment,section"},
{"Segment", "Section", "Segment,Section"}, {"Segment", "Section", "Segment,Section"},
{"SEGMENT", "SECTION", "SEGMENT,SECTION"}, {"SEGMENT", "SECTION", "SEGMENT,SECTION"},
@ -172,7 +171,7 @@ TEST(MachOImageSegmentReader, SegmentAndSectionNameString) {
for (size_t index = 0; index < arraysize(kSegmentAndSectionTestData); for (size_t index = 0; index < arraysize(kSegmentAndSectionTestData);
++index) { ++index) {
const SegmentAndSectionTestData& test = kSegmentAndSectionTestData[index]; const auto& test = kSegmentAndSectionTestData[index];
EXPECT_EQ(MachOImageSegmentReader::SegmentAndSectionNameString( EXPECT_EQ(MachOImageSegmentReader::SegmentAndSectionNameString(
test.segment, test.section), test.segment, test.section),
test.output) test.output)

View File

@ -58,7 +58,7 @@ namespace crashpad {
namespace test { namespace test {
namespace { namespace {
const char kDyldPath[] = "/usr/lib/dyld"; constexpr char kDyldPath[] = "/usr/lib/dyld";
TEST(ProcessReader, SelfBasic) { TEST(ProcessReader, SelfBasic) {
ProcessReader process_reader; ProcessReader process_reader;
@ -73,7 +73,7 @@ TEST(ProcessReader, SelfBasic) {
EXPECT_EQ(process_reader.ProcessID(), getpid()); EXPECT_EQ(process_reader.ProcessID(), getpid());
EXPECT_EQ(process_reader.ParentProcessID(), getppid()); EXPECT_EQ(process_reader.ParentProcessID(), getppid());
const char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[arraysize(kTestMemory)]; char buffer[arraysize(kTestMemory)];
ASSERT_TRUE(process_reader.Memory()->Read( ASSERT_TRUE(process_reader.Memory()->Read(
FromPointerCast<mach_vm_address_t>(kTestMemory), FromPointerCast<mach_vm_address_t>(kTestMemory),
@ -82,7 +82,7 @@ TEST(ProcessReader, SelfBasic) {
EXPECT_STREQ(kTestMemory, buffer); EXPECT_STREQ(kTestMemory, buffer);
} }
const char kTestMemory[] = "Read me from another process"; constexpr char kTestMemory[] = "Read me from another process";
class ProcessReaderChild final : public MachMultiprocess { class ProcessReaderChild final : public MachMultiprocess {
public: public:

View File

@ -65,7 +65,7 @@ bool ReadIntoVersioned(ProcessReader* process_reader,
template <typename Traits> template <typename Traits>
size_t dyld_all_image_infos<Traits>::ExpectedSizeForVersion( size_t dyld_all_image_infos<Traits>::ExpectedSizeForVersion(
decltype(dyld_all_image_infos<Traits>::version) version) { decltype(dyld_all_image_infos<Traits>::version) version) {
const size_t kSizeForVersion[] = { static constexpr size_t kSizeForVersion[] = {
offsetof(dyld_all_image_infos<Traits>, infoArrayCount), // 0 offsetof(dyld_all_image_infos<Traits>, infoArrayCount), // 0
offsetof(dyld_all_image_infos<Traits>, libSystemInitialized), // 1 offsetof(dyld_all_image_infos<Traits>, libSystemInitialized), // 1
offsetof(dyld_all_image_infos<Traits>, jitInfo), // 2 offsetof(dyld_all_image_infos<Traits>, jitInfo), // 2

View File

@ -364,9 +364,9 @@ void SystemSnapshotMac::TimeZone(DaylightSavingTimeStatus* dst_status,
// no transitions to or from daylight saving time occurred or will occur // no transitions to or from daylight saving time occurred or will occur
// within a year of the current date. Arizona, which last observed daylight // within a year of the current date. Arizona, which last observed daylight
// saving time in 1967, is an example. // saving time in 1967, is an example.
const int kMonthDeltas[] = static constexpr int kMonthDeltas[] =
{ 0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, {0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6,
7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12 }; 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12};
for (size_t index = 0; for (size_t index = 0;
index < arraysize(kMonthDeltas) && !found_transition; index < arraysize(kMonthDeltas) && !found_transition;
++index) { ++index) {

View File

@ -210,7 +210,7 @@ TEST_F(SystemSnapshotMacTest, TimeZone) {
// standard_name and daylight_name can be nullptr where no name exists to // standard_name and daylight_name can be nullptr where no name exists to
// verify, as may happen when some versions of the timezone database carry // verify, as may happen when some versions of the timezone database carry
// invented names and others do not. // invented names and others do not.
const struct { static constexpr struct {
const char* tz; const char* tz;
bool observes_dst; bool observes_dst;
float standard_offset_hours; float standard_offset_hours;

View File

@ -128,7 +128,7 @@ TEST(PEImageReader, VSFixedFileInfo_OneModule) {
ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(), ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(),
ProcessSuspensionState::kRunning)); ProcessSuspensionState::kRunning));
const wchar_t kModuleName[] = L"kernel32.dll"; static constexpr wchar_t kModuleName[] = L"kernel32.dll";
const HMODULE module_handle = GetModuleHandle(kModuleName); const HMODULE module_handle = GetModuleHandle(kModuleName);
ASSERT_TRUE(module_handle) << ErrorMessage("GetModuleHandle"); ASSERT_TRUE(module_handle) << ErrorMessage("GetModuleHandle");

View File

@ -41,14 +41,14 @@ TEST(ProcessReaderWin, SelfBasic) {
EXPECT_EQ(process_reader.GetProcessInfo().ProcessID(), GetCurrentProcessId()); EXPECT_EQ(process_reader.GetProcessInfo().ProcessID(), GetCurrentProcessId());
const char kTestMemory[] = "Some test memory"; static constexpr char kTestMemory[] = "Some test memory";
char buffer[arraysize(kTestMemory)]; char buffer[arraysize(kTestMemory)];
ASSERT_TRUE(process_reader.ReadMemory( ASSERT_TRUE(process_reader.ReadMemory(
reinterpret_cast<uintptr_t>(kTestMemory), sizeof(kTestMemory), &buffer)); reinterpret_cast<uintptr_t>(kTestMemory), sizeof(kTestMemory), &buffer));
EXPECT_STREQ(kTestMemory, buffer); EXPECT_STREQ(kTestMemory, buffer);
} }
const char kTestMemory[] = "Read me from another process"; constexpr char kTestMemory[] = "Read me from another process";
class ProcessReaderChild final : public WinMultiprocess { class ProcessReaderChild final : public WinMultiprocess {
public: public:

View File

@ -528,7 +528,7 @@ WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock(
&env_block[0]); &env_block[0]);
env_block.resize( env_block.resize(
static_cast<unsigned int>(bytes_read / sizeof(env_block[0]))); static_cast<unsigned int>(bytes_read / sizeof(env_block[0])));
const wchar_t terminator[] = { 0, 0 }; static constexpr wchar_t terminator[] = {0, 0};
size_t at = env_block.find(std::wstring(terminator, arraysize(terminator))); size_t at = env_block.find(std::wstring(terminator, arraysize(terminator)));
if (at != std::wstring::npos) if (at != std::wstring::npos)
env_block.resize(at + arraysize(terminator)); env_block.resize(at + arraysize(terminator));

View File

@ -98,7 +98,7 @@ void SystemSnapshotWin::Initialize(ProcessReaderWin* process_reader) {
os_server_ = version_info.wProductType != VER_NT_WORKSTATION; os_server_ = version_info.wProductType != VER_NT_WORKSTATION;
} }
const wchar_t kSystemDll[] = L"kernel32.dll"; static constexpr wchar_t kSystemDll[] = L"kernel32.dll";
VS_FIXEDFILEINFO ffi; VS_FIXEDFILEINFO ffi;
if (GetModuleVersionAndType(base::FilePath(kSystemDll), &ffi)) { if (GetModuleVersionAndType(base::FilePath(kSystemDll), &ffi)) {
std::string flags_string = GetStringForFileFlags(ffi.dwFileFlags); std::string flags_string = GetStringForFileFlags(ffi.dwFileFlags);

View File

@ -28,11 +28,11 @@ bool FileExists(const base::FilePath& path) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
struct stat st; struct stat st;
int rv = lstat(path.value().c_str(), &st); int rv = lstat(path.value().c_str(), &st);
const char stat_function[] = "lstat"; static constexpr char stat_function[] = "lstat";
#elif defined(OS_WIN) #elif defined(OS_WIN)
struct _stat st; struct _stat st;
int rv = _wstat(path.value().c_str(), &st); int rv = _wstat(path.value().c_str(), &st);
const char stat_function[] = "_wstat"; static constexpr char stat_function[] = "_wstat";
#else #else
#error "Not implemented" #error "Not implemented"
#endif #endif
@ -48,11 +48,11 @@ FileOffset FileSize(const base::FilePath& path) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
struct stat st; struct stat st;
int rv = lstat(path.value().c_str(), &st); int rv = lstat(path.value().c_str(), &st);
const char stat_function[] = "lstat"; static constexpr char stat_function[] = "lstat";
#elif defined(OS_WIN) #elif defined(OS_WIN)
struct _stati64 st; struct _stati64 st;
int rv = _wstati64(path.value().c_str(), &st); int rv = _wstati64(path.value().c_str(), &st);
const char stat_function[] = "_wstati64"; static constexpr char stat_function[] = "_wstati64";
#else #else
#error "Not implemented" #error "Not implemented"
#endif #endif

View File

@ -24,7 +24,7 @@ namespace {
TEST(HexString, HexString) { TEST(HexString, HexString) {
EXPECT_EQ(BytesToHexString(nullptr, 0), ""); EXPECT_EQ(BytesToHexString(nullptr, 0), "");
const char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_"; static constexpr char kBytes[] = "Abc123xyz \x0a\x7f\xf0\x9f\x92\xa9_";
EXPECT_EQ(BytesToHexString(kBytes, arraysize(kBytes)), EXPECT_EQ(BytesToHexString(kBytes, arraysize(kBytes)),
"41626331323378797a200a7ff09f92a95f00"); "41626331323378797a200a7ff09f92a95f00");
} }

View File

@ -35,7 +35,7 @@ namespace test {
namespace { namespace {
const char kIsMultiprocessChild[] = "--is-multiprocess-child"; constexpr char kIsMultiprocessChild[] = "--is-multiprocess-child";
bool GetSwitch(const char* switch_name, std::string* value) { bool GetSwitch(const char* switch_name, std::string* value) {
int num_args; int num_args;

View File

@ -92,7 +92,7 @@ struct Options {
// performed. Various string representations of a boolean are recognized // performed. Various string representations of a boolean are recognized
// case-insensitively. // case-insensitively.
bool StringToBool(const char* string, bool* boolean) { bool StringToBool(const char* string, bool* boolean) {
const char* const kFalseWords[] = { static constexpr const char* kFalseWords[] = {
"0", "0",
"false", "false",
"no", "no",
@ -100,7 +100,7 @@ bool StringToBool(const char* string, bool* boolean) {
"disabled", "disabled",
"clear", "clear",
}; };
const char* const kTrueWords[] = { static constexpr const char* kTrueWords[] = {
"1", "1",
"true", "true",
"yes", "yes",
@ -153,7 +153,7 @@ bool StringToTime(const char* string, time_t* out_time, bool utc) {
const char* end = string + strlen(string); const char* end = string + strlen(string);
const char* const kFormats[] = { static constexpr const char* kFormats[] = {
"%Y-%m-%d %H:%M:%S %Z", "%Y-%m-%d %H:%M:%S %Z",
"%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S",
"%+", "%+",
@ -294,7 +294,7 @@ int DatabaseUtilMain(int argc, char* argv[]) {
kOptionVersion = -3, kOptionVersion = -3,
}; };
const option long_options[] = { static constexpr option long_options[] = {
{"create", no_argument, nullptr, kOptionCreate}, {"create", no_argument, nullptr, kOptionCreate},
{"database", required_argument, nullptr, kOptionDatabase}, {"database", required_argument, nullptr, kOptionDatabase},
{"show-client-id", no_argument, nullptr, kOptionShowClientID}, {"show-client-id", no_argument, nullptr, kOptionShowClientID},

View File

@ -74,7 +74,7 @@ int HTTPUploadMain(int argc, char* argv[]) {
} options = {}; } options = {};
options.upload_gzip = true; options.upload_gzip = true;
const option long_options[] = { static constexpr option long_options[] = {
{"file", required_argument, nullptr, kOptionFile}, {"file", required_argument, nullptr, kOptionFile},
{"no-upload-gzip", no_argument, nullptr, kOptionNoUploadGzip}, {"no-upload-gzip", no_argument, nullptr, kOptionNoUploadGzip},
{"output", required_argument, nullptr, kOptionOutput}, {"output", required_argument, nullptr, kOptionOutput},

View File

@ -85,7 +85,7 @@ int GenerateDumpMain(int argc, char* argv[]) {
} options = {}; } options = {};
options.suspend = true; options.suspend = true;
const option long_options[] = { static constexpr option long_options[] = {
{"no-suspend", no_argument, nullptr, kOptionNoSuspend}, {"no-suspend", no_argument, nullptr, kOptionNoSuspend},
{"output", required_argument, nullptr, kOptionOutput}, {"output", required_argument, nullptr, kOptionOutput},
{"help", no_argument, nullptr, kOptionHelp}, {"help", no_argument, nullptr, kOptionHelp},

View File

@ -214,7 +214,7 @@ int CatchExceptionToolMain(int argc, char* argv[]) {
Options options = {}; Options options = {};
const option long_options[] = { static constexpr option long_options[] = {
{"file", required_argument, nullptr, kOptionFile}, {"file", required_argument, nullptr, kOptionFile},
{"mach-service", required_argument, nullptr, kOptionMachService}, {"mach-service", required_argument, nullptr, kOptionMachService},
{"persistent", no_argument, nullptr, kOptionPersistent}, {"persistent", no_argument, nullptr, kOptionPersistent},

View File

@ -106,8 +106,8 @@ struct ExceptionHandlerDescription {
std::string handler; std::string handler;
}; };
const char kHandlerNull[] = "NULL"; constexpr char kHandlerNull[] = "NULL";
const char kHandlerBootstrapColon[] = "bootstrap:"; constexpr char kHandlerBootstrapColon[] = "bootstrap:";
// Populates |description| based on a textual representation in // Populates |description| based on a textual representation in
// |handler_string_ro|, returning true on success and false on failure (parse // |handler_string_ro|, returning true on success and false on failure (parse
@ -120,11 +120,11 @@ const char kHandlerBootstrapColon[] = "bootstrap:";
// SymbolicConstantsMach. // SymbolicConstantsMach.
bool ParseHandlerString(const char* handler_string_ro, bool ParseHandlerString(const char* handler_string_ro,
ExceptionHandlerDescription* description) { ExceptionHandlerDescription* description) {
const char kTargetEquals[] = "target="; static constexpr char kTargetEquals[] = "target=";
const char kMaskEquals[] = "mask="; static constexpr char kMaskEquals[] = "mask=";
const char kBehaviorEquals[] = "behavior="; static constexpr char kBehaviorEquals[] = "behavior=";
const char kFlavorEquals[] = "flavor="; static constexpr char kFlavorEquals[] = "flavor=";
const char kHandlerEquals[] = "handler="; static constexpr char kHandlerEquals[] = "handler=";
std::string handler_string(handler_string_ro); std::string handler_string(handler_string_ro);
char* handler_string_c = &handler_string[0]; char* handler_string_c = &handler_string[0];
@ -400,7 +400,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
bool numeric; bool numeric;
} options = {}; } options = {};
const option long_options[] = { static constexpr option long_options[] = {
{"set-handler", required_argument, nullptr, kOptionSetPort}, {"set-handler", required_argument, nullptr, kOptionSetPort},
{"show-bootstrap", required_argument, nullptr, kOptionShowBootstrap}, {"show-bootstrap", required_argument, nullptr, kOptionShowBootstrap},
{"pid", required_argument, nullptr, kOptionPid}, {"pid", required_argument, nullptr, kOptionPid},

View File

@ -81,7 +81,7 @@ int OnDemandServiceToolMain(int argc, char* argv[]) {
std::vector<std::string> mach_services; std::vector<std::string> mach_services;
} options = {}; } options = {};
const option long_options[] = { static constexpr option long_options[] = {
{"load", no_argument, nullptr, kOptionLoadJob}, {"load", no_argument, nullptr, kOptionLoadJob},
{"unload", no_argument, nullptr, kOptionUnloadJob}, {"unload", no_argument, nullptr, kOptionUnloadJob},
{"label", required_argument, nullptr, kOptionJobLabel}, {"label", required_argument, nullptr, kOptionJobLabel},

View File

@ -84,7 +84,7 @@ int RunWithCrashpadMain(int argc, char* argv[]) {
kOptionVersion = -3, kOptionVersion = -3,
}; };
const option long_options[] = { static constexpr option long_options[] = {
{"handler", required_argument, nullptr, kOptionHandler}, {"handler", required_argument, nullptr, kOptionHandler},
{"annotation", required_argument, nullptr, kOptionAnnotation}, {"annotation", required_argument, nullptr, kOptionAnnotation},
{"database", required_argument, nullptr, kOptionDatabase}, {"database", required_argument, nullptr, kOptionDatabase},

View File

@ -257,7 +257,7 @@ TEST(DelimitedFileReader, ReallyLongMultiLineFile) {
} }
TEST(DelimitedFileReader, EmbeddedNUL) { TEST(DelimitedFileReader, EmbeddedNUL) {
const char kString[] = "embedded\0NUL\n"; static constexpr char kString[] = "embedded\0NUL\n";
StringFile string_file; StringFile string_file;
string_file.SetString(std::string(kString, arraysize(kString) - 1)); string_file.SetString(std::string(kString, arraysize(kString) - 1));
DelimitedFileReader delimited_file_reader(&string_file); DelimitedFileReader delimited_file_reader(&string_file);
@ -275,7 +275,7 @@ TEST(DelimitedFileReader, EmbeddedNUL) {
} }
TEST(DelimitedFileReader, NULDelimiter) { TEST(DelimitedFileReader, NULDelimiter) {
const char kString[] = "aa\0b\0ccc\0"; static constexpr char kString[] = "aa\0b\0ccc\0";
StringFile string_file; StringFile string_file;
string_file.SetString(std::string(kString, arraysize(kString) - 1)); string_file.SetString(std::string(kString, arraysize(kString) - 1));
DelimitedFileReader delimited_file_reader(&string_file); DelimitedFileReader delimited_file_reader(&string_file);
@ -299,7 +299,8 @@ TEST(DelimitedFileReader, NULDelimiter) {
} }
TEST(DelimitedFileReader, EdgeCases) { TEST(DelimitedFileReader, EdgeCases) {
const size_t kSizes[] = {4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193}; static constexpr size_t kSizes[] =
{4094, 4095, 4096, 4097, 8190, 8191, 8192, 8193};
for (size_t index = 0; index < arraysize(kSizes); ++index) { for (size_t index = 0; index < arraysize(kSizes); ++index) {
size_t size = kSizes[index]; size_t size = kSizes[index];
SCOPED_TRACE( SCOPED_TRACE(

View File

@ -660,7 +660,7 @@ TEST(FileIO, FileSizeByHandle) {
ASSERT_NE(file_handle.get(), kInvalidFileHandle); ASSERT_NE(file_handle.get(), kInvalidFileHandle);
EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 0); EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 0);
const char data[] = "zippyzap"; static constexpr char data[] = "zippyzap";
ASSERT_TRUE(LoggingWriteFile(file_handle.get(), &data, sizeof(data))); ASSERT_TRUE(LoggingWriteFile(file_handle.get(), &data, sizeof(data)));
EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 9); EXPECT_EQ(LoggingFileSizeByHandle(file_handle.get()), 9);

View File

@ -135,8 +135,8 @@ bool ReadCStringSizeLimited(const ProcessMemory& memory,
FromPointerCast<LinuxVMAddress>(pointer), size, result); FromPointerCast<LinuxVMAddress>(pointer), size, result);
} }
const char kConstCharEmpty[] = ""; constexpr char kConstCharEmpty[] = "";
const char kConstCharShort[] = "A short const char[]"; constexpr char kConstCharShort[] = "A short const char[]";
class ReadCStringTest : public TargetProcessTest { class ReadCStringTest : public TargetProcessTest {
public: public:

View File

@ -43,7 +43,7 @@ bool ExpectationForValidity64(Validity validity) {
} }
TEST(CheckedMachAddressRange, IsValid) { TEST(CheckedMachAddressRange, IsValid) {
const struct TestData { static constexpr struct {
mach_vm_address_t base; mach_vm_address_t base;
mach_vm_size_t size; mach_vm_size_t size;
Validity validity; Validity validity;
@ -117,7 +117,7 @@ TEST(CheckedMachAddressRange, IsValid) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx",
index, index,
testcase.base, testcase.base,
@ -132,7 +132,7 @@ TEST(CheckedMachAddressRange, IsValid) {
} }
TEST(CheckedMachAddressRange, ContainsValue) { TEST(CheckedMachAddressRange, ContainsValue) {
const struct TestData { static constexpr struct {
mach_vm_address_t value; mach_vm_address_t value;
bool expectation; bool expectation;
} kTestData[] = { } kTestData[] = {
@ -167,7 +167,7 @@ TEST(CheckedMachAddressRange, ContainsValue) {
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, value 0x%llx", index, testcase.value)); base::StringPrintf("index %zu, value 0x%llx", index, testcase.value));
@ -185,7 +185,7 @@ TEST(CheckedMachAddressRange, ContainsValue) {
} }
TEST(CheckedMachAddressRange, ContainsRange) { TEST(CheckedMachAddressRange, ContainsRange) {
const struct TestData { static constexpr struct {
mach_vm_address_t base; mach_vm_address_t base;
mach_vm_size_t size; mach_vm_size_t size;
bool expectation; bool expectation;
@ -224,7 +224,7 @@ TEST(CheckedMachAddressRange, ContainsRange) {
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx",
index, index,
testcase.base, testcase.base,

View File

@ -153,7 +153,7 @@ TEST(Launchd, CFPropertyToLaunchData_Data) {
@autoreleasepool { @autoreleasepool {
base::mac::ScopedLaunchData launch_data; base::mac::ScopedLaunchData launch_data;
const uint8_t data_c[] = { static constexpr uint8_t data_c[] = {
1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2}; 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2};
NSData* data_ns = [NSData dataWithBytes:data_c length:sizeof(data_c)]; NSData* data_ns = [NSData dataWithBytes:data_c length:sizeof(data_c)];
launch_data.reset(CFPropertyToLaunchData(data_ns)); launch_data.reset(CFPropertyToLaunchData(data_ns));

View File

@ -114,7 +114,8 @@ TEST(ServiceManagement, SubmitRemoveJob) {
base::StringPrintf("sleep 10; echo %s", cookie.c_str()); base::StringPrintf("sleep 10; echo %s", cookie.c_str());
NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script); NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script);
const char kJobLabel[] = "org.chromium.crashpad.test.service_management"; static constexpr char kJobLabel[] =
"org.chromium.crashpad.test.service_management";
NSDictionary* job_dictionary_ns = @{ NSDictionary* job_dictionary_ns = @{
@LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management", @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management",
@LAUNCH_JOBKEY_RUNATLOAD : @YES, @LAUNCH_JOBKEY_RUNATLOAD : @YES,

View File

@ -55,7 +55,7 @@ class Xattr : public testing::Test {
base::FilePath path_; base::FilePath path_;
}; };
const char kKey[] = "com.google.crashpad.test"; constexpr char kKey[] = "org.chromium.crashpad.test";
TEST_F(Xattr, ReadNonExistentXattr) { TEST_F(Xattr, ReadNonExistentXattr) {
std::string value; std::string value;

View File

@ -106,7 +106,8 @@ bool ChildPortServer::MachMessageServerFunction(
} }
std::set<mach_msg_id_t> ChildPortServer::MachMessageServerRequestIDs() { std::set<mach_msg_id_t> ChildPortServer::MachMessageServerRequestIDs() {
const mach_msg_id_t request_ids[] = {kMachMessageIDChildPortCheckIn}; static constexpr mach_msg_id_t request_ids[] =
{kMachMessageIDChildPortCheckIn};
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[arraysize(request_ids)]); &request_ids[arraysize(request_ids)]);
} }

View File

@ -182,13 +182,13 @@ TEST(CompositeMachMessageServer, OneHandler) {
} }
TEST(CompositeMachMessageServer, ThreeHandlers) { TEST(CompositeMachMessageServer, ThreeHandlers) {
const mach_msg_id_t kRequestIDs0[] = {5}; static constexpr mach_msg_id_t kRequestIDs0[] = {5};
const kern_return_t kReturnCode0 = KERN_SUCCESS; const kern_return_t kReturnCode0 = KERN_SUCCESS;
const mach_msg_id_t kRequestIDs1[] = {4, 7}; static constexpr mach_msg_id_t kRequestIDs1[] = {4, 7};
const kern_return_t kReturnCode1 = KERN_PROTECTION_FAILURE; const kern_return_t kReturnCode1 = KERN_PROTECTION_FAILURE;
const mach_msg_id_t kRequestIDs2[] = {10, 0, 20}; static constexpr mach_msg_id_t kRequestIDs2[] = {10, 0, 20};
const mach_msg_size_t kRequestSize2 = 6144; const mach_msg_size_t kRequestSize2 = 6144;
const mach_msg_size_t kReplySize2 = 16384; const mach_msg_size_t kReplySize2 = 16384;
const kern_return_t kReturnCode2 = KERN_NOT_RECEIVER; const kern_return_t kReturnCode2 = KERN_NOT_RECEIVER;

View File

@ -264,7 +264,7 @@ mach_exception_subcode_t TestExcClientVariants::exception_subcode_ =
0xffffffff00000000; 0xffffffff00000000;
TEST(ExcClientVariants, UniversalExceptionRaise) { TEST(ExcClientVariants, UniversalExceptionRaise) {
const exception_behavior_t kBehaviors[] = { static constexpr exception_behavior_t kBehaviors[] = {
EXCEPTION_DEFAULT, EXCEPTION_DEFAULT,
EXCEPTION_STATE, EXCEPTION_STATE,
EXCEPTION_STATE_IDENTITY, EXCEPTION_STATE_IDENTITY,

View File

@ -877,7 +877,7 @@ TEST(ExcServerVariants, MockUnknownID) {
// UniversalMachExcServer should not dispatch the message to // UniversalMachExcServer should not dispatch the message to
// MachMessageServerFunction, but should generate a MIG_BAD_ID error reply. // MachMessageServerFunction, but should generate a MIG_BAD_ID error reply.
const mach_msg_id_t unknown_ids[] = { static constexpr mach_msg_id_t unknown_ids[] = {
// Reasonable things to check. // Reasonable things to check.
-101, -101,
-100, -100,
@ -1130,11 +1130,10 @@ TEST(ExcServerVariants, ThreadStates) {
// So far, all of the tests worked with MACHINE_THREAD_STATE. Now try all of // So far, all of the tests worked with MACHINE_THREAD_STATE. Now try all of
// the other thread state flavors that are expected to work. // the other thread state flavors that are expected to work.
struct TestData { static constexpr struct {
thread_state_flavor_t flavor; thread_state_flavor_t flavor;
mach_msg_type_number_t count; mach_msg_type_number_t count;
}; } test_data[] = {
const TestData test_data[] = {
#if defined(ARCH_CPU_X86_FAMILY) #if defined(ARCH_CPU_X86_FAMILY)
// For the x86 family, exception handlers can only properly receive the // For the x86 family, exception handlers can only properly receive the
// thread, float, and exception state flavors. Theres a bug in the kernel // thread, float, and exception state flavors. Theres a bug in the kernel
@ -1179,7 +1178,7 @@ TEST(ExcServerVariants, ThreadStates) {
}; };
for (size_t index = 0; index < arraysize(test_data); ++index) { for (size_t index = 0; index < arraysize(test_data); ++index) {
const TestData& test = test_data[index]; const auto& test = test_data[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, flavor %d", index, test.flavor)); base::StringPrintf("index %zu, flavor %d", index, test.flavor));
@ -1195,13 +1194,12 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) {
const kern_return_t prefer_not_set_thread_state = const kern_return_t prefer_not_set_thread_state =
MacOSXMinorVersion() < 11 ? MACH_RCV_PORT_DIED : KERN_SUCCESS; MacOSXMinorVersion() < 11 ? MACH_RCV_PORT_DIED : KERN_SUCCESS;
struct TestData { const struct {
exception_type_t exception; exception_type_t exception;
exception_behavior_t behavior; exception_behavior_t behavior;
bool set_thread_state; bool set_thread_state;
kern_return_t kr; kern_return_t kr;
}; } kTestData[] = {
const TestData kTestData[] = {
{EXC_CRASH, EXCEPTION_DEFAULT, false, KERN_SUCCESS}, {EXC_CRASH, EXCEPTION_DEFAULT, false, KERN_SUCCESS},
{EXC_CRASH, EXCEPTION_STATE, false, prefer_not_set_thread_state}, {EXC_CRASH, EXCEPTION_STATE, false, prefer_not_set_thread_state},
{EXC_CRASH, EXCEPTION_STATE_IDENTITY, false, prefer_not_set_thread_state}, {EXC_CRASH, EXCEPTION_STATE_IDENTITY, false, prefer_not_set_thread_state},
@ -1253,7 +1251,7 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("index %zu, behavior %d, set_thread_state %s", base::StringPrintf("index %zu, behavior %d, set_thread_state %s",
index, index,
@ -1268,7 +1266,7 @@ TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) {
} }
TEST(ExcServerVariants, ExcServerCopyState) { TEST(ExcServerVariants, ExcServerCopyState) {
const natural_t old_state[] = {1, 2, 3, 4, 5}; static constexpr natural_t old_state[] = {1, 2, 3, 4, 5};
natural_t new_state[10] = {}; natural_t new_state[10] = {};
const mach_msg_type_number_t old_state_count = arraysize(old_state); const mach_msg_type_number_t old_state_count = arraysize(old_state);

View File

@ -26,14 +26,13 @@ namespace test {
namespace { namespace {
TEST(ExceptionBehaviors, ExceptionBehaviors) { TEST(ExceptionBehaviors, ExceptionBehaviors) {
struct TestData { static constexpr struct {
exception_behavior_t behavior; exception_behavior_t behavior;
bool state; bool state;
bool identity; bool identity;
bool mach_exception_codes; bool mach_exception_codes;
exception_behavior_t basic_behavior; exception_behavior_t basic_behavior;
}; } kTestData[] = {
const TestData kTestData[] = {
{EXCEPTION_DEFAULT, false, true, false, EXCEPTION_DEFAULT}, {EXCEPTION_DEFAULT, false, true, false, EXCEPTION_DEFAULT},
{EXCEPTION_STATE, true, false, false, EXCEPTION_STATE}, {EXCEPTION_STATE, true, false, false, EXCEPTION_STATE},
{EXCEPTION_STATE_IDENTITY, true, true, false, EXCEPTION_STATE_IDENTITY}, {EXCEPTION_STATE_IDENTITY, true, true, false, EXCEPTION_STATE_IDENTITY},
@ -55,7 +54,7 @@ TEST(ExceptionBehaviors, ExceptionBehaviors) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, behavior %d", index, test_data.behavior)); "index %zu, behavior %d", index, test_data.behavior));

View File

@ -31,13 +31,12 @@ namespace test {
namespace { namespace {
TEST(ExceptionTypes, ExcCrashRecoverOriginalException) { TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
struct TestData { static constexpr struct {
mach_exception_code_t code_0; mach_exception_code_t code_0;
exception_type_t exception; exception_type_t exception;
mach_exception_code_t original_code_0; mach_exception_code_t original_code_0;
int signal; int signal;
}; } kTestData[] = {
const TestData kTestData[] = {
{0xb100001, EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, SIGSEGV}, {0xb100001, EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, SIGSEGV},
{0xb100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGSEGV}, {0xb100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGSEGV},
{0xa100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGBUS}, {0xa100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGBUS},
@ -69,7 +68,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %zu, code_0 0x%llx", index, test_data.code_0)); "index %zu, code_0 0x%llx", index, test_data.code_0));
@ -86,7 +85,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
// Now make sure that ExcCrashRecoverOriginalException() properly ignores // Now make sure that ExcCrashRecoverOriginalException() properly ignores
// optional arguments. // optional arguments.
static_assert(arraysize(kTestData) >= 1, "must have something to test"); static_assert(arraysize(kTestData) >= 1, "must have something to test");
const TestData& test_data = kTestData[0]; const auto& test_data = kTestData[0];
EXPECT_EQ( EXPECT_EQ(
ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr), ExcCrashRecoverOriginalException(test_data.code_0, nullptr, nullptr),
test_data.exception); test_data.exception);
@ -133,12 +132,11 @@ TEST(ExceptionTypes, ExcCrashCouldContainException) {
(static_cast<uint64_t>(flavor) & 0x7ull) << 58))) (static_cast<uint64_t>(flavor) & 0x7ull) << 58)))
TEST(ExceptionTypes, ExceptionCodeForMetrics) { TEST(ExceptionTypes, ExceptionCodeForMetrics) {
struct TestData { static constexpr struct {
exception_type_t exception; exception_type_t exception;
mach_exception_code_t code_0; mach_exception_code_t code_0;
int32_t metrics_code; int32_t metrics_code;
}; } kTestData[] = {
const TestData kTestData[] = {
#define ENCODE_EXC(type, code_0) \ #define ENCODE_EXC(type, code_0) \
{ (type), (code_0), ((type) << 16) | (code_0) } { (type), (code_0), ((type) << 16) | (code_0) }
ENCODE_EXC(EXC_BAD_ACCESS, KERN_INVALID_ADDRESS), ENCODE_EXC(EXC_BAD_ACCESS, KERN_INVALID_ADDRESS),
@ -241,7 +239,7 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& test_data = kTestData[index]; const auto& test_data = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %zu, exception 0x%x, code_0 0x%llx", SCOPED_TRACE(base::StringPrintf("index %zu, exception 0x%x, code_0 0x%llx",
index, index,
test_data.exception, test_data.exception,

View File

@ -279,7 +279,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
} }
std::set<mach_msg_id_t> MachMessageServerRequestIDs() override { std::set<mach_msg_id_t> MachMessageServerRequestIDs() override {
const mach_msg_id_t request_ids[] = {kRequestMessageID}; static constexpr mach_msg_id_t request_ids[] = {kRequestMessageID};
return std::set<mach_msg_id_t>(&request_ids[0], return std::set<mach_msg_id_t>(&request_ids[0],
&request_ids[arraysize(request_ids)]); &request_ids[arraysize(request_ids)]);
} }

View File

@ -259,7 +259,7 @@ bool NotifyServer::MachMessageServerFunction(
} }
std::set<mach_msg_id_t> NotifyServer::MachMessageServerRequestIDs() { std::set<mach_msg_id_t> NotifyServer::MachMessageServerRequestIDs() {
const mach_msg_id_t request_ids[] = { static constexpr mach_msg_id_t request_ids[] = {
MACH_NOTIFY_PORT_DELETED, MACH_NOTIFY_PORT_DELETED,
MACH_NOTIFY_PORT_DESTROYED, MACH_NOTIFY_PORT_DESTROYED,
MACH_NOTIFY_NO_SENDERS, MACH_NOTIFY_NO_SENDERS,

View File

@ -26,7 +26,7 @@
namespace { namespace {
const char* kExceptionNames[] = { constexpr const char* kExceptionNames[] = {
nullptr, nullptr,
// sed -Ene 's/^#define[[:space:]]EXC_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p' // sed -Ene 's/^#define[[:space:]]EXC_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p'
@ -48,10 +48,10 @@ const char* kExceptionNames[] = {
static_assert(arraysize(kExceptionNames) == EXC_TYPES_COUNT, static_assert(arraysize(kExceptionNames) == EXC_TYPES_COUNT,
"kExceptionNames length"); "kExceptionNames length");
const char kExcPrefix[] = "EXC_"; constexpr char kExcPrefix[] = "EXC_";
const char kExcMaskPrefix[] = "EXC_MASK_"; constexpr char kExcMaskPrefix[] = "EXC_MASK_";
const char* kBehaviorNames[] = { constexpr const char* kBehaviorNames[] = {
nullptr, nullptr,
// sed -Ene 's/^# define[[:space:]]EXCEPTION_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p' // sed -Ene 's/^# define[[:space:]]EXCEPTION_([[:graph:]]+)[[:space:]]+[[:digit:]]{1,2}([[:space:]]|$).*/ "\1",/p'
@ -61,11 +61,11 @@ const char* kBehaviorNames[] = {
"STATE_IDENTITY", "STATE_IDENTITY",
}; };
const char kBehaviorPrefix[] = "EXCEPTION_"; constexpr char kBehaviorPrefix[] = "EXCEPTION_";
const char kMachExceptionCodesFull[] = "MACH_EXCEPTION_CODES"; constexpr char kMachExceptionCodesFull[] = "MACH_EXCEPTION_CODES";
const char kMachExceptionCodesShort[] = "MACH"; constexpr char kMachExceptionCodesShort[] = "MACH";
const char* kFlavorNames[] = { constexpr const char* kFlavorNames[] = {
"THREAD_STATE_FLAVOR_LIST", "THREAD_STATE_FLAVOR_LIST",
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
@ -128,7 +128,7 @@ const char* kFlavorNames[] = {
// Certain generic flavors have high constants not contiguous with the flavors // Certain generic flavors have high constants not contiguous with the flavors
// above. List them separately alongside their constants. // above. List them separately alongside their constants.
const struct { constexpr struct {
thread_state_flavor_t flavor; thread_state_flavor_t flavor;
const char* name; const char* name;
} kGenericFlavorNames[] = { } kGenericFlavorNames[] = {
@ -139,7 +139,7 @@ const struct {
// Returns the short name for a flavor name, given its full flavor name. // Returns the short name for a flavor name, given its full flavor name.
std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) { std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) {
// For generic flavors like THREAD_STATE_NONE and THREAD_STATE_FLAVOR_LIST_*. // For generic flavors like THREAD_STATE_NONE and THREAD_STATE_FLAVOR_LIST_*.
const char kThreadState[] = "THREAD_STATE_"; static constexpr char kThreadState[] = "THREAD_STATE_";
size_t prefix_len = strlen(kThreadState); size_t prefix_len = strlen(kThreadState);
const char* flavor_data = flavor.data(); const char* flavor_data = flavor.data();
size_t flavor_len = flavor.size(); size_t flavor_len = flavor.size();
@ -150,11 +150,11 @@ std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) {
// For architecture-specific flavors. // For architecture-specific flavors.
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
const char kArchPrefix[] = "x86_"; static constexpr char kArchPrefix[] = "x86_";
#elif defined(__ppc__) || defined(__ppc64__) #elif defined(__ppc__) || defined(__ppc64__)
const char kArchPrefix[] = "PPC_"; static constexpr char kArchPrefix[] = "PPC_";
#elif defined(__arm__) || defined(__arm64__) #elif defined(__arm__) || defined(__arm64__)
const char kArchPrefix[] = "ARM_" static constexpr char kArchPrefix[] = "ARM_"
#endif #endif
prefix_len = strlen(kArchPrefix); prefix_len = strlen(kArchPrefix);
if (flavor_len >= prefix_len && if (flavor_len >= prefix_len &&
@ -162,7 +162,7 @@ std::string ThreadStateFlavorFullToShort(const base::StringPiece& flavor) {
// Shorten the suffix by removing _STATE. If the suffix contains a // Shorten the suffix by removing _STATE. If the suffix contains a
// significant designation like 32 or 64, keep it, so that a full name like // significant designation like 32 or 64, keep it, so that a full name like
// x86_THREAD_STATE64 becomes a short name like THREAD64. // x86_THREAD_STATE64 becomes a short name like THREAD64.
const struct { static constexpr struct {
const char* orig; const char* orig;
const char* repl; const char* repl;
} kStateSuffixes[] = { } kStateSuffixes[] = {
@ -343,7 +343,7 @@ bool StringToExceptionMask(const base::StringPiece& string,
// EXC_MASK_ALL is a special case: it is not in kExceptionNames as it exists // EXC_MASK_ALL is a special case: it is not in kExceptionNames as it exists
// only as a mask value. // only as a mask value.
const char kExcMaskAll[] = "ALL"; static constexpr char kExcMaskAll[] = "ALL";
if ((can_match_full && short_string.compare(kExcMaskAll) == 0) || if ((can_match_full && short_string.compare(kExcMaskAll) == 0) ||
((options & kAllowShortName) && string.compare(kExcMaskAll) == 0)) { ((options & kAllowShortName) && string.compare(kExcMaskAll) == 0)) {
*exception_mask = ExcMaskAll(); *exception_mask = ExcMaskAll();

View File

@ -32,7 +32,7 @@ namespace test {
namespace { namespace {
// Options to use for normal tests, those that dont require kAllowOr. // Options to use for normal tests, those that dont require kAllowOr.
const StringToSymbolicConstantOptions kNormalOptions[] = { constexpr StringToSymbolicConstantOptions kNormalOptions[] = {
0, 0,
kAllowFullName, kAllowFullName,
kAllowShortName, kAllowShortName,
@ -118,7 +118,7 @@ void TestStringToSomething(const base::StringPiece& string,
} }
} }
const struct { constexpr struct {
exception_type_t exception; exception_type_t exception;
const char* full_name; const char* full_name;
const char* short_name; const char* short_name;
@ -217,7 +217,7 @@ TEST(SymbolicConstantsMach, StringToException) {
} }
} }
const char* const kNegativeTestData[] = { static constexpr const char* kNegativeTestData[] = {
"EXC_CRASH ", "EXC_CRASH ",
" EXC_BAD_INSTRUCTION", " EXC_BAD_INSTRUCTION",
"CRASH ", "CRASH ",
@ -235,7 +235,7 @@ TEST(SymbolicConstantsMach, StringToException) {
TestStringToException(kNegativeTestData[index], options, false, 0); TestStringToException(kNegativeTestData[index], options, false, 0);
} }
const struct { static constexpr struct {
const char* string; const char* string;
size_t length; size_t length;
} kNULTestData[] = { } kNULTestData[] = {
@ -276,7 +276,7 @@ TEST(SymbolicConstantsMach, StringToException) {
} }
} }
const struct { constexpr struct {
exception_mask_t exception_mask; exception_mask_t exception_mask;
const char* full_name; const char* full_name;
const char* short_name; const char* short_name;
@ -370,7 +370,7 @@ void TestStringToExceptionMask(const base::StringPiece& string,
TEST(SymbolicConstantsMach, StringToExceptionMask) { TEST(SymbolicConstantsMach, StringToExceptionMask) {
// Dont use kNormalOptions, because kAllowOr needs to be tested. // Dont use kNormalOptions, because kAllowOr needs to be tested.
const StringToSymbolicConstantOptions kOptions[] = { static constexpr StringToSymbolicConstantOptions kOptions[] = {
0, 0,
kAllowFullName, kAllowFullName,
kAllowShortName, kAllowShortName,
@ -430,7 +430,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
} }
} }
const char* const kNegativeTestData[] = { static constexpr const char* kNegativeTestData[] = {
"EXC_MASK_CRASH ", "EXC_MASK_CRASH ",
" EXC_MASK_BAD_INSTRUCTION", " EXC_MASK_BAD_INSTRUCTION",
"EXC_MASK_EXC_MASK_BAD_ACCESS", "EXC_MASK_EXC_MASK_BAD_ACCESS",
@ -450,7 +450,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
TestStringToExceptionMask(kNegativeTestData[index], options, false, 0); TestStringToExceptionMask(kNegativeTestData[index], options, false, 0);
} }
const struct { static constexpr struct {
const char* string; const char* string;
size_t length; size_t length;
} kNULTestData[] = { } kNULTestData[] = {
@ -479,7 +479,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
} }
} }
const struct { static const struct {
const char* string; const char* string;
StringToSymbolicConstantOptions options; StringToSymbolicConstantOptions options;
exception_mask_t mask; exception_mask_t mask;
@ -531,7 +531,7 @@ TEST(SymbolicConstantsMach, StringToExceptionMask) {
} }
} }
const struct { constexpr struct {
exception_behavior_t behavior; exception_behavior_t behavior;
const char* full_name; const char* full_name;
const char* short_name; const char* short_name;
@ -643,7 +643,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
} }
} }
const char* const kNegativeTestData[] = { static constexpr const char* kNegativeTestData[] = {
"EXCEPTION_DEFAULT ", "EXCEPTION_DEFAULT ",
" EXCEPTION_STATE", " EXCEPTION_STATE",
"EXCEPTION_EXCEPTION_STATE_IDENTITY", "EXCEPTION_EXCEPTION_STATE_IDENTITY",
@ -666,7 +666,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
kNegativeTestData[index], options, false, 0); kNegativeTestData[index], options, false, 0);
} }
const struct { static constexpr struct {
const char* string; const char* string;
size_t length; size_t length;
} kNULTestData[] = { } kNULTestData[] = {
@ -694,7 +694,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
} }
} }
const struct { static constexpr struct {
const char* string; const char* string;
StringToSymbolicConstantOptions options; StringToSymbolicConstantOptions options;
exception_behavior_t behavior; exception_behavior_t behavior;
@ -763,7 +763,7 @@ TEST(SymbolicConstantsMach, StringToExceptionBehavior) {
} }
} }
const struct { constexpr struct {
thread_state_flavor_t flavor; thread_state_flavor_t flavor;
const char* full_name; const char* full_name;
const char* short_name; const char* short_name;
@ -917,7 +917,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) {
} }
} }
const char* const kNegativeTestData[] = { static constexpr const char* kNegativeTestData[] = {
"THREAD_STATE_NONE ", "THREAD_STATE_NONE ",
" THREAD_STATE_NONE", " THREAD_STATE_NONE",
"NONE ", "NONE ",
@ -965,7 +965,7 @@ TEST(SymbolicConstantsMach, StringToThreadStateFlavor) {
kNegativeTestData[index], options, false, 0); kNegativeTestData[index], options, false, 0);
} }
const struct { static constexpr struct {
const char* string; const char* string;
size_t length; size_t length;
} kNULTestData[] = { } kNULTestData[] = {

View File

@ -194,6 +194,27 @@ TEST(TaskMemory, ReadCStringSelf) {
EXPECT_FALSE(result.empty()); EXPECT_FALSE(result.empty());
EXPECT_EQ(result, kStaticConstCharShort); EXPECT_EQ(result, kStaticConstCharShort);
constexpr char kConstexprCharEmpty[] = "";
ASSERT_TRUE(ReadCStringSelf(&memory, kConstexprCharEmpty, &result));
EXPECT_TRUE(result.empty());
EXPECT_EQ(result, kConstexprCharEmpty);
constexpr char kConstexprCharShort[] = "A short constexpr char[]";
ASSERT_TRUE(ReadCStringSelf(&memory, kConstexprCharShort, &result));
EXPECT_FALSE(result.empty());
EXPECT_EQ(result, kConstexprCharShort);
static constexpr char kStaticConstexprCharEmpty[] = "";
ASSERT_TRUE(ReadCStringSelf(&memory, kStaticConstexprCharEmpty, &result));
EXPECT_TRUE(result.empty());
EXPECT_EQ(result, kStaticConstexprCharEmpty);
static constexpr char kStaticConstexprCharShort[] =
"A short static constexpr char[]";
ASSERT_TRUE(ReadCStringSelf(&memory, kStaticConstexprCharShort, &result));
EXPECT_FALSE(result.empty());
EXPECT_EQ(result, kStaticConstexprCharShort);
std::string string_short("A short std::string in a function"); std::string string_short("A short std::string in a function");
ASSERT_TRUE(ReadCStringSelf(&memory, &string_short[0], &result)); ASSERT_TRUE(ReadCStringSelf(&memory, &string_short[0], &result));
EXPECT_FALSE(result.empty()); EXPECT_FALSE(result.empty());
@ -280,7 +301,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_ConstCharEmpty) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::string result; std::string result;
const char kConstCharEmpty[] = ""; static constexpr char kConstCharEmpty[] = "";
ASSERT_TRUE(ReadCStringSizeLimitedSelf( ASSERT_TRUE(ReadCStringSizeLimitedSelf(
&memory, kConstCharEmpty, arraysize(kConstCharEmpty), &result)); &memory, kConstCharEmpty, arraysize(kConstCharEmpty), &result));
EXPECT_TRUE(result.empty()); EXPECT_TRUE(result.empty());
@ -302,7 +323,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_ConstCharShort) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::string result; std::string result;
const char kConstCharShort[] = "A short const char[]"; static constexpr char kConstCharShort[] = "A short const char[]";
ASSERT_TRUE(ReadCStringSizeLimitedSelf( ASSERT_TRUE(ReadCStringSizeLimitedSelf(
&memory, kConstCharShort, arraysize(kConstCharShort), &result)); &memory, kConstCharShort, arraysize(kConstCharShort), &result));
EXPECT_FALSE(result.empty()); EXPECT_FALSE(result.empty());
@ -322,7 +343,7 @@ TEST(TaskMemory, ReadCStringSizeLimited_StaticConstCharEmpty) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::string result; std::string result;
static const char kStaticConstCharEmpty[] = ""; static constexpr char kStaticConstCharEmpty[] = "";
ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory, ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory,
kStaticConstCharEmpty, kStaticConstCharEmpty,
arraysize(kStaticConstCharEmpty), arraysize(kStaticConstCharEmpty),
@ -349,7 +370,8 @@ TEST(TaskMemory, ReadCStringSizeLimited_StaticConstCharShort) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::string result; std::string result;
static const char kStaticConstCharShort[] = "A short static const char[]"; static constexpr char kStaticConstCharShort[] =
"A short static constexpr char[]";
ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory, ASSERT_TRUE(ReadCStringSizeLimitedSelf(&memory,
kStaticConstCharShort, kStaticConstCharShort,
arraysize(kStaticConstCharShort), arraysize(kStaticConstCharShort),
@ -461,7 +483,7 @@ TEST(TaskMemory, MappedMemoryDeallocates) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::unique_ptr<TaskMemory::MappedMemory> mapped; std::unique_ptr<TaskMemory::MappedMemory> mapped;
static const char kTestBuffer[] = "hello!"; static constexpr char kTestBuffer[] = "hello!";
mach_vm_address_t test_address = mach_vm_address_t test_address =
FromPointerCast<mach_vm_address_t>(&kTestBuffer); FromPointerCast<mach_vm_address_t>(&kTestBuffer);
ASSERT_TRUE((mapped = memory.ReadMapped(test_address, sizeof(kTestBuffer)))); ASSERT_TRUE((mapped = memory.ReadMapped(test_address, sizeof(kTestBuffer))));
@ -498,7 +520,7 @@ TEST(TaskMemory, MappedMemoryReadCString) {
TaskMemory memory(mach_task_self()); TaskMemory memory(mach_task_self());
std::unique_ptr<TaskMemory::MappedMemory> mapped; std::unique_ptr<TaskMemory::MappedMemory> mapped;
static const char kTestBuffer[] = "0\0" "2\0" "45\0" "789"; static constexpr char kTestBuffer[] = "0\0" "2\0" "45\0" "789";
const mach_vm_address_t kTestAddress = const mach_vm_address_t kTestAddress =
FromPointerCast<mach_vm_address_t>(&kTestBuffer); FromPointerCast<mach_vm_address_t>(&kTestBuffer);
ASSERT_TRUE((mapped = memory.ReadMapped(kTestAddress, 10))); ASSERT_TRUE((mapped = memory.ReadMapped(kTestAddress, 10)));

View File

@ -71,7 +71,7 @@ void TestSleepNanoseconds(uint64_t nanoseconds) {
} }
TEST(Clock, SleepNanoseconds) { TEST(Clock, SleepNanoseconds) {
const uint64_t kTestData[] = { static constexpr uint64_t kTestData[] = {
0, 0,
1, 1,
static_cast<uint64_t>(1E3), // 1 microsecond static_cast<uint64_t>(1E3), // 1 microsecond

View File

@ -34,8 +34,8 @@ namespace crashpad {
// implicit_cast would have been part of the C++ standard library, // implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make // but the proposal was submitted too late. It will probably make
// its way into the language in the future. // its way into the language in the future.
template<typename To, typename From> template <typename To, typename From>
inline To implicit_cast(From const &f) { constexpr To implicit_cast(From const& f) {
return f; return f;
} }

View File

@ -43,7 +43,7 @@ void ScopedForbidReturnHelper(ForbidReturnType type) {
} }
} }
const char kForbiddenMessage[] = "attempt to exit scope forbidden"; constexpr char kForbiddenMessage[] = "attempt to exit scope forbidden";
TEST(ScopedForbidReturnDeathTest, Default) { TEST(ScopedForbidReturnDeathTest, Default) {
// kForbiddenMessage may appear to be unused if ASSERT_DEATH_CHECK() throws it // kForbiddenMessage may appear to be unused if ASSERT_DEATH_CHECK() throws it

View File

@ -66,7 +66,7 @@ bool UUID::InitializeFromString(const base::StringPiece& string) {
return false; return false;
UUID temp; UUID temp;
const char kScanFormat[] = static constexpr char kScanFormat[] =
"%08" SCNx32 "-%04" SCNx16 "-%04" SCNx16 "%08" SCNx32 "-%04" SCNx16 "-%04" SCNx16
"-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8
"-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8; "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8;

View File

@ -45,22 +45,22 @@ TEST(UUID, UUID) {
EXPECT_EQ(uuid_zero.data_5[5], 0u); EXPECT_EQ(uuid_zero.data_5[5], 0u);
EXPECT_EQ(uuid_zero.ToString(), "00000000-0000-0000-0000-000000000000"); EXPECT_EQ(uuid_zero.ToString(), "00000000-0000-0000-0000-000000000000");
const uint8_t kBytes[16] = {0x00, static constexpr uint8_t kBytes[16] = {0x00,
0x01, 0x01,
0x02, 0x02,
0x03, 0x03,
0x04, 0x04,
0x05, 0x05,
0x06, 0x06,
0x07, 0x07,
0x08, 0x08,
0x09, 0x09,
0x0a, 0x0a,
0x0b, 0x0b,
0x0c, 0x0c,
0x0d, 0x0d,
0x0e, 0x0e,
0x0f}; 0x0f};
UUID uuid; UUID uuid;
uuid.InitializeFromBytes(kBytes); uuid.InitializeFromBytes(kBytes);
EXPECT_EQ(uuid.data_1, 0x00010203u); EXPECT_EQ(uuid.data_1, 0x00010203u);
@ -110,22 +110,22 @@ TEST(UUID, UUID) {
// have been valid. // have been valid.
EXPECT_EQ(uuid_2, uuid); EXPECT_EQ(uuid_2, uuid);
const uint8_t kMoreBytes[16] = {0xff, static constexpr uint8_t kMoreBytes[16] = {0xff,
0xee, 0xee,
0xdd, 0xdd,
0xcc, 0xcc,
0xbb, 0xbb,
0xaa, 0xaa,
0x99, 0x99,
0x88, 0x88,
0x77, 0x77,
0x66, 0x66,
0x55, 0x55,
0x44, 0x44,
0x33, 0x33,
0x22, 0x22,
0x11, 0x11,
0x00}; 0x00};
uuid.InitializeFromBytes(kMoreBytes); uuid.InitializeFromBytes(kMoreBytes);
EXPECT_EQ(uuid.data_1, 0xffeeddccu); EXPECT_EQ(uuid.data_1, 0xffeeddccu);
EXPECT_EQ(uuid.data_2, 0xbbaau); EXPECT_EQ(uuid.data_2, 0xbbaau);
@ -164,7 +164,7 @@ TEST(UUID, UUID) {
} }
TEST(UUID, FromString) { TEST(UUID, FromString) {
const struct TestCase { static constexpr struct TestCase {
const char* uuid_string; const char* uuid_string;
bool success; bool success;
} kCases[] = { } kCases[] = {

View File

@ -29,9 +29,9 @@ namespace crashpad {
namespace { namespace {
const char kCRLF[] = "\r\n"; constexpr char kCRLF[] = "\r\n";
const char kBoundaryCRLF[] = "\r\n\r\n"; constexpr char kBoundaryCRLF[] = "\r\n\r\n";
// Generates a random string suitable for use as a multipart boundary. // Generates a random string suitable for use as a multipart boundary.
std::string GenerateBoundaryString() { std::string GenerateBoundaryString() {
@ -47,7 +47,7 @@ std::string GenerateBoundaryString() {
// randomness (62^32 > 2^190). // randomness (62^32 > 2^190).
std::string boundary_string = "---MultipartBoundary-"; std::string boundary_string = "---MultipartBoundary-";
for (int index = 0; index < 32; ++index) { for (int index = 0; index < 32; ++index) {
const char kCharacters[] = static constexpr char kCharacters[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int random_value = int random_value =
base::RandInt(0, static_cast<int>(strlen(kCharacters)) - 1); base::RandInt(0, static_cast<int>(strlen(kCharacters)) - 1);

View File

@ -55,16 +55,16 @@ std::vector<std::string> SplitCRLF(const std::string& string) {
TEST(HTTPMultipartBuilder, ThreeStringFields) { TEST(HTTPMultipartBuilder, ThreeStringFields) {
HTTPMultipartBuilder builder; HTTPMultipartBuilder builder;
const char kKey1[] = "key1"; static constexpr char kKey1[] = "key1";
const char kValue1[] = "test"; static constexpr char kValue1[] = "test";
builder.SetFormData(kKey1, kValue1); builder.SetFormData(kKey1, kValue1);
const char kKey2[] = "key2"; static constexpr char kKey2[] = "key2";
const char kValue2[] = "This is another test."; static constexpr char kValue2[] = "This is another test.";
builder.SetFormData(kKey2, kValue2); builder.SetFormData(kKey2, kValue2);
const char kKey3[] = "key-three"; static constexpr char kKey3[] = "key-three";
const char kValue3[] = "More tests"; static constexpr char kValue3[] = "More tests";
builder.SetFormData(kKey3, kValue3); builder.SetFormData(kKey3, kValue3);
std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream());
@ -115,7 +115,7 @@ TEST(HTTPMultipartBuilder, ThreeFileAttachments) {
ascii_http_body_path, ascii_http_body_path,
"text/plain"); "text/plain");
const char kFileContents[] = "This is a test.\n"; static constexpr char kFileContents[] = "This is a test.\n";
std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream());
ASSERT_TRUE(body.get()); ASSERT_TRUE(body.get());
@ -158,7 +158,7 @@ TEST(HTTPMultipartBuilder, ThreeFileAttachments) {
TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) { TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) {
HTTPMultipartBuilder builder; HTTPMultipartBuilder builder;
const char kKey[] = "a 100% \"silly\"\r\ntest"; static constexpr char kKey[] = "a 100% \"silly\"\r\ntest";
builder.SetFormData(kKey, "some dummy value"); builder.SetFormData(kKey, "some dummy value");
builder.SetFormData(kKey, "overwrite"); builder.SetFormData(kKey, "overwrite");
std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream());
@ -183,7 +183,7 @@ TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) {
TEST(HTTPMultipartBuilder, OverwriteFileAttachment) { TEST(HTTPMultipartBuilder, OverwriteFileAttachment) {
HTTPMultipartBuilder builder; HTTPMultipartBuilder builder;
const char kValue[] = "1 2 3 test"; static constexpr char kValue[] = "1 2 3 test";
builder.SetFormData("a key", kValue); builder.SetFormData("a key", kValue);
base::FilePath testdata_path = base::FilePath testdata_path =
TestPaths::TestDataRoot().Append(FILE_PATH_LITERAL("util/net/testdata")); TestPaths::TestDataRoot().Append(FILE_PATH_LITERAL("util/net/testdata"));
@ -240,7 +240,7 @@ TEST(HTTPMultipartBuilder, OverwriteFileAttachment) {
TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) { TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) {
HTTPMultipartBuilder builder; HTTPMultipartBuilder builder;
const char kValue1[] = "11111"; static constexpr char kValue1[] = "11111";
builder.SetFormData("one", kValue1); builder.SetFormData("one", kValue1);
base::FilePath ascii_http_body_path = TestPaths::TestDataRoot().Append( base::FilePath ascii_http_body_path = TestPaths::TestDataRoot().Append(
FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt")); FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt"));
@ -248,7 +248,7 @@ TEST(HTTPMultipartBuilder, SharedFormDataAndAttachmentKeyNamespace) {
"minidump.dmp", "minidump.dmp",
ascii_http_body_path, ascii_http_body_path,
""); "");
const char kValue2[] = "this is not a file"; static constexpr char kValue2[] = "this is not a file";
builder.SetFormData("minidump", kValue2); builder.SetFormData("minidump", kValue2);
std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream());

View File

@ -57,31 +57,31 @@ std::string UserAgent() {
// linux-4.9.17/arch/x86/kernel/cpu/bugs.c check_bugs() sets the first digit // linux-4.9.17/arch/x86/kernel/cpu/bugs.c check_bugs() sets the first digit
// to 4, 5, or 6, but no higher. // to 4, 5, or 6, but no higher.
#if defined(__i686__) #if defined(__i686__)
const char arch[] = "i686"; static constexpr char arch[] = "i686";
#elif defined(__i586__) #elif defined(__i586__)
const char arch[] = "i586"; static constexpr char arch[] = "i586";
#elif defined(__i486__) #elif defined(__i486__)
const char arch[] = "i486"; static constexpr char arch[] = "i486";
#else #else
const char arch[] = "i386"; static constexpr char arch[] = "i386";
#endif #endif
#elif defined(ARCH_CPU_X86_64) #elif defined(ARCH_CPU_X86_64)
const char arch[] = "x86_64"; static constexpr char arch[] = "x86_64";
#elif defined(ARCH_CPU_ARMEL) #elif defined(ARCH_CPU_ARMEL)
// linux-4.9.17/arch/arm/kernel/setup.c setup_processor() bases the string // linux-4.9.17/arch/arm/kernel/setup.c setup_processor() bases the string
// on the ARM processor name and a character identifying little- or // on the ARM processor name and a character identifying little- or
// big-endian. The processor name comes from a definition in // big-endian. The processor name comes from a definition in
// arch/arm/mm/proc-*.S. // arch/arm/mm/proc-*.S.
#if defined(__ARM_ARCH_4T__) #if defined(__ARM_ARCH_4T__)
const char arch[] = "armv4t" static constexpr char arch[] = "armv4t"
#elif defined(__ARM_ARCH_5TEJ__) #elif defined(__ARM_ARCH_5TEJ__)
const char arch[] = "armv5tej" static constexpr char arch[] = "armv5tej"
#elif defined(__ARM_ARCH_5TE__) #elif defined(__ARM_ARCH_5TE__)
const char arch[] = "armv5te" static constexpr char arch[] = "armv5te"
#elif defined(__ARM_ARCH_5T__) #elif defined(__ARM_ARCH_5T__)
const char arch[] = "armv5t" static constexpr char arch[] = "armv5t"
#elif defined(__ARM_ARCH_7M__) #elif defined(__ARM_ARCH_7M__)
const char arch[] = "armv7m" static constexpr char arch[] = "armv7m"
#else #else
// Most ARM architectures fall into here, including all profile variants of // Most ARM architectures fall into here, including all profile variants of
// armv6, armv7, armv8, with one exception, armv7m, handled above. // armv6, armv7, armv8, with one exception, armv7m, handled above.
@ -89,7 +89,7 @@ std::string UserAgent() {
// or 8. // or 8.
#define xstr(s) str(s) #define xstr(s) str(s)
#define str(s) #s #define str(s) #s
const char arch[] = "armv" xstr(__ARM_ARCH) static constexpr char arch[] = "armv" xstr(__ARM_ARCH)
#undef str #undef str
#undef xstr #undef xstr
#endif #endif
@ -102,14 +102,14 @@ std::string UserAgent() {
// ARM64 uses aarch64 or aarch64_be as directed by ELF_PLATFORM. See // ARM64 uses aarch64 or aarch64_be as directed by ELF_PLATFORM. See
// linux-4.9.17/arch/arm64/kernel/setup.c setup_arch(). // linux-4.9.17/arch/arm64/kernel/setup.c setup_arch().
#if defined(ARCH_CPU_LITTLE_ENDIAN) #if defined(ARCH_CPU_LITTLE_ENDIAN)
const char arch[] = "aarch64"; static constexpr char arch[] = "aarch64";
#elif defined(ARCH_CPU_BIG_ENDIAN) #elif defined(ARCH_CPU_BIG_ENDIAN)
const char arch[] = "aarch64_be"; static constexpr char arch[] = "aarch64_be";
#endif #endif
#elif defined(ARCH_CPU_MIPSEL) #elif defined(ARCH_CPU_MIPSEL)
const char arch[] = "mips"; static constexpr char arch[] = "mips";
#elif defined(ARCH_CPU_MIPS64EL) #elif defined(ARCH_CPU_MIPS64EL)
const char arch[] = "mips64"; static constexpr char arch[] = "mips64";
#else #else
#error Port #error Port
#endif #endif

View File

@ -136,7 +136,7 @@ class HTTPTransportTestFixture : public MultiprocessExec {
RequestValidator request_validator_; RequestValidator request_validator_;
}; };
const char kMultipartFormData[] = "multipart/form-data"; constexpr char kMultipartFormData[] = "multipart/form-data";
void GetHeaderField(const std::string& request, void GetHeaderField(const std::string& request,
const std::string& header, const std::string& header,
@ -179,7 +179,7 @@ void GetMultipartBoundary(const std::string& request,
} }
} }
const char kBoundaryEq[] = "boundary="; constexpr char kBoundaryEq[] = "boundary=";
void ValidFormData(HTTPTransportTestFixture* fixture, void ValidFormData(HTTPTransportTestFixture* fixture,
const std::string& request) { const std::string& request) {
@ -242,7 +242,7 @@ TEST(HTTPTransport, ValidFormData_Gzip) {
test.Run(); test.Run();
} }
const char kTextPlain[] = "text/plain"; constexpr char kTextPlain[] = "text/plain";
void ErrorResponse(HTTPTransportTestFixture* fixture, void ErrorResponse(HTTPTransportTestFixture* fixture,
const std::string& request) { const std::string& request) {
@ -260,7 +260,7 @@ TEST(HTTPTransport, ErrorResponse) {
test.Run(); test.Run();
} }
const char kTextBody[] = "hello world"; constexpr char kTextBody[] = "hello world";
void UnchunkedPlainText(HTTPTransportTestFixture* fixture, void UnchunkedPlainText(HTTPTransportTestFixture* fixture,
const std::string& request) { const std::string& request) {

View File

@ -242,7 +242,8 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
DWORD content_length_dword; DWORD content_length_dword;
if (chunked) { if (chunked) {
const wchar_t kTransferEncodingHeader[] = L"Transfer-Encoding: chunked\r\n"; static constexpr wchar_t kTransferEncodingHeader[] =
L"Transfer-Encoding: chunked\r\n";
if (!WinHttpAddRequestHeaders( if (!WinHttpAddRequestHeaders(
request.get(), request.get(),
kTransferEncodingHeader, kTransferEncodingHeader,

View File

@ -46,7 +46,7 @@ bool ExpectationForValidity64(Validity validity) {
} }
TEST(CheckedAddressRange, IsValid) { TEST(CheckedAddressRange, IsValid) {
const struct TestData { static constexpr struct {
uint64_t base; uint64_t base;
uint64_t size; uint64_t size;
Validity validity; Validity validity;
@ -120,7 +120,7 @@ TEST(CheckedAddressRange, IsValid) {
}; };
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%" PRIx64 ", size 0x%" PRIx64, ", base 0x%" PRIx64 ", size 0x%" PRIx64,
index, index,
@ -136,7 +136,7 @@ TEST(CheckedAddressRange, IsValid) {
} }
TEST(CheckedAddressRange, ContainsValue) { TEST(CheckedAddressRange, ContainsValue) {
const struct TestData { static constexpr struct {
uint64_t value; uint64_t value;
bool expectation; bool expectation;
} kTestData[] = { } kTestData[] = {
@ -171,7 +171,7 @@ TEST(CheckedAddressRange, ContainsValue) {
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", value 0x%" PRIx64, index, testcase.value)); "index %" PRIuS ", value 0x%" PRIx64, index, testcase.value));
@ -189,7 +189,7 @@ TEST(CheckedAddressRange, ContainsValue) {
} }
TEST(CheckedAddressRange, ContainsRange) { TEST(CheckedAddressRange, ContainsRange) {
const struct TestData { static constexpr struct {
uint64_t base; uint64_t base;
uint64_t size; uint64_t size;
bool expectation; bool expectation;
@ -228,7 +228,7 @@ TEST(CheckedAddressRange, ContainsRange) {
ASSERT_TRUE(parent_range_32.IsValid()); ASSERT_TRUE(parent_range_32.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS SCOPED_TRACE(base::StringPrintf("index %" PRIuS
", base 0x%" PRIx64 ", size 0x%" PRIx64, ", base 0x%" PRIx64 ", size 0x%" PRIx64,
index, index,

View File

@ -29,7 +29,7 @@ namespace test {
namespace { namespace {
TEST(CheckedRange, IsValid) { TEST(CheckedRange, IsValid) {
const struct UnsignedTestData { static constexpr struct {
uint32_t base; uint32_t base;
uint32_t size; uint32_t size;
bool valid; bool valid;
@ -79,7 +79,7 @@ TEST(CheckedRange, IsValid) {
}; };
for (size_t index = 0; index < arraysize(kUnsignedTestData); ++index) { for (size_t index = 0; index < arraysize(kUnsignedTestData); ++index) {
const UnsignedTestData& testcase = kUnsignedTestData[index]; const auto& testcase = kUnsignedTestData[index];
SCOPED_TRACE(base::StringPrintf("unsigned index %" PRIuS SCOPED_TRACE(base::StringPrintf("unsigned index %" PRIuS
", base 0x%x, size 0x%x", ", base 0x%x, size 0x%x",
index, index,
@ -91,7 +91,7 @@ TEST(CheckedRange, IsValid) {
} }
const int32_t kMinInt32 = std::numeric_limits<int32_t>::min(); const int32_t kMinInt32 = std::numeric_limits<int32_t>::min();
const struct SignedTestData { static constexpr struct {
int32_t base; int32_t base;
uint32_t size; uint32_t size;
bool valid; bool valid;
@ -141,7 +141,7 @@ TEST(CheckedRange, IsValid) {
}; };
for (size_t index = 0; index < arraysize(kSignedTestData); ++index) { for (size_t index = 0; index < arraysize(kSignedTestData); ++index) {
const SignedTestData& testcase = kSignedTestData[index]; const auto& testcase = kSignedTestData[index];
SCOPED_TRACE(base::StringPrintf("signed index %" PRIuS SCOPED_TRACE(base::StringPrintf("signed index %" PRIuS
", base 0x%x, size 0x%x", ", base 0x%x, size 0x%x",
index, index,
@ -154,7 +154,7 @@ TEST(CheckedRange, IsValid) {
} }
TEST(CheckedRange, ContainsValue) { TEST(CheckedRange, ContainsValue) {
const struct TestData { static constexpr struct {
uint32_t value; uint32_t value;
bool contains; bool contains;
} kTestData[] = { } kTestData[] = {
@ -187,7 +187,7 @@ TEST(CheckedRange, ContainsValue) {
ASSERT_TRUE(parent_range.IsValid()); ASSERT_TRUE(parent_range.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", value 0x%x", index, testcase.value)); "index %" PRIuS ", value 0x%x", index, testcase.value));
@ -196,7 +196,7 @@ TEST(CheckedRange, ContainsValue) {
} }
TEST(CheckedRange, ContainsRange) { TEST(CheckedRange, ContainsRange) {
const struct TestData { static constexpr struct {
uint32_t base; uint32_t base;
uint32_t size; uint32_t size;
bool contains; bool contains;
@ -235,7 +235,7 @@ TEST(CheckedRange, ContainsRange) {
ASSERT_TRUE(parent_range.IsValid()); ASSERT_TRUE(parent_range.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
index, index,
testcase.base, testcase.base,
@ -248,7 +248,7 @@ TEST(CheckedRange, ContainsRange) {
} }
TEST(CheckedRange, OverlapsRange) { TEST(CheckedRange, OverlapsRange) {
const struct TestData { static constexpr struct {
uint32_t base; uint32_t base;
uint32_t size; uint32_t size;
bool overlaps; bool overlaps;
@ -288,7 +288,7 @@ TEST(CheckedRange, OverlapsRange) {
ASSERT_TRUE(first_range.IsValid()); ASSERT_TRUE(first_range.IsValid());
for (size_t index = 0; index < arraysize(kTestData); ++index) { for (size_t index = 0; index < arraysize(kTestData); ++index) {
const TestData& testcase = kTestData[index]; const auto& testcase = kTestData[index];
SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
index, index,
testcase.base, testcase.base,

View File

@ -23,10 +23,10 @@ namespace {
TEST(Int128, UInt128) { TEST(Int128, UInt128) {
#if defined(ARCH_CPU_LITTLE_ENDIAN) #if defined(ARCH_CPU_LITTLE_ENDIAN)
const uint8_t kBytes[] = static constexpr uint8_t kBytes[] =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
#else #else
const uint8_t kBytes[] = static constexpr uint8_t kBytes[] =
{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
#endif #endif

View File

@ -75,9 +75,9 @@ void CloseNowOrOnExec(int fd, bool ebadf_ok) {
// no attempt needs to be made to close file descriptors that are not open. // no attempt needs to be made to close file descriptors that are not open.
bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) { bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
const char kFDDir[] = "/dev/fd"; static constexpr char kFDDir[] = "/dev/fd";
#elif defined(OS_LINUX) || defined(OS_ANDROID) #elif defined(OS_LINUX) || defined(OS_ANDROID)
const char kFDDir[] = "/proc/self/fd"; static constexpr char kFDDir[] = "/proc/self/fd";
#endif #endif
DIR* dir = opendir(kFDDir); DIR* dir = opendir(kFDDir);
@ -99,10 +99,10 @@ bool CloseMultipleNowOrOnExecUsingFDDir(int fd, int preserve_fd) {
// readdir_r() is deprecated as of glibc 2.24. See // readdir_r() is deprecated as of glibc 2.24. See
// https://sourceware.org/bugzilla/show_bug.cgi?id=19056 and // https://sourceware.org/bugzilla/show_bug.cgi?id=19056 and
// https://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit?id=0c52f6d623636a61eacd0f7b7a3bb942793a2a05. // https://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit?id=0c52f6d623636a61eacd0f7b7a3bb942793a2a05.
const char kReaddirName[] = "readdir"; static constexpr char kReaddirName[] = "readdir";
while ((errno = 0, result = readdir(dir)) != nullptr) while ((errno = 0, result = readdir(dir)) != nullptr)
#else #else
const char kReaddirName[] = "readdir_r"; static constexpr char kReaddirName[] = "readdir_r";
dirent entry; dirent entry;
while ((errno = readdir_r(dir, &entry, &result)) == 0 && result != nullptr) while ((errno = readdir_r(dir, &entry, &result)) == 0 && result != nullptr)
#endif #endif

View File

@ -26,7 +26,7 @@
namespace { namespace {
const char* kSignalNames[] = { constexpr const char* kSignalNames[] = {
nullptr, nullptr,
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
@ -108,7 +108,7 @@ static_assert(arraysize(kSignalNames) == 32, "kSignalNames length");
static_assert(arraysize(kSignalNames) == NSIG, "kSignalNames length"); static_assert(arraysize(kSignalNames) == NSIG, "kSignalNames length");
#endif #endif
const char kSigPrefix[] = "SIG"; constexpr char kSigPrefix[] = "SIG";
} // namespace } // namespace

View File

@ -29,7 +29,7 @@ namespace crashpad {
namespace test { namespace test {
namespace { namespace {
const struct { constexpr struct {
int signal; int signal;
const char* full_name; const char* full_name;
const char* short_name; const char* short_name;
@ -157,7 +157,7 @@ void TestStringToSignal(const base::StringPiece& string,
} }
TEST(SymbolicConstantsPOSIX, StringToSignal) { TEST(SymbolicConstantsPOSIX, StringToSignal) {
const StringToSymbolicConstantOptions kOptions[] = { static constexpr StringToSymbolicConstantOptions kOptions[] = {
0, 0,
kAllowFullName, kAllowFullName,
kAllowShortName, kAllowShortName,
@ -198,7 +198,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) {
} }
} }
const char* const kNegativeTestData[] = { static constexpr const char* kNegativeTestData[] = {
"SIGHUP ", "SIGHUP ",
" SIGINT", " SIGINT",
"QUIT ", "QUIT ",
@ -216,7 +216,7 @@ TEST(SymbolicConstantsPOSIX, StringToSignal) {
TestStringToSignal(kNegativeTestData[index], options, false, 0); TestStringToSignal(kNegativeTestData[index], options, false, 0);
} }
const struct { static constexpr struct {
const char* string; const char* string;
size_t length; size_t length;
} kNULTestData[] = { } kNULTestData[] = {

View File

@ -26,7 +26,7 @@ namespace test {
namespace { namespace {
TEST(StringNumberConversion, StringToInt) { TEST(StringNumberConversion, StringToInt) {
const struct { static constexpr struct {
const char* string; const char* string;
bool valid; bool valid;
int value; int value;
@ -113,7 +113,7 @@ TEST(StringNumberConversion, StringToInt) {
// Ensure that embedded NUL characters are treated as bad input. The string // Ensure that embedded NUL characters are treated as bad input. The string
// is split to avoid MSVC warning: // is split to avoid MSVC warning:
// "decimal digit terminates octal escape sequence". // "decimal digit terminates octal escape sequence".
const char input[] = "6\000" "6"; static constexpr char input[] = "6\000" "6";
base::StringPiece input_string(input, arraysize(input) - 1); base::StringPiece input_string(input, arraysize(input) - 1);
int output; int output;
EXPECT_FALSE(StringToNumber(input_string, &output)); EXPECT_FALSE(StringToNumber(input_string, &output));
@ -124,7 +124,7 @@ TEST(StringNumberConversion, StringToInt) {
} }
TEST(StringNumberConversion, StringToUnsignedInt) { TEST(StringNumberConversion, StringToUnsignedInt) {
const struct { static constexpr struct {
const char* string; const char* string;
bool valid; bool valid;
unsigned int value; unsigned int value;
@ -211,7 +211,7 @@ TEST(StringNumberConversion, StringToUnsignedInt) {
// Ensure that embedded NUL characters are treated as bad input. The string // Ensure that embedded NUL characters are treated as bad input. The string
// is split to avoid MSVC warning: // is split to avoid MSVC warning:
// "decimal digit terminates octal escape sequence". // "decimal digit terminates octal escape sequence".
const char input[] = "6\000" "6"; static constexpr char input[] = "6\000" "6";
base::StringPiece input_string(input, arraysize(input) - 1); base::StringPiece input_string(input, arraysize(input) - 1);
unsigned int output; unsigned int output;
EXPECT_FALSE(StringToNumber(input_string, &output)); EXPECT_FALSE(StringToNumber(input_string, &output));
@ -222,7 +222,7 @@ TEST(StringNumberConversion, StringToUnsignedInt) {
} }
TEST(StringNumberConversion, StringToInt64) { TEST(StringNumberConversion, StringToInt64) {
const struct { static constexpr struct {
const char* string; const char* string;
bool valid; bool valid;
int64_t value; int64_t value;
@ -271,7 +271,7 @@ TEST(StringNumberConversion, StringToInt64) {
} }
TEST(StringNumberConversion, StringToUnsignedInt64) { TEST(StringNumberConversion, StringToUnsignedInt64) {
const struct { static constexpr struct {
const char* string; const char* string;
bool valid; bool valid;
uint64_t value; uint64_t value;

View File

@ -41,7 +41,8 @@ TEST(strlcpy, c16lcpy) {
// Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and // Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and
// nonzero low and high bytes. // nonzero low and high bytes.
const base::char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; static constexpr base::char16 test_characters[] =
{0x4d, 0xe9, 0x100, 0x151, 0x1e18};
for (size_t index = 0; index < arraysize(test_characters); ++index) { for (size_t index = 0; index < arraysize(test_characters); ++index) {
base::char16 test_character = test_characters[index]; base::char16 test_character = test_characters[index];

View File

@ -23,7 +23,7 @@ namespace test {
namespace { namespace {
TEST(strnlen, strnlen) { TEST(strnlen, strnlen) {
const char kTestBuffer[] = "abc\0d"; static constexpr char kTestBuffer[] = "abc\0d";
ASSERT_EQ(strlen(kTestBuffer), 3u); ASSERT_EQ(strlen(kTestBuffer), 3u);
EXPECT_EQ(crashpad::strnlen(kTestBuffer, 0), 0u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 0), 0u);
EXPECT_EQ(crashpad::strnlen(kTestBuffer, 1), 1u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 1), 1u);
@ -33,7 +33,7 @@ TEST(strnlen, strnlen) {
EXPECT_EQ(crashpad::strnlen(kTestBuffer, 5), 3u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 5), 3u);
EXPECT_EQ(crashpad::strnlen(kTestBuffer, 6), 3u); EXPECT_EQ(crashpad::strnlen(kTestBuffer, 6), 3u);
const char kEmptyBuffer[] = "\0"; static constexpr char kEmptyBuffer[] = "\0";
ASSERT_EQ(strlen(kEmptyBuffer), 0u); ASSERT_EQ(strlen(kEmptyBuffer), 0u);
EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 0), 0u); EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 0), 0u);
EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 1), 0u); EXPECT_EQ(crashpad::strnlen(kEmptyBuffer, 1), 0u);

View File

@ -50,7 +50,7 @@ std::string MessageString(const std::string& log_message) {
return std::string(); return std::string();
} }
const char kFindString[] = "] "; static constexpr char kFindString[] = "] ";
size_t pos = log_message.find(kFindString); size_t pos = log_message.find(kFindString);
if (pos == std::string::npos) { if (pos == std::string::npos) {
EXPECT_NE(pos, std::string::npos); EXPECT_NE(pos, std::string::npos);
@ -78,7 +78,7 @@ TEST(ThreadLogMessages, Basic) {
ASSERT_TRUE(LOG_IS_ON(INFO)); ASSERT_TRUE(LOG_IS_ON(INFO));
{ {
const char* const kMessages[] = { static constexpr const char* kMessages[] = {
"An info message", "An info message",
"A warning message", "A warning message",
"An error message", "An error message",
@ -101,7 +101,7 @@ TEST(ThreadLogMessages, Basic) {
} }
{ {
const char kMessage[] = "Sample error message"; static constexpr char kMessage[] = "Sample error message";
ThreadLogMessages thread_log_messages; ThreadLogMessages thread_log_messages;

View File

@ -60,10 +60,10 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("simple"); SCOPED_TRACE("simple");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"argument 1", L"argument 1",
L"argument 2", L"argument 2",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -71,11 +71,11 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("path with spaces"); SCOPED_TRACE("path with spaces");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"argument1", L"argument1",
L"argument 2", L"argument 2",
L"\\some\\path with\\spaces", L"\\some\\path with\\spaces",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -83,11 +83,11 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("argument with embedded quotation marks"); SCOPED_TRACE("argument with embedded quotation marks");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"argument1", L"argument1",
L"she said, \"you had me at hello\"", L"she said, \"you had me at hello\"",
L"\\some\\path with\\spaces", L"\\some\\path with\\spaces",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -95,12 +95,12 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("argument with unbalanced quotation marks"); SCOPED_TRACE("argument with unbalanced quotation marks");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"argument1", L"argument1",
L"argument\"2", L"argument\"2",
L"argument3", L"argument3",
L"argument4", L"argument4",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -108,10 +108,10 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("argument ending with backslash"); SCOPED_TRACE("argument ending with backslash");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"\\some\\directory with\\spaces\\", L"\\some\\directory with\\spaces\\",
L"argument2", L"argument2",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -119,10 +119,10 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("empty argument"); SCOPED_TRACE("empty argument");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"", L"",
L"argument2", L"argument2",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }
@ -130,34 +130,34 @@ TEST(CommandLine, AppendCommandLineArgument) {
{ {
SCOPED_TRACE("funny nonprintable characters"); SCOPED_TRACE("funny nonprintable characters");
const wchar_t* const kArguments[] = { static constexpr wchar_t* const kArguments[] = {
L"child.exe", L"child.exe",
L"argument 1", L"argument 1",
L"argument\t2", L"argument\t2",
L"argument\n3", L"argument\n3",
L"argument\v4", L"argument\v4",
L"argument\"5", L"argument\"5",
L" ", L" ",
L"\t", L"\t",
L"\n", L"\n",
L"\v", L"\v",
L"\"", L"\"",
L" x", L" x",
L"\tx", L"\tx",
L"\nx", L"\nx",
L"\vx", L"\vx",
L"\"x", L"\"x",
L"x ", L"x ",
L"x\t", L"x\t",
L"x\n", L"x\n",
L"x\v", L"x\v",
L"x\"", L"x\"",
L" ", L" ",
L"\t\t", L"\t\t",
L"\n\n", L"\n\n",
L"\v\v", L"\v\v",
L"\"\"", L"\"\"",
L" \t\n\v\"", L" \t\n\v\"",
}; };
AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); AppendCommandLineArgumentTest(arraysize(kArguments), kArguments);
} }

View File

@ -42,7 +42,7 @@ namespace crashpad {
namespace test { namespace test {
namespace { namespace {
const wchar_t kNtdllName[] = L"\\ntdll.dll"; constexpr wchar_t kNtdllName[] = L"\\ntdll.dll";
bool IsProcessWow64(HANDLE process_handle) { bool IsProcessWow64(HANDLE process_handle) {
static const auto is_wow64_process = static const auto is_wow64_process =
@ -101,7 +101,7 @@ TEST(ProcessInfo, Self) {
std::vector<ProcessInfo::Module> modules; std::vector<ProcessInfo::Module> modules;
EXPECT_TRUE(process_info.Modules(&modules)); EXPECT_TRUE(process_info.Modules(&modules));
ASSERT_GE(modules.size(), 2u); ASSERT_GE(modules.size(), 2u);
const wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; static constexpr wchar_t kSelfName[] = L"\\crashpad_util_test.exe";
ASSERT_GE(modules[0].name.size(), wcslen(kSelfName)); ASSERT_GE(modules[0].name.size(), wcslen(kSelfName));
EXPECT_EQ(modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName)), EXPECT_EQ(modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName)),
kSelfName); kSelfName);
@ -178,7 +178,7 @@ void TestOtherProcess(const base::string16& directory_modification) {
kNtdllName); kNtdllName);
// lz32.dll is an uncommonly-used-but-always-available module that the test // lz32.dll is an uncommonly-used-but-always-available module that the test
// binary manually loads. // binary manually loads.
const wchar_t kLz32dllName[] = L"\\lz32.dll"; static constexpr wchar_t kLz32dllName[] = L"\\lz32.dll";
ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName)); ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName));
EXPECT_EQ(modules.back().name.substr(modules.back().name.size() - EXPECT_EQ(modules.back().name.substr(modules.back().name.size() -
wcslen(kLz32dllName)), wcslen(kLz32dllName)),

View File

@ -136,7 +136,7 @@ const void* GetSecurityDescriptorForNamedPipeInstance(size_t* size) {
// would in turn cause deadlock. // would in turn cause deadlock.
#pragma pack(push, 1) #pragma pack(push, 1)
static const struct SecurityDescriptorBlob { static constexpr struct SecurityDescriptorBlob {
// See https://msdn.microsoft.com/en-us/library/cc230366.aspx. // See https://msdn.microsoft.com/en-us/library/cc230366.aspx.
SECURITY_DESCRIPTOR_RELATIVE sd_rel; SECURITY_DESCRIPTOR_RELATIVE sd_rel;
struct { struct {

View File

@ -33,7 +33,7 @@ TEST(SecurityDescriptor, MatchesAdvapi32) {
// Mandatory Label, no ACE flags, no ObjectType, integrity level // Mandatory Label, no ACE flags, no ObjectType, integrity level
// untrusted. // untrusted.
const wchar_t kSddl[] = L"S:(ML;;;;;S-1-16-0)"; static constexpr wchar_t kSddl[] = L"S:(ML;;;;;S-1-16-0)";
PSECURITY_DESCRIPTOR sec_desc; PSECURITY_DESCRIPTOR sec_desc;
ULONG sec_desc_len; ULONG sec_desc_len;
ASSERT_TRUE(ConvertStringSecurityDescriptorToSecurityDescriptor( ASSERT_TRUE(ConvertStringSecurityDescriptorToSecurityDescriptor(

View File

@ -134,7 +134,7 @@ TEST(SafeTerminateProcess, PatchBadly) {
// https://crashpad.chromium.org/bug/179. In reality, this only affects // https://crashpad.chromium.org/bug/179. In reality, this only affects
// 32-bit x86, as theres no calling convention confusion on x86_64. It // 32-bit x86, as theres no calling convention confusion on x86_64. It
// doesnt hurt to run this test in the 64-bit environment, though. // doesnt hurt to run this test in the 64-bit environment, though.
const uint8_t patch[] = { static constexpr uint8_t patch[] = {
#if defined(ARCH_CPU_X86) #if defined(ARCH_CPU_X86)
0x31, 0xc0, // xor eax, eax 0x31, 0xc0, // xor eax, eax
#elif defined(ARCH_CPU_X86_64) #elif defined(ARCH_CPU_X86_64)