register_notification_packet_test.cc revision 8f7377353db29efe0a506123deec03d70935957a
1/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include "avrcp_test_packets.h"
20#include "packet_test_helper.h"
21#include "register_notification_packet.h"
22
23namespace bluetooth {
24namespace avrcp {
25
26using TestRegNotifReqPacket = TestPacketType<RegisterNotificationRequest>;
27
28TEST(RegisterNotificationRequestTest, getterTest) {
29  auto test_packet =
30      TestRegNotifReqPacket::Make(register_play_status_notification);
31
32  ASSERT_EQ(test_packet->GetEventRegistered(), Event::PLAYBACK_STATUS_CHANGED);
33  ASSERT_EQ(test_packet->GetInterval(), 5u);
34}
35
36TEST(RegisterNotificationRequestTest, validTest) {
37  auto test_packet =
38      TestRegNotifReqPacket::Make(register_play_status_notification);
39  ASSERT_TRUE(test_packet->IsValid());
40}
41
42TEST(RegisterNotificationRequestTest, invalidTest) {
43  std::vector<uint8_t> packet_copy = register_play_status_notification;
44  packet_copy.push_back(0x00);
45  auto test_packet = TestRegNotifReqPacket::Make(packet_copy);
46  ASSERT_FALSE(test_packet->IsValid());
47
48  std::vector<uint8_t> short_packet = {0, 1, 2, 3, 4};
49  test_packet = TestRegNotifReqPacket::Make(short_packet);
50  ASSERT_FALSE(test_packet->IsValid());
51}
52
53TEST(RegisterNotificationResponseTest, playStatusBuilderTest) {
54  auto builder = RegisterNotificationResponseBuilder::MakePlaybackStatusBuilder(
55      true, 0x00);
56  ASSERT_EQ(builder->size(), interim_play_status_notification.size());
57  auto test_packet = TestRegNotifReqPacket::Make();
58  builder->Serialize(test_packet);
59  ASSERT_EQ(test_packet->GetData(), interim_play_status_notification);
60}
61
62TEST(RegisterNotificationResponseTest, trackChangedBuilderTest) {
63  auto builder = RegisterNotificationResponseBuilder::MakeTrackChangedBuilder(
64      true, 0x0000000000000000);
65  ASSERT_EQ(builder->size(), interim_track_changed_notification.size());
66  auto test_packet = TestRegNotifReqPacket::Make();
67  builder->Serialize(test_packet);
68  ASSERT_EQ(test_packet->GetData(), interim_track_changed_notification);
69}
70
71TEST(RegisterNotificationResponseTest, playPositionBuilderTest) {
72  auto builder =
73      RegisterNotificationResponseBuilder::MakePlaybackPositionBuilder(
74          false, 0x00000000);
75  ASSERT_EQ(builder->size(), changed_play_pos_notification.size());
76  auto test_packet = TestRegNotifReqPacket::Make();
77  builder->Serialize(test_packet);
78  ASSERT_EQ(test_packet->GetData(), changed_play_pos_notification);
79}
80
81}  // namespace avrcp
82}  // namespace bluetooth