Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/bluetooth/bluetooth_device_id.h" | |
| 6 | |
| 7 #include "base/base64.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "crypto/random.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using content::BluetoothDeviceId; | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const char kValidDeviceId1[] = "1234567890123456789012=="; | |
| 17 const char kValidDeviceId2[] = "AbCdEfGhIjKlMnOpQrSt+/=="; | |
| 18 const char kInvalidLongDeviceId[] = "12345678901234567890123="; | |
| 19 const char kInvalidShortDeviceId[] = "12345678901234567890"; | |
| 20 const char kInvalidCharacterDeviceId[] = "123456789012345678901*=="; | |
| 21 // A base64 string should have a length of a multiple of 4. | |
| 22 const char kInvalidLengthDeviceId[] = "123456789012345678901"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 TEST(BluetoothDeviceIdTest, DefaulConstructor) { | |
| 27 BluetoothDeviceId default_id1; | |
| 28 BluetoothDeviceId default_id2; | |
| 29 BluetoothDeviceId valid_id(kValidDeviceId1); | |
| 30 | |
| 31 ASSERT_TRUE(BluetoothDeviceId::IsValid(valid_id.str())); | |
|
Jeffrey Yasskin
2016/06/03 17:22:05
Also EXPECT_FALSE(BluetoothDeviceId::IsValid(defau
ortuno
2016/06/06 22:23:00
IsValid takes a string and we can't get a string b
Jeffrey Yasskin
2016/06/06 23:44:02
Oh, right. What you've done looks good.
| |
| 32 | |
| 33 EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == default_id2; }(), ""); | |
| 34 EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != default_id2; }(), ""); | |
| 35 | |
| 36 EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == valid_id; }(), ""); | |
| 37 EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id == default_id1; }(), ""); | |
| 38 | |
| 39 EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != valid_id; }(), ""); | |
| 40 EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id != default_id1; }(), ""); | |
| 41 } | |
| 42 | |
| 43 TEST(BluetoothDeviceIdTest, StrConstructor) { | |
|
Jeffrey Yasskin
2016/06/03 17:22:05
Assert on == and != too.
ortuno
2016/06/06 22:23:00
Do you mean add statements that compare the object
Jeffrey Yasskin
2016/06/06 23:44:02
Yep, that. Thanks.
| |
| 44 BluetoothDeviceId(kValidDeviceId1); | |
| 45 BluetoothDeviceId(kValidDeviceId2); | |
| 46 // Above call should not crash. | |
| 47 EXPECT_TRUE(true); | |
|
Jeffrey Yasskin
2016/06/03 17:22:05
This doesn't add anything: the test will fail if i
ortuno
2016/06/06 22:23:00
Done.
| |
| 48 | |
| 49 EXPECT_DEATH_IF_SUPPORTED(BluetoothDeviceId(""), ""); | |
| 50 EXPECT_DEATH_IF_SUPPORTED( | |
| 51 [&]() { return BluetoothDeviceId(kInvalidLongDeviceId); }(), ""); | |
| 52 EXPECT_DEATH_IF_SUPPORTED( | |
| 53 [&]() { return BluetoothDeviceId(kInvalidShortDeviceId); }(), ""); | |
| 54 EXPECT_DEATH_IF_SUPPORTED( | |
| 55 [&]() { return BluetoothDeviceId(kInvalidCharacterDeviceId); }(), ""); | |
| 56 EXPECT_DEATH_IF_SUPPORTED( | |
| 57 [&]() { return BluetoothDeviceId(kInvalidLengthDeviceId); }(), ""); | |
| 58 } | |
| 59 | |
| 60 TEST(BluetoothDeviceIdTest, IsValid_Valid) { | |
| 61 EXPECT_TRUE(BluetoothDeviceId::IsValid(kValidDeviceId1)); | |
| 62 EXPECT_TRUE(BluetoothDeviceId::IsValid(kValidDeviceId2)); | |
| 63 } | |
| 64 | |
| 65 TEST(BluetoothDeviceIdTest, IsValid_Invalid) { | |
| 66 EXPECT_FALSE(BluetoothDeviceId::IsValid("")); | |
| 67 EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidLongDeviceId)); | |
| 68 EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidShortDeviceId)); | |
| 69 EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidCharacterDeviceId)); | |
| 70 EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidLengthDeviceId)); | |
| 71 } | |
| 72 | |
| 73 TEST(BluetoothDeviceIdTest, Create) { | |
| 74 // Tests that Create generates a valid Device Id. | |
| 75 EXPECT_TRUE(BluetoothDeviceId::IsValid(BluetoothDeviceId::Create().str())) | |
| 76 << "This should never fail."; | |
|
Jeffrey Yasskin
2016/06/03 17:22:05
That's implied by it being in a test. :) Do you me
ortuno
2016/06/06 22:23:00
Hmm actually the opposite haha. I'm afraid that si
Jeffrey Yasskin
2016/06/06 23:44:02
Say something like that in the failure message.
ortuno
2016/06/24 17:39:43
After some more thinking I decided to remove the m
| |
| 77 } | |
| OLD | NEW |