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 "third_party/googletest/src/googletest/include/gtest/gtest.h"
13 #include "test/acm_random.h"
14
15 using libaom_test::ACMRandom;
16
17 extern "C" {
18 int av1_neg_interleave(int x, int ref, int max);
19 int av1_neg_deinterleave(int diff, int ref, int max);
20 }
21
22 namespace {
23
24 struct Segment {
25 int id;
26 int pred;
27 int last_id;
28 };
29
GenerateSegment(int seed)30 Segment GenerateSegment(int seed) {
31 static const int MAX_SEGMENTS = 8;
32
33 ACMRandom rnd_(seed);
34
35 Segment segment;
36 const int last_segid = rnd_.PseudoUniform(MAX_SEGMENTS);
37 segment.last_id = last_segid;
38 segment.pred = rnd_.PseudoUniform(MAX_SEGMENTS);
39 segment.id = rnd_.PseudoUniform(last_segid + 1);
40
41 return segment;
42 }
43
44 // Try to reveal a mismatch between segment binarization and debinarization
TEST(SegmentBinarizationSync,SearchForBinarizationMismatch)45 TEST(SegmentBinarizationSync, SearchForBinarizationMismatch) {
46 const int count_tests = 1000;
47 const int seed_init = 4321;
48
49 for (int i = 0; i < count_tests; ++i) {
50 const Segment seg = GenerateSegment(seed_init + i);
51
52 const int max_segid = seg.last_id + 1;
53 const int seg_diff = av1_neg_interleave(seg.id, seg.pred, max_segid);
54 const int decoded_segid =
55 av1_neg_deinterleave(seg_diff, seg.pred, max_segid);
56
57 ASSERT_EQ(decoded_segid, seg.id);
58 }
59 }
60
61 } // namespace
62