Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(884)

Side by Side Diff: media/cast/net/frame_id_wrap_helper_test.cc

Issue 458313003: Smarter algorithm for extending 8-bit frame IDs to 32-bit frame IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch to unsigned arithmetics Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/net/cast_transport_defines.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 #include "media/cast/cast_defines.h"
6 #include "media/cast/net/cast_transport_defines.h" 7 #include "media/cast/net/cast_transport_defines.h"
7 8
8 namespace media { 9 namespace media {
9 namespace cast { 10 namespace cast {
10 11
11 class FrameIdWrapHelperTest : public ::testing::Test { 12 class FrameIdWrapHelperTest : public ::testing::Test {
12 protected: 13 protected:
13 FrameIdWrapHelperTest() {} 14 FrameIdWrapHelperTest() {}
14 virtual ~FrameIdWrapHelperTest() {} 15 virtual ~FrameIdWrapHelperTest() {}
15 16
17 void RunOneTest(uint32 starting_point, int iterations) {
18 const int window_size = 127;
19 uint32 window_base = starting_point;
20 frame_id_wrap_helper_.largest_frame_id_seen_ = starting_point;
21 for (int i = 0; i < iterations; i++) {
22 uint32 largest_frame_id_seen =
23 frame_id_wrap_helper_.largest_frame_id_seen_;
24 int offset = rand() % window_size;
25 uint32 frame_id = window_base + offset;
26 uint32 mapped_frame_id =
27 frame_id_wrap_helper_.MapTo32bitsFrameId(frame_id & 0xff);
28 EXPECT_EQ(frame_id, mapped_frame_id)
29 << " Largest ID seen: " << largest_frame_id_seen
30 << " Window base: " << window_base
31 << " Offset: " << offset;
32 window_base = frame_id;
33 }
34 }
35
16 FrameIdWrapHelper frame_id_wrap_helper_; 36 FrameIdWrapHelper frame_id_wrap_helper_;
17 37
18 DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelperTest); 38 DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelperTest);
19 }; 39 };
20 40
21 TEST_F(FrameIdWrapHelperTest, FirstFrame) { 41 TEST_F(FrameIdWrapHelperTest, FirstFrame) {
22 EXPECT_EQ(kStartFrameId, frame_id_wrap_helper_.MapTo32bitsFrameId(255u)); 42 EXPECT_EQ(kStartFrameId, frame_id_wrap_helper_.MapTo32bitsFrameId(255u));
23 } 43 }
24 44
25 TEST_F(FrameIdWrapHelperTest, Rollover) { 45 TEST_F(FrameIdWrapHelperTest, Rollover) {
(...skipping 13 matching lines...) Expand all
39 } 59 }
40 EXPECT_EQ(254u, new_frame_id); 60 EXPECT_EQ(254u, new_frame_id);
41 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(0u); 61 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(0u);
42 EXPECT_EQ(256u, new_frame_id); 62 EXPECT_EQ(256u, new_frame_id);
43 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(255u); 63 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(255u);
44 EXPECT_EQ(255u, new_frame_id); 64 EXPECT_EQ(255u, new_frame_id);
45 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(1u); 65 new_frame_id = frame_id_wrap_helper_.MapTo32bitsFrameId(1u);
46 EXPECT_EQ(257u, new_frame_id); 66 EXPECT_EQ(257u, new_frame_id);
47 } 67 }
48 68
69 TEST_F(FrameIdWrapHelperTest, Windowed) {
70 srand(0);
71 for (int i = 0; i < 50000 && !HasFailure(); i++) {
72 RunOneTest(i * 4711, 20);
73 // Test wrap-around scenarios.
74 RunOneTest(0x7fffff00ul, 20);
75 RunOneTest(0xffffff00ul, 20);
76 }
77 }
78
49 } // namespace cast 79 } // namespace cast
50 } // namespace media 80 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/cast_transport_defines.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698