Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Unified Diff: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator_unittest.cc

Issue 2031953003: Weave Packet Generator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uWeave Packet Generator Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator_unittest.cc
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator_unittest.cc b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2fcb293b417765784b98777017817c6c5dab8229
--- /dev/null
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator_unittest.cc
@@ -0,0 +1,131 @@
+// 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 "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h"
+
+#include <algorithm>
+#include <string>
+
+#include "base/logging.h"
+#include "base/macros.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace proximity_auth {
+
+class ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest
+ : public testing::Test {
+ protected:
+ ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(
+ ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest);
+};
+
+TEST_F(ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest,
+ CreateConnectionRequestTest) {
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> generator =
+ (new BluetoothLowEnergyWeavePacketGenerator::Factory())->NewInstance();
+
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator::Packet> packet =
+ generator->CreateConnectionRequest();
+
+ std::vector<uint8_t> expected(20, 0);
+ expected[0] = 0x80;
+ expected[2] = 1;
+ expected[4] = 1;
+
+ EXPECT_EQ(expected, *packet);
+}
+
+TEST_F(ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest,
+ CreateConnectionResponseTest) {
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> generator =
+ (new BluetoothLowEnergyWeavePacketGenerator::Factory())->NewInstance();
+
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator::Packet> packet =
+ generator->CreateConnectionResponse();
+
+ std::vector<uint8_t> expected(20, 0);
+ expected[0] = 0x81;
+ expected[2] = 1;
+ expected[4] = 20;
+
+ EXPECT_EQ(expected, *packet);
+}
+
+TEST_F(ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest,
+ CreateConnectionCloseTest) {
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> generator =
+ (new BluetoothLowEnergyWeavePacketGenerator::Factory())->NewInstance();
+
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator::Packet> packet =
+ generator->CreateConnectionClose(BluetoothLowEnergyWeavePacketGenerator::
+ ReasonForClose::APPLICATION_ERROR);
+
+ std::vector<uint8_t> expected(20, 0);
+ expected[0] = 0x82;
+ expected[2] = 0x80;
+
+ EXPECT_EQ(expected, *packet);
+}
+
+TEST_F(ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest,
+ EncodeDataMessageTest) {
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> generator =
+ (new BluetoothLowEnergyWeavePacketGenerator::Factory())->NewInstance();
+
+ std::string data = "abcdef";
+
+ generator->SetDataPacketSize(4);
+
+ std::unique_ptr<std::vector<BluetoothLowEnergyWeavePacketGenerator::Packet>>
+ packets = generator->EncodeDataMessage(data);
+
+ std::vector<std::vector<uint8_t>> expected(3);
+
+ expected[0].push_back(0x08);
+ expected[0].push_back('a');
+ expected[0].push_back('b');
+ expected[0].push_back('c');
+
+ expected[1].push_back(0x10);
+ expected[1].push_back('d');
+ expected[1].push_back('e');
+ expected[1].push_back('f');
+
+ expected[2].push_back(0x24);
+ expected[2].push_back('\0');
+
+ EXPECT_EQ(expected, *packets);
+}
+
+TEST_F(ProximityAuthBluetoothLowEnergyWeavePacketGeneratorTest,
+ PacketCounterTest) {
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> generator =
+ (new BluetoothLowEnergyWeavePacketGenerator::Factory())->NewInstance();
+
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator::Packet> packet =
+ generator->CreateConnectionRequest();
+
+ EXPECT_EQ(0x80, packet->at(0));
+
+ packet = generator->CreateConnectionResponse();
+
+ EXPECT_EQ(0x91, packet->at(0));
+
+ std::string data = "a";
+ std::unique_ptr<std::vector<BluetoothLowEnergyWeavePacketGenerator::Packet>>
+ packets = generator->EncodeDataMessage(data);
+
+ EXPECT_EQ(0x2C, packets->at(0)[0]);
+
+ packet = generator->CreateConnectionClose(
+ BluetoothLowEnergyWeavePacketGenerator::ReasonForClose::UNKNOWN_ERROR);
+
+ EXPECT_EQ(0xB2, packet->at(0));
+}
+
+} // namespace proximity_auth

Powered by Google App Engine
This is Rietveld 408576698