- add sources.
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_service_record_win_unittest.cc
1 // Copyright (c) 2013 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 "base/basictypes.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "device/bluetooth/bluetooth_service_record_win.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 const char kTestNoRfcommSdpBytes[] =
13     "35510900000a00010001090001350319110a09000435103506190100090019350619001909"
14     "010209000535031910020900093508350619110d090102090100250c417564696f20536f75"
15     "726365090311090001";
16 const int kTestNoRfcommSdpBytesSize = sizeof(kTestNoRfcommSdpBytes) / 2;
17 const char kTestNoRfcommSdpUuid[] = "0000110a-0000-1000-8000-00805f9b34fb";
18
19 const char kTestRfcommSdpBytes[] =
20     "354b0900000a000100030900013506191112191203090004350c3503190100350519000308"
21     "0b090005350319100209000935083506191108090100090100250d566f6963652047617465"
22     "776179";
23 const int kTestRfcommSdpBytesSize = sizeof(kTestRfcommSdpBytes) / 2;
24 const char kTestRfcommSdpUuid[] = "00001112-0000-1000-8000-00805f9b34fb";
25 const int kTestRfcommChannel = 11;
26
27 }  // namespace
28
29 namespace device {
30
31 class BluetoothServiceRecordWinTest : public testing::Test {
32  protected:
33   void ConvertSdpBytes(const char* sdp_hex_char, uint8* sdp_bytes_array) {
34     std::vector<uint8> sdp_bytes_vector;
35     base::HexStringToBytes(sdp_hex_char, &sdp_bytes_vector);
36     std::copy(sdp_bytes_vector.begin(),
37               sdp_bytes_vector.end(),
38               sdp_bytes_array);
39   }
40 };
41
42 TEST_F(BluetoothServiceRecordWinTest, NoRfcommSdp) {
43   uint8 sdp_bytes_array[kTestNoRfcommSdpBytesSize];
44   ConvertSdpBytes(kTestNoRfcommSdpBytes, sdp_bytes_array);
45   BluetoothServiceRecordWin service_record("NoRfcommSdp",
46                                            "01:02:03:0A:10:A0",
47                                            kTestNoRfcommSdpBytesSize,
48                                            sdp_bytes_array);
49   EXPECT_STREQ(kTestNoRfcommSdpUuid, service_record.uuid().c_str());
50   EXPECT_FALSE(service_record.SupportsRfcomm());
51 }
52
53
54 TEST_F(BluetoothServiceRecordWinTest, RfcommSdp) {
55   uint8 sdp_bytes_array[kTestRfcommSdpBytesSize];
56   ConvertSdpBytes(kTestRfcommSdpBytes, sdp_bytes_array);
57   BluetoothServiceRecordWin service_record("RfcommSdp",
58                                            "01:02:03:0A:10:A0",
59                                            kTestRfcommSdpBytesSize,
60                                            sdp_bytes_array);
61   EXPECT_STREQ(kTestRfcommSdpUuid, service_record.uuid().c_str());
62   EXPECT_TRUE(service_record.SupportsRfcomm());
63   EXPECT_EQ(kTestRfcommChannel, service_record.rfcomm_channel());
64 }
65
66 TEST_F(BluetoothServiceRecordWinTest, BthAddr) {
67   uint8 sdp_bytes_array[kTestRfcommSdpBytesSize];
68   ConvertSdpBytes(kTestRfcommSdpBytes, sdp_bytes_array);
69   BluetoothServiceRecordWin service_record("Sdp",
70                                            "01:02:03:0A:10:A0",
71                                            kTestRfcommSdpBytesSize,
72                                            sdp_bytes_array);
73   EXPECT_EQ(1108152553632, service_record.bth_addr());
74 }
75
76 }  // namespace device