@@ -18,23 +18,16 @@ using namespace libcamera;
const std::vector<int> NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };
const std::vector<StreamRole> ROLES = { Raw, StillCapture, VideoRecording, Viewfinder };
-class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>
+class CameraHolder
{
-public:
- static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
-
protected:
- void SetUp() override;
- void TearDown() override;
+ void acquireCamera();
+ void releaseCamera();
std::shared_ptr<Camera> camera_;
};
-/*
- * We use gtest's SetUp() and TearDown() instead of constructor and destructor
- * in order to be able to assert on them.
- */
-void SingleStream::SetUp()
+void CameraHolder::acquireCamera()
{
Environment *env = Environment::get();
@@ -43,7 +36,7 @@ void SingleStream::SetUp()
ASSERT_EQ(camera_->acquire(), 0);
}
-void SingleStream::TearDown()
+void CameraHolder::releaseCamera()
{
if (!camera_)
return;
@@ -52,6 +45,30 @@ void SingleStream::TearDown()
camera_.reset();
}
+class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder
+{
+public:
+ static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
+
+protected:
+ void SetUp() override;
+ void TearDown() override;
+};
+
+/*
+ * We use gtest's SetUp() and TearDown() instead of constructor and destructor
+ * in order to be able to assert on them.
+ */
+void SingleStream::SetUp()
+{
+ acquireCamera();
+}
+
+void SingleStream::TearDown()
+{
+ releaseCamera();
+}
+
std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info)
{
std::map<StreamRole, std::string> rolesMap = { { Raw, "Raw" },
Different base classes can be used for different setups on tests, but all of them will need to setup the camera for the test. To reuse that code, move it to a separate CameraHolder class that is inherited by test classes. Signed-off-by: NĂcolas F. R. A. Prado <nfraprado@collabora.com> --- No changes in v6 Added in v5 src/lc-compliance/capture_test.cpp | 41 +++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-)