mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Roll forward to cl/328359974
Change-Id: If2b57ecc852aecf7dea454648f485fd7c08e72a9
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#include "platform_v2/base/bluetooth_utils.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
constexpr absl::string_view kBluetoothMacAddress{"00:00:E6:88:64:13"};
|
||||
constexpr char kBluetoothMacAddressBytes[] = {0x00, 0x00, 0xe6,
|
||||
0x88, 0x64, 0x13};
|
||||
|
||||
TEST(BluetoothUtilsTest, ToStringWorks) {
|
||||
ByteArray bt_mac_address_bytes{
|
||||
kBluetoothMacAddressBytes, sizeof(kBluetoothMacAddressBytes)};
|
||||
|
||||
auto bt_mac_address = BluetoothUtils::ToString(bt_mac_address_bytes);
|
||||
|
||||
EXPECT_EQ(kBluetoothMacAddress, bt_mac_address);
|
||||
}
|
||||
|
||||
TEST(BluetoothUtilsTest, FromStringWorks) {
|
||||
ByteArray bt_mac_address_bytes{
|
||||
kBluetoothMacAddressBytes, sizeof(kBluetoothMacAddressBytes)};
|
||||
|
||||
auto bt_mac_address_bytes_result =
|
||||
BluetoothUtils::FromString(kBluetoothMacAddress);
|
||||
|
||||
EXPECT_EQ(bt_mac_address_bytes, bt_mac_address_bytes_result);
|
||||
}
|
||||
|
||||
TEST(BluetoothUtilsTest, InvalidBytesReturnsEmptyString) {
|
||||
std::string string_result;
|
||||
|
||||
char bad_bt_mac_address_1[] = {0x02, 0x20, 0x00};
|
||||
ByteArray bad_bt_mac_address_bytes_1{bad_bt_mac_address_1,
|
||||
sizeof(bad_bt_mac_address_1)};
|
||||
string_result = BluetoothUtils::ToString(bad_bt_mac_address_bytes_1);
|
||||
EXPECT_TRUE(string_result.empty());
|
||||
|
||||
char bad_bt_mac_address_2[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
ByteArray bad_bt_mac_address_bytes_2{bad_bt_mac_address_2,
|
||||
sizeof(bad_bt_mac_address_2)};
|
||||
string_result = BluetoothUtils::ToString(bad_bt_mac_address_bytes_2);
|
||||
EXPECT_TRUE(string_result.empty());
|
||||
|
||||
char bad_bt_mac_address_3[] = {0x11, 0x22, 0x33, 0x44, 0x55,
|
||||
0x66, 0x77, 0x88, 0x99};
|
||||
ByteArray bad_bt_mac_address_bytes_3{bad_bt_mac_address_3,
|
||||
sizeof(bad_bt_mac_address_3)};
|
||||
string_result = BluetoothUtils::ToString(bad_bt_mac_address_bytes_3);
|
||||
EXPECT_TRUE(string_result.empty());
|
||||
}
|
||||
|
||||
TEST(BluetoothUtilsTest, InvalidStringReturnsEmptyByteArray) {
|
||||
ByteArray bytes_result;
|
||||
|
||||
std::string bad_bt_mac_address_1 = "022:00";
|
||||
bytes_result = BluetoothUtils::FromString(bad_bt_mac_address_1);
|
||||
EXPECT_TRUE(bytes_result.Empty());
|
||||
|
||||
std::string bad_bt_mac_address_2 = "22:00:11:33:77:aa::bb::99";
|
||||
bytes_result = BluetoothUtils::FromString(bad_bt_mac_address_2);
|
||||
EXPECT_TRUE(bytes_result.Empty());
|
||||
|
||||
std::string bad_bt_mac_address_3 = "00:00:00:00:00:00";
|
||||
bytes_result = BluetoothUtils::FromString(bad_bt_mac_address_3);
|
||||
EXPECT_TRUE(bytes_result.Empty());
|
||||
|
||||
std::string bad_bt_mac_address_4 = "BLUETOOTHCHIP";
|
||||
bytes_result = BluetoothUtils::FromString(bad_bt_mac_address_4);
|
||||
EXPECT_TRUE(bytes_result.Empty());
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
Reference in New Issue
Block a user