1 /* sane - Scanner Access Now Easy.
2
3 Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4
5 This file is part of the SANE package.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #define DEBUG_DECLARE_ONLY
22
23 #include "tests.h"
24 #include "minigtest.h"
25
26 #include "../../../backend/genesys/low.h"
27
28 #include <sstream>
29
30 namespace genesys {
31
create_fake_calibration_entry()32 Genesys_Calibration_Cache create_fake_calibration_entry()
33 {
34 Genesys_Calibration_Cache calib;
35 calib.params.channels = 3;
36 calib.params.depth = 8;
37 calib.params.lines = 100;
38 calib.params.pixels = 200;
39
40 GenesysFrontendLayout wolfson_layout;
41 wolfson_layout.offset_addr = { 0x20, 0x21, 0x22 };
42 wolfson_layout.gain_addr = { 0x28, 0x29, 0x2a };
43
44 Genesys_Frontend fe;
45 fe.id = AdcId::WOLFSON_UMAX;
46 fe.layout = wolfson_layout;
47 fe.regs = {
48 { 0x00, 0x00 },
49 { 0x01, 0x03 },
50 { 0x02, 0x05 },
51 { 0x03, 0x11 },
52 { ' ', 0x80 }, // check whether space-like integer values are correctly serialized
53 { ',', 0x80 },
54 { '\r', '\n' },
55 { '\n', 0x00 },
56 { 0x25, 0x00 },
57 { 0x26, 0x00 },
58 { 0x28, 0x02 },
59 { 0x29, 0x02 },
60 { 0x2a, 0x02 },
61 };
62 fe.reg2 = {0x00, 0x00, 0x00};
63 calib.frontend = fe;
64
65 Genesys_Sensor sensor;
66 sensor.sensor_id = SensorId::CCD_UMAX;
67 sensor.full_resolution = 1200;
68 sensor.black_pixels = 48;
69 sensor.dummy_pixel = 64;
70 sensor.fau_gain_white_ref = 210;
71 sensor.gain_white_ref = 230;
72 sensor.exposure = { 0x0000, 0x0000, 0x0000 };
73 sensor.custom_regs = {
74 { 0x08, 0x01 },
75 { 0x09, 0x03 },
76 { 0x0a, 0x05 },
77 { 0x0b, 0x07 },
78 { 0x16, 0x33 },
79 { 0x17, 0x05 },
80 { 0x18, 0x31 },
81 { 0x19, 0x2a },
82 { 0x1a, 0x00 },
83 { 0x1b, 0x00 },
84 { 0x1c, 0x00 },
85 { 0x1d, 0x02 },
86 { 0x52, 0x13 },
87 { 0x53, 0x17 },
88 { 0x54, 0x03 },
89 { 0x55, 0x07 },
90 { 0x56, 0x0b },
91 { 0x57, 0x0f },
92 { 0x58, 0x23 },
93 { 0x59, 0x00 },
94 { 0x5a, 0xc1 },
95 { 0x5b, 0x00 },
96 { 0x5c, 0x00 },
97 { 0x5d, 0x00 },
98 { 0x5e, 0x00 },
99 };
100 sensor.gamma = {1.0, 1.0, 1.0};
101 calib.sensor = sensor;
102
103 calib.average_size = 7;
104 calib.white_average_data = { 8, 7, 6, 5, 4, 3, 2 };
105 calib.dark_average_data = { 6, 5, 4, 3, 2, 18, 12 };
106 return calib;
107 }
108
test_calibration_roundtrip()109 void test_calibration_roundtrip()
110 {
111 Genesys_Device::Calibration calibration = { create_fake_calibration_entry() };
112 Genesys_Device::Calibration deserialized;
113
114 std::stringstream str;
115 serialize(static_cast<std::ostream&>(str), calibration);
116 serialize(static_cast<std::istream&>(str), deserialized);
117 ASSERT_TRUE(calibration == deserialized);
118
119 int x;
120 str >> x;
121 ASSERT_TRUE(str.eof());
122 }
123
test_calibration_parsing()124 void test_calibration_parsing()
125 {
126 test_calibration_roundtrip();
127 }
128
129 } // namespace genesys
130