From e5c51e1fcf8cf5de6d5bce1da7a2b3d95019f06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= Date: Fri, 2 Jul 2021 09:21:12 -0300 Subject: lc-compliance: Add Environment singleton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- 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 (limited to 'src') diff --git a/src/lc-compliance/environment.cpp b/src/lc-compliance/environment.cpp new file mode 100644 index 00000000..9e24b5e3 --- /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 00000000..1c7d9a55 --- /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 + +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 f3a7cbde..3e7bdb03 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', -- cgit v1.2.1