Chromium Code Reviews| Index: util/misc/uuid_test.cc |
| diff --git a/util/misc/uuid_test.cc b/util/misc/uuid_test.cc |
| index 2bd4ceb0cc4f1ff9a4d4c5834a7bcca831304d6e..27e5724b59fe52c4ea64cf2780aaa51369248149 100644 |
| --- a/util/misc/uuid_test.cc |
| +++ b/util/misc/uuid_test.cc |
| @@ -19,6 +19,7 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/strings/stringprintf.h" |
| #include "gtest/gtest.h" |
| namespace crashpad { |
| @@ -152,6 +153,50 @@ TEST(UUID, UUID) { |
| EXPECT_EQ("45454545-4545-4545-4545-454545454545", uuid.ToString()); |
| } |
| +TEST(UUID, FromString) { |
|
Mark Mentovai
2015/01/02 23:33:46
const (and kCases?)
Robert Sesek
2015/01/02 23:46:00
Done.
|
| + struct TestCase { |
| + const char uuid_string[37]; |
|
Mark Mentovai
2015/01/02 23:33:46
Probably ought to be const char*, especially in li
Robert Sesek
2015/01/02 23:46:00
Done.
|
| + bool success; |
| + } cases[] = { |
| + // Valid: |
| + {"c6849cb5-fe14-4a79-8978-9ae6034c521d", true}, |
| + {"00000000-0000-0000-0000-000000000000", true}, |
| + {"ffffffff-ffff-ffff-ffff-ffffffffffff", true}, |
| + // Outside HEX range: |
| + {"7318z10b-c453-4cef-9dc8-015655cb4bbc", false}, |
| + {"7318a10b-c453-4cef-9dz8-015655cb4bbc", false}, |
| + // Incomplete: |
| + {"15655cb4-", false}, |
| + {"7318f10b-c453-4cef-9dc8-015655cb4bb", false}, |
| + {"318f10b-c453-4cef-9dc8-015655cb4bb2", false}, |
| + {"7318f10b-c453-4ef-9dc8-015655cb4bb2", false}, |
| + {"", false}, |
| + {"abcd", false}, |
|
Mark Mentovai
2015/01/02 23:33:46
You should also have a test case that is a valid U
Robert Sesek
2015/01/02 23:45:59
Done.
|
| + }; |
| + |
| + const std::string empty_uuid = UUID().ToString(); |
| + |
| + for (size_t index = 0; index < arraysize(cases); ++index) { |
| + const TestCase& test_case = cases[index]; |
| + SCOPED_TRACE( |
| + base::StringPrintf("index %zu: %s", index, test_case.uuid_string)); |
| + |
| + UUID uuid; |
| + EXPECT_EQ(test_case.success, |
| + uuid.InitializeFromString(test_case.uuid_string)); |
| + if (test_case.success) { |
| + EXPECT_EQ(test_case.uuid_string, uuid.ToString()); |
| + } else { |
| + EXPECT_EQ(empty_uuid, uuid.ToString()); |
| + } |
| + } |
| + |
| + // Test for case insensitivty. |
| + UUID uuid; |
| + uuid.InitializeFromString("F32E5BDC-2681-4C73-A4E6-911FFD89B846"); |
|
Mark Mentovai
2015/01/02 23:33:46
I was going to ask for this in the list of cases a
Robert Sesek
2015/01/02 23:46:00
Done.
|
| + EXPECT_EQ("f32e5bdc-2681-4c73-a4e6-911ffd89b846", uuid.ToString()); |
| +} |
| + |
| } // namespace |
| } // namespace test |
| } // namespace crashpad |