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

Side by Side Diff: device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc

Issue 2287023002: device/bluetooth: Fix = operator and copy constructor of BluetoothServiceAttributeValueBlueZ (Closed)
Patch Set: change bug number Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <string>
8 9
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace bluez { 14 namespace bluez {
14 15
15 namespace { 16 namespace {
16 17
17 using Type = BluetoothServiceAttributeValueBlueZ::Type; 18 using Type = BluetoothServiceAttributeValueBlueZ::Type;
(...skipping 17 matching lines...) Expand all
35 EXPECT_EQ(val, static_cast<uint32_t>(i_val)); 36 EXPECT_EQ(val, static_cast<uint32_t>(i_val));
36 } 37 }
37 38
38 // MakeUnique can't use a initializer list directly, since it can't derive the 39 // MakeUnique can't use a initializer list directly, since it can't derive the
39 // template type for it unless we explicitly use std::initializer_list({...}) 40 // template type for it unless we explicitly use std::initializer_list({...})
40 // in the call. This function helps us avoid all that ugly syntax. 41 // in the call. This function helps us avoid all that ugly syntax.
41 std::unique_ptr<Sequence> MakeSequence( 42 std::unique_ptr<Sequence> MakeSequence(
42 const std::initializer_list<BluetoothServiceAttributeValueBlueZ> list) { 43 const std::initializer_list<BluetoothServiceAttributeValueBlueZ> list) {
43 return base::MakeUnique<Sequence>(list); 44 return base::MakeUnique<Sequence>(list);
44 } 45 }
45 } 46
47 } // namespace
46 48
47 TEST(BluetoothServiceAttributeBlueZTest, BasicValue) { 49 TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
48 BluetoothServiceAttributeValueBlueZ value1( 50 BluetoothServiceAttributeValueBlueZ value1(
49 Type::UUID, 16, base::MakeUnique<base::StringValue>(kServiceUuid)); 51 Type::UUID, 16, base::MakeUnique<base::StringValue>(kServiceUuid));
50 BluetoothServiceAttributeValueBlueZ value2 = value1; 52 BluetoothServiceAttributeValueBlueZ value2 = value1;
51 53
52 CheckUuidValue(value2, kServiceUuid); 54 CheckUuidValue(value2, kServiceUuid);
53 } 55 }
54 56
55 TEST(BluetoothServiceAttributeBlueZTest, Sequence) { 57 TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 115
114 // Check value3 again. 116 // Check value3 again.
115 EXPECT_EQ(2u, v4[0].size()); 117 EXPECT_EQ(2u, v4[0].size());
116 EXPECT_EQ(Type::SEQUENCE, v4[0].type()); 118 EXPECT_EQ(Type::SEQUENCE, v4[0].type());
117 const Sequence& v31 = v4[0].sequence(); 119 const Sequence& v31 = v4[0].sequence();
118 EXPECT_EQ(2u, v31.size()); 120 EXPECT_EQ(2u, v31.size());
119 CheckUuidValue(v31[0], kServiceUuid); 121 CheckUuidValue(v31[0], kServiceUuid);
120 CheckIntValue(v31[1], 0x1337); 122 CheckIntValue(v31[1], 0x1337);
121 } 123 }
122 124
125 TEST(BluetoothServiceAttributeBlueZTest, CopyAssignment) {
126 BluetoothServiceAttributeValueBlueZ value1(
127 Type::UUID, 16, base::MakeUnique<base::StringValue>(kServiceUuid));
128 BluetoothServiceAttributeValueBlueZ value2(
129 Type::INT, 4, base::MakeUnique<base::FundamentalValue>(0x1337));
130 BluetoothServiceAttributeValueBlueZ value3(
131 Type::INT, 4, base::MakeUnique<base::FundamentalValue>(0x7331));
132 std::unique_ptr<BluetoothServiceAttributeValueBlueZ> value4(
133 new BluetoothServiceAttributeValueBlueZ(
134 MakeSequence({value1, value2, value3})));
135
136 BluetoothServiceAttributeValueBlueZ value;
137
138 value = *value4;
139 value4 = nullptr;
140
141 EXPECT_EQ(3u, value.size());
142 const Sequence& s = value.sequence();
143 EXPECT_EQ(3u, s.size());
144
145 CheckUuidValue(s[0], kServiceUuid);
146 CheckIntValue(s[2], 0x7331);
147 CheckIntValue(s[1], 0x1337);
148 }
149
123 } // namespace bluez 150 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698