| Index: content/common/bluetooth/bluetooth_device_id_unittest.cc
|
| diff --git a/content/common/bluetooth/bluetooth_device_id_unittest.cc b/content/common/bluetooth/bluetooth_device_id_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ffafb7c7962dc0b725a7297ac950a12a3055305a
|
| --- /dev/null
|
| +++ b/content/common/bluetooth/bluetooth_device_id_unittest.cc
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/common/bluetooth/bluetooth_device_id.h"
|
| +
|
| +#include "base/base64.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "crypto/random.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::BluetoothDeviceId;
|
| +
|
| +namespace {
|
| +
|
| +const char kValidDeviceId1[] = "1234567890123456789012==";
|
| +const char kValidDeviceId2[] = "AbCdEfGhIjKlMnOpQrSt+/==";
|
| +const char kInvalidLongDeviceId[] = "12345678901234567890123=";
|
| +const char kInvalidShortDeviceId[] = "12345678901234567890";
|
| +const char kInvalidCharacterDeviceId[] = "123456789012345678901*==";
|
| +// A base64 string should have a length of a multiple of 4.
|
| +const char kInvalidLengthDeviceId[] = "123456789012345678901";
|
| +
|
| +} // namespace
|
| +
|
| +TEST(BluetoothDeviceIdTest, DefaulConstructor) {
|
| + BluetoothDeviceId default_id1;
|
| + BluetoothDeviceId default_id2;
|
| + BluetoothDeviceId valid_id(kValidDeviceId1);
|
| +
|
| + ASSERT_DEATH_IF_SUPPORTED(default_id1.str(), "");
|
| + ASSERT_DEATH_IF_SUPPORTED(default_id2.str(), "");
|
| + ASSERT_TRUE(BluetoothDeviceId::IsValid(valid_id.str()));
|
| +
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == default_id2; }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != default_id2; }(), "");
|
| +
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 == valid_id; }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id == default_id1; }(), "");
|
| +
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return default_id1 != valid_id; }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED([&]() { return valid_id != default_id1; }(), "");
|
| +}
|
| +
|
| +TEST(BluetoothDeviceIdTest, StrConstructor) {
|
| + BluetoothDeviceId(kValidDeviceId1);
|
| + BluetoothDeviceId(kValidDeviceId2);
|
| +
|
| + EXPECT_TRUE(kValidDeviceId1 == kValidDeviceId1);
|
| + EXPECT_TRUE(kValidDeviceId2 == kValidDeviceId2);
|
| +
|
| + EXPECT_TRUE(kValidDeviceId1 != kValidDeviceId2);
|
| +
|
| + EXPECT_DEATH_IF_SUPPORTED(BluetoothDeviceId(""), "");
|
| + EXPECT_DEATH_IF_SUPPORTED(
|
| + [&]() { return BluetoothDeviceId(kInvalidLongDeviceId); }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED(
|
| + [&]() { return BluetoothDeviceId(kInvalidShortDeviceId); }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED(
|
| + [&]() { return BluetoothDeviceId(kInvalidCharacterDeviceId); }(), "");
|
| + EXPECT_DEATH_IF_SUPPORTED(
|
| + [&]() { return BluetoothDeviceId(kInvalidLengthDeviceId); }(), "");
|
| +}
|
| +
|
| +TEST(BluetoothDeviceIdTest, IsValid_Valid) {
|
| + EXPECT_TRUE(BluetoothDeviceId::IsValid(kValidDeviceId1));
|
| + EXPECT_TRUE(BluetoothDeviceId::IsValid(kValidDeviceId2));
|
| +}
|
| +
|
| +TEST(BluetoothDeviceIdTest, IsValid_Invalid) {
|
| + EXPECT_FALSE(BluetoothDeviceId::IsValid(""));
|
| + EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidLongDeviceId));
|
| + EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidShortDeviceId));
|
| + EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidCharacterDeviceId));
|
| + EXPECT_FALSE(BluetoothDeviceId::IsValid(kInvalidLengthDeviceId));
|
| +}
|
| +
|
| +TEST(BluetoothDeviceIdTest, Create) {
|
| + // Tests that Create generates a valid Device Id.
|
| + EXPECT_TRUE(BluetoothDeviceId::IsValid(BluetoothDeviceId::Create().str()))
|
| + << "This should never fail.";
|
| +}
|
|
|