@@ -10,8 +10,8 @@
#include <gtest/gtest.h>
-#include "environment.h"
#include "simple_capture.h"
+#include "test_base.h"
using namespace libcamera;
@@ -23,7 +23,7 @@ const std::vector<StreamRole> ROLES = {
StreamRole::Viewfinder
};
-class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>
+class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder
{
public:
static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
@@ -31,8 +31,6 @@ public:
protected:
void SetUp() override;
void TearDown() override;
-
- std::shared_ptr<Camera> camera_;
};
/*
@@ -41,20 +39,12 @@ protected:
*/
void SingleStream::SetUp()
{
- Environment *env = Environment::get();
-
- camera_ = env->cm()->get(env->cameraId());
-
- ASSERT_EQ(camera_->acquire(), 0);
+ acquireCamera();
}
void SingleStream::TearDown()
{
- if (!camera_)
- return;
-
- camera_->release();
- camera_.reset();
+ releaseCamera();
}
std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info)
@@ -15,6 +15,7 @@ lc_compliance_sources = files([
'environment.cpp',
'main.cpp',
'simple_capture.cpp',
+ 'test_base.cpp',
])
lc_compliance = executable('lc-compliance', lc_compliance_sources,
new file mode 100644
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021, Collabora Ltd.
+ *
+ * test_base.cpp - Base definitions for tests
+ */
+
+#include "test_base.h"
+
+#include "environment.h"
+
+void CameraHolder::acquireCamera()
+{
+ Environment *env = Environment::get();
+
+ camera_ = env->cm()->get(env->cameraId());
+
+ ASSERT_EQ(camera_->acquire(), 0);
+}
+
+void CameraHolder::releaseCamera()
+{
+ if (!camera_)
+ return;
+
+ camera_->release();
+ camera_.reset();
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021, Collabora Ltd.
+ *
+ * test_base.h - Base definitions for tests
+ */
+
+#ifndef __LC_COMPLIANCE_TEST_BASE_H__
+#define __LC_COMPLIANCE_TEST_BASE_H__
+
+#include <libcamera/libcamera.h>
+
+#include <gtest/gtest.h>
+
+class CameraHolder
+{
+protected:
+ void acquireCamera();
+ void releaseCamera();
+
+ std::shared_ptr<libcamera::Camera> camera_;
+};
+
+#endif /* __LC_COMPLIANCE_TEST_BASE_H__ */