• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 "cast/streaming/ssrc.h"
6 
7 #include <vector>
8 
9 #include "gtest/gtest.h"
10 #include "util/std_util.h"
11 
12 namespace openscreen {
13 namespace cast {
14 namespace {
15 
TEST(SsrcTest,GeneratesUniqueAndPrioritizedSsrcs)16 TEST(SsrcTest, GeneratesUniqueAndPrioritizedSsrcs) {
17   std::vector<Ssrc> priority_ssrcs;
18   for (int i = 0; i < 3; ++i) {
19     priority_ssrcs.push_back(GenerateSsrc(true));
20   }
21 
22   // Three different higher-priority SSRCs should have been generated.
23   SortAndDedupeElements(&priority_ssrcs);
24   EXPECT_EQ(3u, priority_ssrcs.size());
25 
26   std::vector<Ssrc> normal_ssrcs;
27   for (int i = 0; i < 3; ++i) {
28     normal_ssrcs.push_back(GenerateSsrc(false));
29   }
30 
31   // Three different normal SSRCs should have been generated.
32   SortAndDedupeElements(&normal_ssrcs);
33   EXPECT_EQ(3u, normal_ssrcs.size());
34 
35   // All six SSRCs, together, should be unique.
36   std::vector<Ssrc> all_ssrcs;
37   all_ssrcs.insert(all_ssrcs.end(), priority_ssrcs.begin(),
38                    priority_ssrcs.end());
39   all_ssrcs.insert(all_ssrcs.end(), normal_ssrcs.begin(), normal_ssrcs.end());
40   SortAndDedupeElements(&all_ssrcs);
41   EXPECT_EQ(6u, all_ssrcs.size());
42 
43   // ComparePriority() should return values indicating the appropriate
44   // prioritization.
45   for (int i = 0; i < 3; ++i) {
46     for (int j = 0; j < 3; ++j) {
47       EXPECT_LT(ComparePriority(priority_ssrcs[i], normal_ssrcs[j]), 0);
48       EXPECT_GT(ComparePriority(normal_ssrcs[i], priority_ssrcs[j]), 0);
49     }
50   }
51 }
52 
53 }  // namespace
54 }  // namespace cast
55 }  // namespace openscreen
56