[libcamera-devel,v6,05/10] lc-compliance: Move camera setup to CameraHolder class
diff mbox series

Message ID 20210714183857.2046425-6-nfraprado@collabora.com
State Superseded
Headers show
Series
  • lc-compliance: Add test to queue more requests than hardware depth
Related show

Commit Message

NĂ­colas F. R. A. Prado July 14, 2021, 6:38 p.m. UTC
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(-)

Patch
diff mbox series

diff --git a/src/lc-compliance/capture_test.cpp b/src/lc-compliance/capture_test.cpp
index 6439cbd88f8e..949407d3191e 100644
--- a/src/lc-compliance/capture_test.cpp
+++ b/src/lc-compliance/capture_test.cpp
@@ -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" },