blob: 37f415302ff6ae4aa8ff288d5b0a17829d847f2f (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* control_value.cpp - ControlValue tests
*/
#include <iostream>
#include <libcamera/controls.h>
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlValueTest : public Test
{
protected:
int run()
{
/*
* None type.
*/
ControlValue value;
if (!value.isNone() || value.isArray()) {
cerr << "Empty value is non-null" << endl;
return TestFail;
}
/*
* Bool type.
*/
value.set(true);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeBool) {
cerr << "Control type mismatch after setting to bool" << endl;
return TestFail;
}
if (value.get<bool>() != true) {
cerr << "Control value mismatch after setting to bool" << endl;
return TestFail;
}
if (value.toString() != "true") {
cerr << "Control string mismatch after setting to bool" << endl;
return TestFail;
}
/*
* Integer8 type.
*/
value.set(static_cast<uint8_t>(42));
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeByte) {
cerr << "Control type mismatch after setting to uint8_t" << endl;
return TestFail;
}
if (value.get<uint8_t>() != 42) {
cerr << "Control value mismatch after setting to uint8_t" << endl;
return TestFail;
}
if (value.toString() != "42") {
cerr << "Control string mismatch after setting to uint8_t" << endl;
return TestFail;
}
/*
* Integer32 type.
*/
value.set(0x42000000);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeInteger32) {
cerr << "Control type mismatch after setting to int32_t" << endl;
return TestFail;
}
if (value.get<int32_t>() != 0x42000000) {
cerr << "Control value mismatch after setting to int32_t" << endl;
return TestFail;
}
if (value.toString() != "1107296256") {
cerr << "Control string mismatch after setting to int32_t" << endl;
return TestFail;
}
/*
* Integer64 type.
*/
value.set(static_cast<int64_t>(-42));
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeInteger64) {
cerr << "Control type mismatch after setting to int64_t" << endl;
return TestFail;
}
if (value.get<int64_t>() != -42) {
cerr << "Control value mismatch after setting to int64_t" << endl;
return TestFail;
}
if (value.toString() != "-42") {
cerr << "Control string mismatch after setting to int64_t" << endl;
return TestFail;
}
/*
* Float type.
*/
value.set(-0.42f);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeFloat) {
cerr << "Control type mismatch after setting to float" << endl;
return TestFail;
}
if (value.get<float>() != -0.42f) {
cerr << "Control value mismatch after setting to float" << endl;
return TestFail;
}
if (value.toString() != "-0.420000") {
cerr << "Control string mismatch after setting to float" << endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(ControlValueTest)
|