mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 21:20:18 +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 "test_common.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
namespace opencv_test { namespace {
|
||||
using namespace cv::dnn;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
@ -11539,12 +11539,15 @@ typename ParamNameGenFunc<ParamType>::Type *GetParamNameGen() {
|
||||
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.
|
||||
//
|
||||
// Stores a parameter value and later creates tests parameterized with that
|
||||
// value.
|
||||
template <class TestClass>
|
||||
class ParameterizedTestFactory : public TestFactoryBase {
|
||||
class ParameterizedTestFactory : public internal::TestFactoryBase {
|
||||
public:
|
||||
typedef typename TestClass::ParamType ParamType;
|
||||
explicit ParameterizedTestFactory(ParamType parameter) :
|
||||
@ -11559,6 +11562,8 @@ class ParameterizedTestFactory : public TestFactoryBase {
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
|
||||
};
|
||||
} // namespace
|
||||
namespace internal {
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
@ -20405,6 +20410,12 @@ class GTEST_API_ AssertHelper {
|
||||
} // namespace internal
|
||||
|
||||
#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.
|
||||
// A value-parameterized class must inherit from both ::testing::Test and
|
||||
// ::testing::WithParamInterface. In most cases that just means inheriting
|
||||
@ -20451,29 +20462,28 @@ class WithParamInterface {
|
||||
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
|
||||
// uses a fixture whose parameter type is int.
|
||||
const ParamType& GetParam() const {
|
||||
GTEST_CHECK_(parameter_ != NULL)
|
||||
GTEST_CHECK_(GetParameterPtrRef_() != NULL)
|
||||
<< "GetParam() can only be called inside a value-parameterized test "
|
||||
<< "-- did you intend to write TEST_P instead of TEST_F?";
|
||||
return *parameter_;
|
||||
return *GetParameterPtrRef_();
|
||||
}
|
||||
|
||||
private:
|
||||
// Sets parameter value. The caller is responsible for making sure the value
|
||||
// remains alive and unchanged throughout the current test.
|
||||
static void SetParam(const ParamType* parameter) {
|
||||
parameter_ = parameter;
|
||||
GetParameterPtrRef_() = parameter;
|
||||
}
|
||||
|
||||
// Static value used for accessing parameter during a test lifetime.
|
||||
static const ParamType* parameter_;
|
||||
static const ParamType*& GetParameterPtrRef_()
|
||||
{
|
||||
return (const ParamType*&)internal::g_parameter_;
|
||||
}
|
||||
|
||||
// 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
|
||||
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
|
||||
|
||||
|
@ -10441,5 +10441,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
void* g_parameter_ = NULL;
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
Loading…
Reference in New Issue
Block a user