[libcamera-devel,v2,12/12] tests: add test to list all cameras in the system

Message ID 20181229032855.26249-13-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • Add basic camera enumeration
Related show

Commit Message

Niklas Söderlund Dec. 29, 2018, 3:28 a.m. UTC
Add simple test which lists all cameras detected in the system. The test
fails if no camera can be found.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 test/list.cpp    | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  5 +++++
 2 files changed, 59 insertions(+)
 create mode 100644 test/list.cpp

Patch

diff --git a/test/list.cpp b/test/list.cpp
new file mode 100644
index 0000000000000000..39b8a41d1fef892c
--- /dev/null
+++ b/test/list.cpp
@@ -0,0 +1,54 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2018, Google Inc.
+ *
+ * list.cpp - camera list tests
+ */
+
+#include <iostream>
+
+#include <libcamera/camera_manager.h>
+
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+
+class ListTest : public Test
+{
+protected:
+	int init()
+	{
+		cm = new CameraManager();
+		if (!cm)
+			return -ENOMEM;
+
+		cm->start();
+
+		return 0;
+	}
+
+	int run()
+	{
+		unsigned int count = 0;
+
+		for (auto name : cm->list()) {
+			cout << "- " << name << endl;
+			count++;
+		}
+
+		return count ? 0 : -ENODEV;
+	}
+
+	void cleanup()
+	{
+		cm->stop();
+
+		delete cm;
+	}
+
+private:
+	CameraManager *cm;
+};
+
+TEST_REGISTER(ListTest)
diff --git a/test/meson.build b/test/meson.build
index da0aea9678d127ce..a74629f89197ecea 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -8,4 +8,9 @@  test_init = executable('test_init', 'init.cpp',
                        link_with : libcamera,
                        include_directories : libcamera_includes)
 
+list = executable('list', 'list.cpp',
+                    link_with : [libcamera, libtest],
+                    include_directories : libcamera_includes)
+
 test('Initialisation test', test_init)
+test('List Camera API tests', list)