• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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 #ifndef AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_
13 #define AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_
14 
15 #include <ostream>
16 
17 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
18 #include "test/acm_random.h"
19 #include "test/clear_system_state.h"
20 #include "test/util.h"
21 
22 using libaom_test::ACMRandom;
23 
24 namespace libaom_test {
25 // Base class for tests that compare 2 implementations of the same function
26 // for equivalence. The template parameter should be pointer to a function
27 // that is being tested.
28 //
29 // The test takes a 3-parameters encapsulating struct 'FuncParam', containing:
30 //   - Pointer to reference function
31 //   - Pointer to tested function
32 //   - Integer bit depth (default to 0).
33 //
34 // These values are then accessible in the tests as member of params_:
35 // params_.ref_func, params_.tst_func, and params_.bit_depth.
36 //
37 
38 template <typename T>
39 struct FuncParam {
40   FuncParam(T ref = NULL, T tst = NULL, int bit_depth = 0)
ref_funcFuncParam41       : ref_func(ref), tst_func(tst), bit_depth(bit_depth) {}
42   T ref_func;
43   T tst_func;
44   int bit_depth;
45 };
46 
47 template <typename T>
48 std::ostream &operator<<(std::ostream &os, const FuncParam<T> &p) {
49   return os << "bit_depth:" << p.bit_depth
50             << " function:" << reinterpret_cast<const void *>(p.ref_func)
51             << " function:" << reinterpret_cast<const void *>(p.tst_func);
52 }
53 
54 template <typename T>
55 class FunctionEquivalenceTest : public ::testing::TestWithParam<FuncParam<T> > {
56  public:
FunctionEquivalenceTest()57   FunctionEquivalenceTest() : rng_(ACMRandom::DeterministicSeed()) {}
58 
~FunctionEquivalenceTest()59   virtual ~FunctionEquivalenceTest() {}
60 
SetUp()61   virtual void SetUp() { params_ = this->GetParam(); }
62 
TearDown()63   virtual void TearDown() { libaom_test::ClearSystemState(); }
64 
65  protected:
66   ACMRandom rng_;
67   FuncParam<T> params_;
68 };
69 
70 }  // namespace libaom_test
71 #endif  // AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_
72