• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3#
4#  Use of this source code is governed by a BSD-style license
5#  that can be found in the LICENSE file in the root of the source
6#  tree. An additional intellectual property rights grant can be found
7#  in the file PATENTS.  All contributing project authors may
8#  be found in the AUTHORS file in the root of the source tree.
9
10"""Run the tests with
11
12      python rtp_analyzer_test.py
13or
14      python3 rtp_analyzer_test.py
15"""
16
17import collections
18import unittest
19
20MISSING_NUMPY = False  # pylint: disable=invalid-name
21try:
22  import numpy
23  import rtp_analyzer
24except ImportError:
25  MISSING_NUMPY = True
26
27FakePoint = collections.namedtuple("FakePoint",
28                                   ["real_send_time_ms", "absdelay"])
29
30
31class TestDelay(unittest.TestCase):
32  def AssertMaskEqual(self, masked_array, data, mask):
33    self.assertEqual(list(masked_array.data), data)
34
35    if isinstance(masked_array.mask, numpy.bool_):
36      array_mask = masked_array.mask
37    else:
38      array_mask = list(masked_array.mask)
39    self.assertEqual(array_mask, mask)
40
41  def testCalculateDelaySimple(self):
42    points = [FakePoint(0, 0), FakePoint(1, 0)]
43    mask = rtp_analyzer.CalculateDelay(0, 1, 1, points)
44    self.AssertMaskEqual(mask, [0, 0], False)
45
46  def testCalculateDelayMissing(self):
47    points = [FakePoint(0, 0), FakePoint(2, 0)]
48    mask = rtp_analyzer.CalculateDelay(0, 2, 1, points)
49    self.AssertMaskEqual(mask, [0, -1, 0], [False, True, False])
50
51  def testCalculateDelayBorders(self):
52    points = [FakePoint(0, 0), FakePoint(2, 0)]
53    mask = rtp_analyzer.CalculateDelay(0, 3, 2, points)
54    self.AssertMaskEqual(mask, [0, 0, -1], [False, False, True])
55
56
57if __name__ == "__main__":
58  if MISSING_NUMPY:
59    print "Missing numpy, skipping test."
60  else:
61    unittest.main()
62