1 /*
2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include "gtest/gtest.h"
13
14 #include "av1/common/seg_common.h"
15 #include "av1/decoder/decodemv.h"
16 #include "av1/encoder/bitstream.h"
17 #include "test/acm_random.h"
18
19 using libaom_test::ACMRandom;
20
21 namespace {
22
23 struct Segment {
24 int id;
25 int pred;
26 int last_id;
27 };
28
GenerateSegment(int seed)29 Segment GenerateSegment(int seed) {
30 ACMRandom rnd_(seed);
31
32 Segment segment;
33 const int last_segid = rnd_.PseudoUniform(MAX_SEGMENTS);
34 segment.last_id = last_segid;
35 segment.pred = rnd_.PseudoUniform(MAX_SEGMENTS);
36 segment.id = rnd_.PseudoUniform(last_segid + 1);
37
38 return segment;
39 }
40
41 // Try to reveal a mismatch between segment binarization and debinarization
TEST(SegmentBinarizationSync,SearchForBinarizationMismatch)42 TEST(SegmentBinarizationSync, SearchForBinarizationMismatch) {
43 const int count_tests = 1000;
44 const int seed_init = 4321;
45
46 for (int i = 0; i < count_tests; ++i) {
47 const Segment seg = GenerateSegment(seed_init + i);
48
49 const int max_segid = seg.last_id + 1;
50 const int seg_diff = av1_neg_interleave(seg.id, seg.pred, max_segid);
51 const int decoded_segid =
52 av1_neg_deinterleave(seg_diff, seg.pred, max_segid);
53
54 ASSERT_EQ(decoded_segid, seg.id);
55 }
56 }
57
58 } // namespace
59