[libcamera-devel,v11,3/5] lc-compliance: Add Environment singleton
diff mbox series

Message ID 20210702122114.724932-4-nfraprado@collabora.com
State Accepted
Commit e5c51e1fcf8cf5de6d5bce1da7a2b3d95019f06e
Headers show
Series
  • lc-compliance: Refactor using Googletest
Related show

Commit Message

Nícolas F. R. A. Prado July 2, 2021, 12:21 p.m. UTC
Add a singleton Environment class in order to make the camera available
inside all tests. This is needed for the Googletest refactor, otherwise
the tests, which are statically declared, won't be able to access the
camera.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
No changes in v11

No changes in v10

No changes in v9

Changes in v8:
- Thanks to Laurent:
  - Fixed compiling error in Clang
- Thanks to Kieran:
  - Fixed coding style issues

Changes in v7:
- Thanks to Jacopo:
  - Fixed style issue
  - Made CameraManager a unique_ptr and passed to Environment as raw pointer

Changes in v6:
- Thanks to Niklas:
  - Made cameraId() return const& 

Changes in v5:
- Thanks to Laurent:
  - Stored CameraManager and cameraId instead of Camera in Environment
- Thanks to Laurent & Niklas:
  - Improved Environment singleton class instantiation and destruction

Added in v4

 src/lc-compliance/environment.cpp | 20 ++++++++++++++++++++
 src/lc-compliance/environment.h   | 31 +++++++++++++++++++++++++++++++
 src/lc-compliance/meson.build     |  1 +
 3 files changed, 52 insertions(+)
 create mode 100644 src/lc-compliance/environment.cpp
 create mode 100644 src/lc-compliance/environment.h

Patch
diff mbox series

diff --git a/src/lc-compliance/environment.cpp b/src/lc-compliance/environment.cpp
new file mode 100644
index 000000000000..9e24b5e34e4a
--- /dev/null
+++ b/src/lc-compliance/environment.cpp
@@ -0,0 +1,20 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021, Collabora Ltd.
+ *
+ * environment.cpp - Common environment for tests
+ */
+
+#include "environment.h"
+
+Environment *Environment::get()
+{
+	static Environment instance;
+	return &instance;
+}
+
+void Environment::setup(CameraManager *cm, std::string cameraId)
+{
+	cm_ = cm;
+	cameraId_ = cameraId;
+}
diff --git a/src/lc-compliance/environment.h b/src/lc-compliance/environment.h
new file mode 100644
index 000000000000..1c7d9a558dc2
--- /dev/null
+++ b/src/lc-compliance/environment.h
@@ -0,0 +1,31 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021, Collabora Ltd.
+ *
+ * environment.h - Common environment for tests
+ */
+#ifndef __LC_COMPLIANCE_ENVIRONMENT_H__
+#define __LC_COMPLIANCE_ENVIRONMENT_H__
+
+#include <libcamera/libcamera.h>
+
+using namespace libcamera;
+
+class Environment
+{
+public:
+	static Environment *get();
+
+	void setup(CameraManager *cm, std::string cameraId);
+
+	const std::string &cameraId() const { return cameraId_; }
+	CameraManager *cm() const { return cm_; }
+
+private:
+	Environment() = default;
+
+	std::string cameraId_;
+	CameraManager *cm_;
+};
+
+#endif /* __LC_COMPLIANCE_ENVIRONMENT_H__ */
diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build
index f3a7cbdec4f8..3e7bdb032843 100644
--- a/src/lc-compliance/meson.build
+++ b/src/lc-compliance/meson.build
@@ -12,6 +12,7 @@  lc_compliance_enabled = true
 lc_compliance_sources = files([
     '../cam/event_loop.cpp',
     '../cam/options.cpp',
+    'environment.cpp',
     'main.cpp',
     'results.cpp',
     'simple_capture.cpp',