diff --git a/lldb/include/lldb/Utility/UUID.h b/lldb/include/lldb/Utility/UUID.h --- a/lldb/include/lldb/Utility/UUID.h +++ b/lldb/include/lldb/Utility/UUID.h @@ -21,8 +21,18 @@ class Stream; class UUID { + // Represents UUID's of various sizes. In all cases, a uuid of all zeros is + // treated as an "Invalid UUID" marker, and the UUID created from such data + // will return false for IsValid. public: UUID() = default; + + /// Creates a uuid from the data pointed to by the bytes argument. + UUID(llvm::ArrayRef bytes) : m_bytes(bytes.begin(), bytes.end()) { + if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) { + Clear(); + } + } // Reference: // https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html @@ -38,35 +48,15 @@ }; /// Create a UUID from CvRecordPdb70. - static UUID fromCvRecord(CvRecordPdb70 debug_info); - - /// Creates a UUID from the data pointed to by the bytes argument. No special - /// significance is attached to any of the values. - static UUID fromData(const void *bytes, uint32_t num_bytes) { - if (bytes) - return fromData({reinterpret_cast(bytes), num_bytes}); - return UUID(); - } - - /// Creates a uuid from the data pointed to by the bytes argument. No special - /// significance is attached to any of the values. - static UUID fromData(llvm::ArrayRef bytes) { return UUID(bytes); } - - /// Creates a UUID from the data pointed to by the bytes argument. Data - /// consisting purely of zero bytes is treated as an invalid UUID. - static UUID fromOptionalData(const void *bytes, uint32_t num_bytes) { - if (bytes) - return fromOptionalData( - {reinterpret_cast(bytes), num_bytes}); - return UUID(); - } - - /// Creates a UUID from the data pointed to by the bytes argument. Data - /// consisting purely of zero bytes is treated as an invalid UUID. - static UUID fromOptionalData(llvm::ArrayRef bytes) { - if (llvm::all_of(bytes, [](uint8_t b) { return b == 0; })) - return UUID(); - return UUID(bytes); + UUID(CvRecordPdb70 debug_info); + + /// Creates a UUID from the data pointed to by the bytes argument. + UUID(const void *bytes, uint32_t num_bytes) { + if (!bytes) + return; + *this + = UUID(llvm::ArrayRef(reinterpret_cast(bytes), + num_bytes)); } void Clear() { m_bytes.clear(); } @@ -77,15 +67,11 @@ explicit operator bool() const { return IsValid(); } bool IsValid() const { return !m_bytes.empty(); } - + std::string GetAsString(llvm::StringRef separator = "-") const; bool SetFromStringRef(llvm::StringRef str); - // Same as SetFromStringRef, but if the resultant UUID is all 0 bytes, set the - // UUID to invalid. - bool SetFromOptionalStringRef(llvm::StringRef str); - /// Decode as many UUID bytes as possible from the C string \a cstr. /// /// \param[in] str @@ -103,8 +89,6 @@ llvm::SmallVectorImpl &uuid_bytes); private: - UUID(llvm::ArrayRef bytes) : m_bytes(bytes.begin(), bytes.end()) {} - // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations // for this case. llvm::SmallVector m_bytes; diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp --- a/lldb/source/API/SBModuleSpec.cpp +++ b/lldb/source/API/SBModuleSpec.cpp @@ -134,7 +134,7 @@ bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { LLDB_INSTRUMENT_VA(this, uuid, uuid_len) - m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); + m_opaque_up->GetUUID() = UUID(uuid, uuid_len); return m_opaque_up->GetUUID().IsValid(); } diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp --- a/lldb/source/Core/DataFileCache.cpp +++ b/lldb/source/Core/DataFileCache.cpp @@ -238,7 +238,7 @@ const uint8_t length = data.GetU8(offset_ptr); const uint8_t *bytes = (const uint8_t *)data.GetData(offset_ptr, length); if (bytes != nullptr && length > 0) - m_uuid = UUID::fromData(llvm::ArrayRef(bytes, length)); + m_uuid = UUID(llvm::ArrayRef(bytes, length)); } break; case eSignatureModTime: { uint32_t mod_time = data.GetU32(offset_ptr); diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -565,7 +565,7 @@ assert(minVmAddr != UINT_MAX); assert(maxVmAddr != 0); m_images[dyld_image_get_installname(image)] = SharedCacheImageInfo{ - UUID::fromData(uuid, 16), + UUID(uuid, 16), std::make_shared((uint8_t *)minVmAddr, maxVmAddr - minVmAddr)}; }); @@ -585,12 +585,12 @@ _dyld_get_shared_cache_range(&shared_cache_size); uuid_t dsc_uuid; _dyld_get_shared_cache_uuid(dsc_uuid); - m_uuid = UUID::fromData(dsc_uuid); + m_uuid = UUID(dsc_uuid); dyld_shared_cache_iterate_text( dsc_uuid, ^(const dyld_shared_cache_dylib_text_info *info) { m_images[info->path] = SharedCacheImageInfo{ - UUID::fromData(info->dylibUuid, 16), + UUID(info->dylibUuid, 16), std::make_shared( shared_cache_start + info->textSegmentOffset, shared_cache_size - info->textSegmentOffset)}; diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -1389,7 +1389,7 @@ if (name_data == nullptr) break; image_infos[i].SetName((const char *)name_data); - UUID uuid = UUID::fromOptionalData(extractor.GetData(&offset, 16), 16); + UUID uuid(extractor.GetData(&offset, 16), 16); image_infos[i].SetUUID(uuid); image_infos[i].SetLoadAddress(extractor.GetU64(&offset)); image_infos[i].SetSize(extractor.GetU64(&offset)); diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -501,7 +501,7 @@ image_infos[i].segments.push_back(segment); } - image_infos[i].uuid.SetFromOptionalStringRef( + image_infos[i].uuid.SetFromStringRef( image->GetValueForKey("uuid")->GetAsString()->GetValue()); // All sections listed in the dyld image info structure will all either be diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -885,7 +885,7 @@ break; case llvm::MachO::LC_UUID: - dylib_info.uuid = UUID::fromOptionalData(data.GetData(&offset, 16), 16); + dylib_info.uuid = UUID(data.GetData(&offset, 16), 16); break; default: @@ -1093,7 +1093,7 @@ uuid_t shared_cache_uuid; if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid, sizeof(uuid_t), err) == sizeof(uuid_t)) { - uuid = UUID::fromOptionalData(shared_cache_uuid, 16); + uuid = UUID(shared_cache_uuid, 16); if (uuid.IsValid()) { using_shared_cache = eLazyBoolYes; } diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp b/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp --- a/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp +++ b/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp @@ -122,8 +122,8 @@ // On non-windows, the age field should always be zero, so we don't include to // match the native uuid format of these platforms. - return UUID::fromData(&data, os == llvm::Triple::Win32 ? sizeof(data) - : sizeof(data.uuid)); + return UUID(&data, os == llvm::Triple::Win32 ? sizeof(data) + : sizeof(data.uuid)); } llvm::Optional Record::classify(llvm::StringRef Line) { diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -627,13 +627,13 @@ if (gnu_debuglink_crc) { // Use 4 bytes of crc from the .gnu_debuglink section. u32le data(gnu_debuglink_crc); - uuid = UUID::fromData(&data, sizeof(data)); + uuid = UUID(&data, sizeof(data)); } else if (core_notes_crc) { // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make // it look different form .gnu_debuglink crc followed by 4 bytes // of note segments crc. u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)}; - uuid = UUID::fromData(data, sizeof(data)); + uuid = UUID(data, sizeof(data)); } } @@ -788,7 +788,7 @@ // look different form .gnu_debuglink crc - followed by 4 bytes of note // segments crc. u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)}; - m_uuid = UUID::fromData(data, sizeof(data)); + m_uuid = UUID(data, sizeof(data)); } } else { if (!m_gnu_debuglink_crc) @@ -796,7 +796,7 @@ if (m_gnu_debuglink_crc) { // Use 4 bytes of crc from the .gnu_debuglink section. u32le data(m_gnu_debuglink_crc); - m_uuid = UUID::fromData(&data, sizeof(data)); + m_uuid = UUID(&data, sizeof(data)); } } } @@ -1134,7 +1134,7 @@ if (note.n_descsz >= 4) { if (const uint8_t *buf = data.PeekData(offset, note.n_descsz)) { // Save the build id as the UUID for the module. - uuid = UUID::fromData(buf, note.n_descsz); + uuid = UUID(buf, note.n_descsz); } else { error.SetErrorString("failed to read GNU_BUILD_ID note payload"); return error; diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -2177,8 +2177,8 @@ version_str[6] = '\0'; if (strcmp(version_str, "dyld_v") == 0) { offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid); - dsc_uuid = UUID::fromOptionalData( - dsc_header_data.GetData(&offset, sizeof(uuid_t)), sizeof(uuid_t)); + dsc_uuid = UUID(dsc_header_data.GetData(&offset, sizeof(uuid_t)), + sizeof(uuid_t)); } Log *log = GetLog(LLDBLog::Symbols); if (log && dsc_uuid.IsValid()) { @@ -2318,7 +2318,7 @@ const uint8_t *uuid_bytes = m_data.PeekData(offset, 16); if (uuid_bytes) - image_uuid = UUID::fromOptionalData(uuid_bytes, 16); + image_uuid = UUID(uuid_bytes, 16); break; } @@ -2715,7 +2715,7 @@ return; if (process_shared_cache_uuid.IsValid() && - process_shared_cache_uuid != UUID::fromOptionalData(&cache_uuid, 16)) + process_shared_cache_uuid != UUID::fromData(&cache_uuid, 16)) return; dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) { @@ -2724,7 +2724,7 @@ return; dyld_image_copy_uuid(image, &dsc_image_uuid); - if (image_uuid != UUID::fromOptionalData(dsc_image_uuid, 16)) + if (image_uuid != UUID::fromData(dsc_image_uuid, 16)) return; found_image = true; @@ -4842,7 +4842,7 @@ if (!memcmp(uuid_bytes, opencl_uuid, 16)) return UUID(); - return UUID::fromOptionalData(uuid_bytes, 16); + return UUID(uuid_bytes, 16); } return UUID(); } @@ -5605,8 +5605,7 @@ } if (m_data.CopyData(offset, sizeof(uuid_t), raw_uuid) != 0) { - if (!uuid_is_null(raw_uuid)) - uuid = UUID::fromOptionalData(raw_uuid, sizeof(uuid_t)); + uuid = UUID(raw_uuid, sizeof(uuid_t)); // convert the "main bin spec" type into our // ObjectFile::BinaryType enum switch (binspec_type) { @@ -5901,7 +5900,7 @@ 100); // sharedCacheBaseAddress } } - uuid = UUID::fromOptionalData(sharedCacheUUID_address, sizeof(uuid_t)); + uuid = UUID(sharedCacheUUID_address, sizeof(uuid_t)); } } } else { @@ -5930,7 +5929,7 @@ dyld_process_info_get_cache(process_info, &sc_info); if (sc_info.cacheBaseAddress != 0) { base_addr = sc_info.cacheBaseAddress; - uuid = UUID::fromOptionalData(sc_info.cacheUUID, sizeof(uuid_t)); + uuid = UUID(sc_info.cacheUUID, sizeof(uuid_t)); } dyld_process_info_release(process_info); } @@ -6917,8 +6916,7 @@ MachOCorefileImageEntry image_entry; image_entry.filename = (const char *)m_data.GetCStr(&filepath_offset); - if (!uuid_is_null(uuid)) - image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); + image_entry.uuid = UUID(uuid, sizeof(uuid_t)); image_entry.load_address = load_address; image_entry.currently_executing = currently_executing; @@ -6949,8 +6947,7 @@ MachOCorefileImageEntry image_entry; image_entry.filename = filename; - if (!uuid_is_null(uuid)) - image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); + image_entry.uuid = UUID(uuid, sizeof(uuid_t)); image_entry.load_address = load_address; image_entry.slide = slide; image_entry.currently_executing = true; diff --git a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp --- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -31,7 +31,7 @@ UUID::CvRecordPdb70 debug_info; memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid)); debug_info.Age = IS.getAge(); - return UUID::fromCvRecord(debug_info); + return UUID(debug_info); } char ObjectFilePDB::ID; diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -147,7 +147,7 @@ UUID::CvRecordPdb70 info; memcpy(&info.Uuid, pdb_info->PDB70.Signature, sizeof(info.Uuid)); info.Age = pdb_info->PDB70.Age; - return UUID::fromCvRecord(info); + return UUID(info); } } @@ -170,7 +170,7 @@ } // Use 4 bytes of crc from the .gnu_debuglink section. llvm::support::ulittle32_t data(gnu_debuglink_crc); - return UUID::fromData(&data, sizeof(data)); + return UUID(&data, sizeof(data)); } char ObjectFilePECOFF::ID; diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp --- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp +++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp @@ -68,13 +68,13 @@ return UUID(); if (GetArchitecture().GetTriple().isOSBinFormatELF()) { if (pdb70_uuid->Age != 0) - return UUID::fromOptionalData(pdb70_uuid, sizeof(*pdb70_uuid)); - return UUID::fromOptionalData(&pdb70_uuid->Uuid, + return UUID(pdb70_uuid, sizeof(*pdb70_uuid)); + return UUID(&pdb70_uuid->Uuid, sizeof(pdb70_uuid->Uuid)); } - return UUID::fromCvRecord(*pdb70_uuid); + return UUID(*pdb70_uuid); } else if (cv_signature == CvSignature::ElfBuildId) - return UUID::fromOptionalData(cv_record); + return UUID(cv_record); return UUID(); } diff --git a/lldb/source/Utility/UUID.cpp b/lldb/source/Utility/UUID.cpp --- a/lldb/source/Utility/UUID.cpp +++ b/lldb/source/Utility/UUID.cpp @@ -35,14 +35,15 @@ } } -UUID UUID::fromCvRecord(UUID::CvRecordPdb70 debug_info) { +UUID::UUID(UUID::CvRecordPdb70 debug_info) { llvm::sys::swapByteOrder(debug_info.Uuid.Data1); llvm::sys::swapByteOrder(debug_info.Uuid.Data2); llvm::sys::swapByteOrder(debug_info.Uuid.Data3); llvm::sys::swapByteOrder(debug_info.Age); if (debug_info.Age) - return UUID::fromOptionalData(&debug_info, sizeof(debug_info)); - return UUID::fromOptionalData(&debug_info.Uuid, sizeof(debug_info.Uuid)); + *this = UUID(&debug_info, sizeof(debug_info)); + else + *this = UUID(&debug_info.Uuid, sizeof(debug_info.Uuid)); } std::string UUID::GetAsString(llvm::StringRef separator) const { @@ -107,16 +108,6 @@ if (!rest.empty() || bytes.empty()) return false; - *this = fromData(bytes); + *this = UUID(bytes); return true; } - -bool UUID::SetFromOptionalStringRef(llvm::StringRef str) { - bool result = SetFromStringRef(str); - if (result) { - if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) - Clear(); - } - - return result; -} diff --git a/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp b/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp --- a/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp +++ b/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp @@ -37,7 +37,7 @@ TEST(ModuleRecord, parse) { EXPECT_EQ(ModuleRecord(llvm::Triple::Linux, llvm::Triple::x86_64, - UUID::fromData("@ABCDEFGHIJKLMNO", 16)), + UUID("@ABCDEFGHIJKLMNO", 16)), ModuleRecord::parse( "MODULE Linux x86_64 404142434445464748494a4b4c4d4e4f0 a.out")); @@ -49,7 +49,7 @@ } TEST(InfoRecord, parse) { - EXPECT_EQ(InfoRecord(UUID::fromData("@ABCDEFGHIJKLMNO", 16)), + EXPECT_EQ(InfoRecord(UUID("@ABCDEFGHIJKLMNO", 16)), InfoRecord::parse("INFO CODE_ID 404142434445464748494a4b4c4d4e4f")); EXPECT_EQ(InfoRecord(UUID()), InfoRecord::parse("INFO CODE_ID 47 a.exe")); diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp --- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp @@ -194,7 +194,7 @@ ASSERT_EQ(1u, result->size()); EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath()); EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple()); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), result.value()[0].GetUUID()); EXPECT_EQ(0u, result.value()[0].GetObjectOffset()); EXPECT_EQ(1234u, result.value()[0].GetObjectSize()); @@ -219,7 +219,7 @@ ASSERT_EQ(1u, result->size()); EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath()); EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple()); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), result.value()[0].GetUUID()); EXPECT_EQ(0u, result.value()[0].GetObjectOffset()); EXPECT_EQ(1234u, result.value()[0].GetObjectSize()); diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp --- a/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp @@ -231,7 +231,7 @@ EncodeDecode(sig, /*encode_result=*/false); sig.Clear(); - sig.m_uuid = UUID::fromData("@\x00\x11\x22\x33\x44\x55\x66\x77", 8); + sig.m_uuid = UUID("@\x00\x11\x22\x33\x44\x55\x66\x77", 8); EXPECT_TRUE(sig.IsValid()); EncodeDecode(sig, /*encode_result=*/true); sig.m_mod_time = 0x12345678; diff --git a/lldb/unittests/Utility/UUIDTest.cpp b/lldb/unittests/Utility/UUIDTest.cpp --- a/lldb/unittests/Utility/UUIDTest.cpp +++ b/lldb/unittests/Utility/UUIDTest.cpp @@ -14,10 +14,10 @@ TEST(UUIDTest, RelationalOperators) { UUID empty; - UUID a16 = UUID::fromData("1234567890123456", 16); - UUID b16 = UUID::fromData("1234567890123457", 16); - UUID a20 = UUID::fromData("12345678901234567890", 20); - UUID b20 = UUID::fromData("12345678900987654321", 20); + UUID a16 = UUID("1234567890123456", 16); + UUID b16 = UUID("1234567890123457", 16); + UUID a20 = UUID("12345678901234567890", 20); + UUID b20 = UUID("12345678900987654321", 20); EXPECT_EQ(empty, empty); EXPECT_EQ(a16, a16); @@ -37,59 +37,52 @@ TEST(UUIDTest, Validity) { UUID empty; std::vector zeroes(20, 0); - UUID a16 = UUID::fromData(zeroes.data(), 16); - UUID a20 = UUID::fromData(zeroes.data(), 20); - UUID a16_0 = UUID::fromOptionalData(zeroes.data(), 16); - UUID a20_0 = UUID::fromOptionalData(zeroes.data(), 20); + UUID a16 = UUID(zeroes.data(), 16); + UUID a20 = UUID(zeroes.data(), 20); UUID from_str; from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000"); - UUID opt_from_str; - opt_from_str.SetFromOptionalStringRef("00000000-0000-0000-0000-000000000000"); EXPECT_FALSE(empty); - EXPECT_TRUE(a16); - EXPECT_TRUE(a20); - EXPECT_TRUE(from_str); - EXPECT_FALSE(a16_0); - EXPECT_FALSE(a20_0); - EXPECT_FALSE(opt_from_str); + EXPECT_FALSE(a16); + EXPECT_FALSE(a20); + EXPECT_FALSE(from_str); } TEST(UUIDTest, SetFromStringRef) { UUID u; EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f")); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u); + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u); EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f")); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u); + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u); EXPECT_TRUE( u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253")); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), u); + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u); EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f")); EXPECT_FALSE(u.SetFromStringRef("40xxxxx")); EXPECT_FALSE(u.SetFromStringRef("")); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u) + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u) << "uuid was changed by failed parse calls"; EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253")); - EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), u); + EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u); EXPECT_TRUE(u.SetFromStringRef("40414243")); - EXPECT_EQ(UUID::fromData("@ABCD", 4), u); + EXPECT_EQ(UUID("@ABCD", 4), u); EXPECT_FALSE(u.SetFromStringRef("4")); } TEST(UUIDTest, StringConverion) { - EXPECT_EQ("40414243", UUID::fromData("@ABC", 4).GetAsString()); - EXPECT_EQ("40414243-4445-4647", UUID::fromData("@ABCDEFG", 8).GetAsString()); + EXPECT_EQ("40414243", UUID("@ABC", 4).GetAsString()); + EXPECT_EQ("40414243-4445-4647", UUID("@ABCDEFG", 8).GetAsString()); EXPECT_EQ("40414243-4445-4647-4849-4A4B", - UUID::fromData("@ABCDEFGHIJK", 12).GetAsString()); + UUID("@ABCDEFGHIJK", 12).GetAsString()); EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F", - UUID::fromData("@ABCDEFGHIJKLMNO", 16).GetAsString()); + UUID("@ABCDEFGHIJKLMNO", 16).GetAsString()); EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253", - UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString()); + UUID("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString()); }