tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

function_equivalence_test.h (2206B)


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