1 // Copyright 2014 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.
5 #include "components/copresence/handlers/audio/audio_directive_list.h"
8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gmock/include/gmock/gmock.h"
12 using testing::IsNull
;
14 namespace copresence
{
16 static const int64 kTtl
= 10;
18 const Directive
CreateDirective(int64 ttl
) {
20 directive
.set_ttl_millis(ttl
);
24 class AudioDirectiveListTest
: public testing::Test
{
26 AudioDirectiveListTest() : directive_list_(new AudioDirectiveList
) {}
29 base::MessageLoop message_loop_
;
30 scoped_ptr
<AudioDirectiveList
> directive_list_
;
33 TEST_F(AudioDirectiveListTest
, Basic
) {
34 EXPECT_THAT(directive_list_
->GetActiveDirective(), IsNull());
36 directive_list_
->AddDirective("op_id1", CreateDirective(kTtl
));
37 directive_list_
->AddDirective("op_id2", CreateDirective(kTtl
* 3));
38 directive_list_
->AddDirective("op_id3", CreateDirective(kTtl
* 2));
39 EXPECT_EQ("op_id2", directive_list_
->GetActiveDirective()->op_id
);
41 directive_list_
->RemoveDirective("op_id2");
42 EXPECT_EQ("op_id3", directive_list_
->GetActiveDirective()->op_id
);
45 TEST_F(AudioDirectiveListTest
, AddDirectiveMultiple
) {
46 directive_list_
->AddDirective("op_id1", CreateDirective(kTtl
));
47 directive_list_
->AddDirective("op_id2", CreateDirective(kTtl
* 2));
48 directive_list_
->AddDirective("op_id3", CreateDirective(kTtl
* 3 * 2));
49 directive_list_
->AddDirective("op_id3", CreateDirective(kTtl
* 3 * 3));
50 directive_list_
->AddDirective("op_id4", CreateDirective(kTtl
* 4));
52 EXPECT_EQ("op_id3", directive_list_
->GetActiveDirective()->op_id
);
53 directive_list_
->RemoveDirective("op_id3");
54 EXPECT_EQ("op_id4", directive_list_
->GetActiveDirective()->op_id
);
55 directive_list_
->RemoveDirective("op_id4");
56 EXPECT_EQ("op_id2", directive_list_
->GetActiveDirective()->op_id
);
57 directive_list_
->RemoveDirective("op_id2");
58 EXPECT_EQ("op_id1", directive_list_
->GetActiveDirective()->op_id
);
59 directive_list_
->RemoveDirective("op_id1");
60 EXPECT_THAT(directive_list_
->GetActiveDirective(), IsNull());
63 TEST_F(AudioDirectiveListTest
, RemoveDirectiveMultiple
) {
64 directive_list_
->AddDirective("op_id1", CreateDirective(kTtl
));
65 directive_list_
->AddDirective("op_id2", CreateDirective(kTtl
* 2));
66 directive_list_
->AddDirective("op_id3", CreateDirective(kTtl
* 3));
67 directive_list_
->AddDirective("op_id4", CreateDirective(kTtl
* 4));
69 EXPECT_EQ("op_id4", directive_list_
->GetActiveDirective()->op_id
);
70 directive_list_
->RemoveDirective("op_id4");
71 EXPECT_EQ("op_id3", directive_list_
->GetActiveDirective()->op_id
);
72 directive_list_
->RemoveDirective("op_id3");
73 directive_list_
->RemoveDirective("op_id3");
74 directive_list_
->RemoveDirective("op_id3");
75 EXPECT_EQ("op_id2", directive_list_
->GetActiveDirective()->op_id
);
76 directive_list_
->RemoveDirective("op_id2");
77 EXPECT_EQ("op_id1", directive_list_
->GetActiveDirective()->op_id
);
78 directive_list_
->RemoveDirective("op_id1");
79 EXPECT_THAT(directive_list_
->GetActiveDirective(), IsNull());
82 } // namespace copresence