blob: b122ff18c3761d73c30efb455a85edb50da50aab [file] [log] [blame]
Geza Lorea661bc82016-05-20 16:33:12 +01001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Geza Lorea661bc82016-05-20 16:33:12 +01003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Geza Lorea661bc82016-05-20 16:33:12 +010010 */
11
12#ifndef TEST_FUNCTION_EQUIVALENCE_TEST_H_
13#define TEST_FUNCTION_EQUIVALENCE_TEST_H_
14
15#include "third_party/googletest/src/include/gtest/gtest.h"
Geza Lorea3f7ddc2016-07-12 15:26:36 +010016#include "test/acm_random.h"
Geza Lorea661bc82016-05-20 16:33:12 +010017#include "test/clear_system_state.h"
18#include "test/util.h"
19
Yaowu Xuc27fc142016-08-22 16:08:15 -070020using libaom_test::ACMRandom;
Geza Lorea3f7ddc2016-07-12 15:26:36 +010021
Yaowu Xuc27fc142016-08-22 16:08:15 -070022namespace libaom_test {
Geza Lorea3f7ddc2016-07-12 15:26:36 +010023// Base class for tests that compare 2 implementations of the same function
24// for equivalence. The template parameter should be pointer to a function
25// that is being tested.
26//
27// The test takes a 3-parameters encapsulating struct 'FuncParam', containing:
28// - Pointer to reference function
29// - Pointer to tested function
30// - Integer bit depth (default to 0).
31//
32// These values are then accessible in the tests as member of params_:
33// params_.ref_func, params_.tst_func, and params_.bit_depth.
34//
35
Geza Lorea661bc82016-05-20 16:33:12 +010036template <typename T>
Geza Lorea3f7ddc2016-07-12 15:26:36 +010037struct FuncParam {
38 FuncParam(T ref = NULL, T tst = NULL, int bit_depth = 0)
39 : ref_func(ref), tst_func(tst), bit_depth(bit_depth) {}
40 T ref_func;
41 T tst_func;
42 int bit_depth;
43};
44
45template <typename T>
46class FunctionEquivalenceTest : public ::testing::TestWithParam<FuncParam<T> > {
Geza Lorea661bc82016-05-20 16:33:12 +010047 public:
Geza Lorea3f7ddc2016-07-12 15:26:36 +010048 FunctionEquivalenceTest() : rng_(ACMRandom::DeterministicSeed()) {}
49
Geza Lorea661bc82016-05-20 16:33:12 +010050 virtual ~FunctionEquivalenceTest() {}
51
clang-format3a826f12016-08-11 17:46:05 -070052 virtual void SetUp() { params_ = this->GetParam(); }
Geza Lorea661bc82016-05-20 16:33:12 +010053
Yaowu Xuc27fc142016-08-22 16:08:15 -070054 virtual void TearDown() { libaom_test::ClearSystemState(); }
Geza Lorea661bc82016-05-20 16:33:12 +010055
56 protected:
Geza Lorea3f7ddc2016-07-12 15:26:36 +010057 ACMRandom rng_;
58 FuncParam<T> params_;
Geza Lorea661bc82016-05-20 16:33:12 +010059};
60
Yaowu Xuc27fc142016-08-22 16:08:15 -070061} // namespace libaom_test
Geza Lorea661bc82016-05-20 16:33:12 +010062#endif // TEST_FUNCTION_EQUIVALENCE_TEST_H_