mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 11:03:03 +08:00
gtest: support parameters with types from anonymous namespace
This commit is contained in:
parent
ccbc0b91ea
commit
04802e41e9
@ -49,7 +49,7 @@
|
|||||||
#include "opencv2/dnn.hpp"
|
#include "opencv2/dnn.hpp"
|
||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
namespace opencv_test {
|
namespace opencv_test { namespace {
|
||||||
using namespace cv::dnn;
|
using namespace cv::dnn;
|
||||||
|
|
||||||
CV_ENUM(DNNBackend, DNN_BACKEND_DEFAULT, DNN_BACKEND_HALIDE, DNN_BACKEND_INFERENCE_ENGINE)
|
CV_ENUM(DNNBackend, DNN_BACKEND_DEFAULT, DNN_BACKEND_HALIDE, DNN_BACKEND_INFERENCE_ENGINE)
|
||||||
@ -69,6 +69,6 @@ static testing::internal::ParamGenerator<DNNTarget> availableDnnTargets()
|
|||||||
return testing::ValuesIn(targets);
|
return testing::ValuesIn(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11539,12 +11539,15 @@ typename ParamNameGenFunc<ParamType>::Type *GetParamNameGen() {
|
|||||||
return DefaultParamName;
|
return DefaultParamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace internal:: // fixes MacOS X issue with "friend class internal/*::anon*/::ParameterizedTestFactory;"
|
||||||
|
namespace { // wrap into anynomous namespace to avoid build warnings like GCC's -Wsubobject-linkage
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Stores a parameter value and later creates tests parameterized with that
|
// Stores a parameter value and later creates tests parameterized with that
|
||||||
// value.
|
// value.
|
||||||
template <class TestClass>
|
template <class TestClass>
|
||||||
class ParameterizedTestFactory : public TestFactoryBase {
|
class ParameterizedTestFactory : public internal::TestFactoryBase {
|
||||||
public:
|
public:
|
||||||
typedef typename TestClass::ParamType ParamType;
|
typedef typename TestClass::ParamType ParamType;
|
||||||
explicit ParameterizedTestFactory(ParamType parameter) :
|
explicit ParameterizedTestFactory(ParamType parameter) :
|
||||||
@ -11559,6 +11562,8 @@ class ParameterizedTestFactory : public TestFactoryBase {
|
|||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
|
||||||
};
|
};
|
||||||
|
} // namespace
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
@ -20405,6 +20410,12 @@ class GTEST_API_ AssertHelper {
|
|||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
#if GTEST_HAS_PARAM_TEST
|
#if GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
// Static value used for accessing test parameter during a test lifetime.
|
||||||
|
extern void* g_parameter_;
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
// The pure interface class that all value-parameterized tests inherit from.
|
// The pure interface class that all value-parameterized tests inherit from.
|
||||||
// A value-parameterized class must inherit from both ::testing::Test and
|
// A value-parameterized class must inherit from both ::testing::Test and
|
||||||
// ::testing::WithParamInterface. In most cases that just means inheriting
|
// ::testing::WithParamInterface. In most cases that just means inheriting
|
||||||
@ -20451,29 +20462,28 @@ class WithParamInterface {
|
|||||||
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
|
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
|
||||||
// uses a fixture whose parameter type is int.
|
// uses a fixture whose parameter type is int.
|
||||||
const ParamType& GetParam() const {
|
const ParamType& GetParam() const {
|
||||||
GTEST_CHECK_(parameter_ != NULL)
|
GTEST_CHECK_(GetParameterPtrRef_() != NULL)
|
||||||
<< "GetParam() can only be called inside a value-parameterized test "
|
<< "GetParam() can only be called inside a value-parameterized test "
|
||||||
<< "-- did you intend to write TEST_P instead of TEST_F?";
|
<< "-- did you intend to write TEST_P instead of TEST_F?";
|
||||||
return *parameter_;
|
return *GetParameterPtrRef_();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Sets parameter value. The caller is responsible for making sure the value
|
// Sets parameter value. The caller is responsible for making sure the value
|
||||||
// remains alive and unchanged throughout the current test.
|
// remains alive and unchanged throughout the current test.
|
||||||
static void SetParam(const ParamType* parameter) {
|
static void SetParam(const ParamType* parameter) {
|
||||||
parameter_ = parameter;
|
GetParameterPtrRef_() = parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static value used for accessing parameter during a test lifetime.
|
static const ParamType*& GetParameterPtrRef_()
|
||||||
static const ParamType* parameter_;
|
{
|
||||||
|
return (const ParamType*&)internal::g_parameter_;
|
||||||
|
}
|
||||||
|
|
||||||
// TestClass must be a subclass of WithParamInterface<T> and Test.
|
// TestClass must be a subclass of WithParamInterface<T> and Test.
|
||||||
template <class TestClass> friend class internal::ParameterizedTestFactory;
|
template <class TestClass> friend class /*internal::*/ParameterizedTestFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
const T* WithParamInterface<T>::parameter_ = NULL;
|
|
||||||
|
|
||||||
// Most value-parameterized classes can ignore the existence of
|
// Most value-parameterized classes can ignore the existence of
|
||||||
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
|
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
|
||||||
|
|
||||||
|
@ -10441,5 +10441,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
|||||||
|
|
||||||
#endif // GTEST_HAS_TYPED_TEST_P
|
#endif // GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
|
void* g_parameter_ = NULL;
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
Loading…
Reference in New Issue
Block a user