/utils/tracepoints/

d class='logo' rowspan='2'>cgit logo index : libcamera/libcamera.git
libcamera official repositorygit repository hosting on libcamera.org
summaryrefslogtreecommitdiff
path: root/test/stream/stream_formats.cpp
blob: 99fa0385e961dc1623d60cb9cbabfbd5be8a8341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * stream_formats.cpp - StreamFormats test
 */

#include <iostream>

#include <libcamera/geometry.h>
#include <libcamera/stream.h>

#include "test.h"

using namespace std;
using namespace libcamera;

class StreamFormatsTest : public Test
{
protected:
	int testSizes(std::string name, std::vector<Size> test, std::vector<Size> valid)
	{
		bool pass = false;

		for (Size &size : test) {
			pass = false;

			for (Size &validSize : valid) {
				if (size == validSize) {
					pass = true;
					break;
				}
			}

			if (!pass)
				break;
		}

		if (!pass) {
			cout << "Failed " << name << endl;
			cout << "Sizes to test:" << endl;
			for (Size &size : test)
				cout << size << endl;
			cout << "Valid sizes:" << endl;
			for (Size &size : valid)
				cout << size << endl;

			return TestFail;
		}

		return TestPass;
	}

	int run()
	{
		/* Test discrete sizes */
		StreamFormats discrete({
			{ PixelFormat(1), { SizeRange({ 100, 100 }), SizeRange({ 200, 200 }) } },
			{ PixelFormat(2), { SizeRange({ 300, 300 }), SizeRange({ 400, 400 }) } },
		});

		if (testSizes("discrete 1", discrete.sizes(PixelFormat(1)),
			      { Size(100, 100), Size(200, 200) }))
			return TestFail;
		if (testSizes("discrete 2", discrete.sizes(PixelFormat(2)),
			      { Size(300, 300), Size(400, 400) }))
			return TestFail;

		/* Test range sizes */
		StreamFormats range({
			{ PixelFormat(1), { SizeRange({ 640, 480 }, { 640, 480 }) } },
			{ PixelFormat(2), { SizeRange({ 640, 480 }, { 800, 600 }, 8, 8) } },
			{ PixelFormat(3), { SizeRange({ 640, 480 }, { 800, 600 }, 16, 16) } },
			{ PixelFormat(4), { SizeRange({ 128, 128 }, { 4096, 4096 }, 128, 128) } },
		});

		if (testSizes("range 1", range.sizes(PixelFormat(1)), { Size(640, 480) }))
			return TestFail;

		if (testSizes("range 2", range.sizes(PixelFormat(2)), {
			      Size(640, 480), Size(720, 480),
			      Size(720, 576), Size(768, 480),
			      Size(800, 600) }))
			return TestFail;

		if (testSizes("range 3", range.sizes(PixelFormat(3)), {
			      Size(640, 480), Size(720, 480),