1*77c1e3ccSAndroid Build Coastguard Worker /* 2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved. 3*77c1e3ccSAndroid Build Coastguard Worker * 4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and 5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can 7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the 9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10*77c1e3ccSAndroid Build Coastguard Worker */ 11*77c1e3ccSAndroid Build Coastguard Worker 12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_ 13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_ 14*77c1e3ccSAndroid Build Coastguard Worker 15*77c1e3ccSAndroid Build Coastguard Worker #include <ostream> 16*77c1e3ccSAndroid Build Coastguard Worker 17*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h" 18*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h" 19*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h" 20*77c1e3ccSAndroid Build Coastguard Worker 21*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom; 22*77c1e3ccSAndroid Build Coastguard Worker 23*77c1e3ccSAndroid Build Coastguard Worker namespace libaom_test { 24*77c1e3ccSAndroid Build Coastguard Worker // Base class for tests that compare 2 implementations of the same function 25*77c1e3ccSAndroid Build Coastguard Worker // for equivalence. The template parameter should be pointer to a function 26*77c1e3ccSAndroid Build Coastguard Worker // that is being tested. 27*77c1e3ccSAndroid Build Coastguard Worker // 28*77c1e3ccSAndroid Build Coastguard Worker // The test takes a 3-parameters encapsulating struct 'FuncParam', containing: 29*77c1e3ccSAndroid Build Coastguard Worker // - Pointer to reference function 30*77c1e3ccSAndroid Build Coastguard Worker // - Pointer to tested function 31*77c1e3ccSAndroid Build Coastguard Worker // - Integer bit depth (default to 0). 32*77c1e3ccSAndroid Build Coastguard Worker // 33*77c1e3ccSAndroid Build Coastguard Worker // These values are then accessible in the tests as member of params_: 34*77c1e3ccSAndroid Build Coastguard Worker // params_.ref_func, params_.tst_func, and params_.bit_depth. 35*77c1e3ccSAndroid Build Coastguard Worker // 36*77c1e3ccSAndroid Build Coastguard Worker 37*77c1e3ccSAndroid Build Coastguard Worker template <typename T> 38*77c1e3ccSAndroid Build Coastguard Worker struct FuncParam { 39*77c1e3ccSAndroid Build Coastguard Worker FuncParam(T ref = nullptr, T tst = nullptr, int depth = 0) ref_funcFuncParam40*77c1e3ccSAndroid Build Coastguard Worker : ref_func(ref), tst_func(tst), bit_depth(depth) {} 41*77c1e3ccSAndroid Build Coastguard Worker T ref_func; 42*77c1e3ccSAndroid Build Coastguard Worker T tst_func; 43*77c1e3ccSAndroid Build Coastguard Worker int bit_depth; 44*77c1e3ccSAndroid Build Coastguard Worker }; 45*77c1e3ccSAndroid Build Coastguard Worker 46*77c1e3ccSAndroid Build Coastguard Worker template <typename T> 47*77c1e3ccSAndroid Build Coastguard Worker std::ostream &operator<<(std::ostream &os, const FuncParam<T> &p) { 48*77c1e3ccSAndroid Build Coastguard Worker return os << "bit_depth:" << p.bit_depth 49*77c1e3ccSAndroid Build Coastguard Worker << " function:" << reinterpret_cast<const void *>(p.ref_func) 50*77c1e3ccSAndroid Build Coastguard Worker << " function:" << reinterpret_cast<const void *>(p.tst_func); 51*77c1e3ccSAndroid Build Coastguard Worker } 52*77c1e3ccSAndroid Build Coastguard Worker 53*77c1e3ccSAndroid Build Coastguard Worker template <typename T> 54*77c1e3ccSAndroid Build Coastguard Worker class FunctionEquivalenceTest : public ::testing::TestWithParam<FuncParam<T> > { 55*77c1e3ccSAndroid Build Coastguard Worker public: FunctionEquivalenceTest()56*77c1e3ccSAndroid Build Coastguard Worker FunctionEquivalenceTest() : rng_(ACMRandom::DeterministicSeed()) {} 57*77c1e3ccSAndroid Build Coastguard Worker 58*77c1e3ccSAndroid Build Coastguard Worker ~FunctionEquivalenceTest() override = default; 59*77c1e3ccSAndroid Build Coastguard Worker SetUp()60*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override { params_ = this->GetParam(); } 61*77c1e3ccSAndroid Build Coastguard Worker 62*77c1e3ccSAndroid Build Coastguard Worker protected: 63*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rng_; 64*77c1e3ccSAndroid Build Coastguard Worker FuncParam<T> params_; 65*77c1e3ccSAndroid Build Coastguard Worker }; 66*77c1e3ccSAndroid Build Coastguard Worker 67*77c1e3ccSAndroid Build Coastguard Worker } // namespace libaom_test 68*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_ 69