xref: /aosp_15_r20/external/webrtc/rtc_tools/py_event_log_analyzer/rtp_analyzer_test.py (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1#!/usr/bin/env python3
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"""Run the tests with
10
11      python rtp_analyzer_test.py
12or
13      python3 rtp_analyzer_test.py
14"""
15
16from __future__ import absolute_import
17from __future__ import print_function
18import collections
19import unittest
20
21MISSING_NUMPY = False  # pylint: disable=invalid-name
22try:
23  import numpy
24  import rtp_analyzer
25except ImportError:
26  MISSING_NUMPY = True
27
28FakePoint = collections.namedtuple("FakePoint",
29                                   ["real_send_time_ms", "absdelay"])
30
31
32class TestDelay(unittest.TestCase):
33  def AssertMaskEqual(self, masked_array, data, mask):
34    self.assertEqual(list(masked_array.data), data)
35
36    if isinstance(masked_array.mask, numpy.bool_):
37      array_mask = masked_array.mask
38    else:
39      array_mask = list(masked_array.mask)
40    self.assertEqual(array_mask, mask)
41
42  def testCalculateDelaySimple(self):
43    points = [FakePoint(0, 0), FakePoint(1, 0)]
44    mask = rtp_analyzer.CalculateDelay(0, 1, 1, points)
45    self.AssertMaskEqual(mask, [0, 0], False)
46
47  def testCalculateDelayMissing(self):
48    points = [FakePoint(0, 0), FakePoint(2, 0)]
49    mask = rtp_analyzer.CalculateDelay(0, 2, 1, points)
50    self.AssertMaskEqual(mask, [0, -1, 0], [False, True, False])
51
52  def testCalculateDelayBorders(self):
53    points = [FakePoint(0, 0), FakePoint(2, 0)]
54    mask = rtp_analyzer.CalculateDelay(0, 3, 2, points)
55    self.AssertMaskEqual(mask, [0, 0, -1], [False, False, True])
56
57
58if __name__ == "__main__":
59  if MISSING_NUMPY:
60    print("Missing numpy, skipping test.")
61  else:
62    unittest.main()
63