1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci 3141cc406Sopenharmony_ci Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt> 4141cc406Sopenharmony_ci 5141cc406Sopenharmony_ci This file is part of the SANE package. 6141cc406Sopenharmony_ci 7141cc406Sopenharmony_ci This program is free software; you can redistribute it and/or 8141cc406Sopenharmony_ci modify it under the terms of the GNU General Public License as 9141cc406Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 10141cc406Sopenharmony_ci License, or (at your option) any later version. 11141cc406Sopenharmony_ci 12141cc406Sopenharmony_ci This program is distributed in the hope that it will be useful, but 13141cc406Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 14141cc406Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15141cc406Sopenharmony_ci General Public License for more details. 16141cc406Sopenharmony_ci 17141cc406Sopenharmony_ci You should have received a copy of the GNU General Public License 18141cc406Sopenharmony_ci along with this program. If not, see <https://www.gnu.org/licenses/>. 19141cc406Sopenharmony_ci*/ 20141cc406Sopenharmony_ci 21141cc406Sopenharmony_ci#define DEBUG_DECLARE_ONLY 22141cc406Sopenharmony_ci 23141cc406Sopenharmony_ci#include "tests.h" 24141cc406Sopenharmony_ci#include "minigtest.h" 25141cc406Sopenharmony_ci 26141cc406Sopenharmony_ci#include "../../../backend/genesys/low.h" 27141cc406Sopenharmony_ci 28141cc406Sopenharmony_ci#include <sstream> 29141cc406Sopenharmony_ci 30141cc406Sopenharmony_cinamespace genesys { 31141cc406Sopenharmony_ci 32141cc406Sopenharmony_ciGenesys_Calibration_Cache create_fake_calibration_entry() 33141cc406Sopenharmony_ci{ 34141cc406Sopenharmony_ci Genesys_Calibration_Cache calib; 35141cc406Sopenharmony_ci calib.params.channels = 3; 36141cc406Sopenharmony_ci calib.params.depth = 8; 37141cc406Sopenharmony_ci calib.params.lines = 100; 38141cc406Sopenharmony_ci calib.params.pixels = 200; 39141cc406Sopenharmony_ci 40141cc406Sopenharmony_ci GenesysFrontendLayout wolfson_layout; 41141cc406Sopenharmony_ci wolfson_layout.offset_addr = { 0x20, 0x21, 0x22 }; 42141cc406Sopenharmony_ci wolfson_layout.gain_addr = { 0x28, 0x29, 0x2a }; 43141cc406Sopenharmony_ci 44141cc406Sopenharmony_ci Genesys_Frontend fe; 45141cc406Sopenharmony_ci fe.id = AdcId::WOLFSON_UMAX; 46141cc406Sopenharmony_ci fe.layout = wolfson_layout; 47141cc406Sopenharmony_ci fe.regs = { 48141cc406Sopenharmony_ci { 0x00, 0x00 }, 49141cc406Sopenharmony_ci { 0x01, 0x03 }, 50141cc406Sopenharmony_ci { 0x02, 0x05 }, 51141cc406Sopenharmony_ci { 0x03, 0x11 }, 52141cc406Sopenharmony_ci { ' ', 0x80 }, // check whether space-like integer values are correctly serialized 53141cc406Sopenharmony_ci { ',', 0x80 }, 54141cc406Sopenharmony_ci { '\r', '\n' }, 55141cc406Sopenharmony_ci { '\n', 0x00 }, 56141cc406Sopenharmony_ci { 0x25, 0x00 }, 57141cc406Sopenharmony_ci { 0x26, 0x00 }, 58141cc406Sopenharmony_ci { 0x28, 0x02 }, 59141cc406Sopenharmony_ci { 0x29, 0x02 }, 60141cc406Sopenharmony_ci { 0x2a, 0x02 }, 61141cc406Sopenharmony_ci }; 62141cc406Sopenharmony_ci fe.reg2 = {0x00, 0x00, 0x00}; 63141cc406Sopenharmony_ci calib.frontend = fe; 64141cc406Sopenharmony_ci 65141cc406Sopenharmony_ci Genesys_Sensor sensor; 66141cc406Sopenharmony_ci sensor.sensor_id = SensorId::CCD_UMAX; 67141cc406Sopenharmony_ci sensor.full_resolution = 1200; 68141cc406Sopenharmony_ci sensor.black_pixels = 48; 69141cc406Sopenharmony_ci sensor.dummy_pixel = 64; 70141cc406Sopenharmony_ci sensor.fau_gain_white_ref = 210; 71141cc406Sopenharmony_ci sensor.gain_white_ref = 230; 72141cc406Sopenharmony_ci sensor.exposure = { 0x0000, 0x0000, 0x0000 }; 73141cc406Sopenharmony_ci sensor.custom_regs = { 74141cc406Sopenharmony_ci { 0x08, 0x01 }, 75141cc406Sopenharmony_ci { 0x09, 0x03 }, 76141cc406Sopenharmony_ci { 0x0a, 0x05 }, 77141cc406Sopenharmony_ci { 0x0b, 0x07 }, 78141cc406Sopenharmony_ci { 0x16, 0x33 }, 79141cc406Sopenharmony_ci { 0x17, 0x05 }, 80141cc406Sopenharmony_ci { 0x18, 0x31 }, 81141cc406Sopenharmony_ci { 0x19, 0x2a }, 82141cc406Sopenharmony_ci { 0x1a, 0x00 }, 83141cc406Sopenharmony_ci { 0x1b, 0x00 }, 84141cc406Sopenharmony_ci { 0x1c, 0x00 }, 85141cc406Sopenharmony_ci { 0x1d, 0x02 }, 86141cc406Sopenharmony_ci { 0x52, 0x13 }, 87141cc406Sopenharmony_ci { 0x53, 0x17 }, 88141cc406Sopenharmony_ci { 0x54, 0x03 }, 89141cc406Sopenharmony_ci { 0x55, 0x07 }, 90141cc406Sopenharmony_ci { 0x56, 0x0b }, 91141cc406Sopenharmony_ci { 0x57, 0x0f }, 92141cc406Sopenharmony_ci { 0x58, 0x23 }, 93141cc406Sopenharmony_ci { 0x59, 0x00 }, 94141cc406Sopenharmony_ci { 0x5a, 0xc1 }, 95141cc406Sopenharmony_ci { 0x5b, 0x00 }, 96141cc406Sopenharmony_ci { 0x5c, 0x00 }, 97141cc406Sopenharmony_ci { 0x5d, 0x00 }, 98141cc406Sopenharmony_ci { 0x5e, 0x00 }, 99141cc406Sopenharmony_ci }; 100141cc406Sopenharmony_ci sensor.gamma = {1.0, 1.0, 1.0}; 101141cc406Sopenharmony_ci calib.sensor = sensor; 102141cc406Sopenharmony_ci 103141cc406Sopenharmony_ci calib.average_size = 7; 104141cc406Sopenharmony_ci calib.white_average_data = { 8, 7, 6, 5, 4, 3, 2 }; 105141cc406Sopenharmony_ci calib.dark_average_data = { 6, 5, 4, 3, 2, 18, 12 }; 106141cc406Sopenharmony_ci return calib; 107141cc406Sopenharmony_ci} 108141cc406Sopenharmony_ci 109141cc406Sopenharmony_civoid test_calibration_roundtrip() 110141cc406Sopenharmony_ci{ 111141cc406Sopenharmony_ci Genesys_Device::Calibration calibration = { create_fake_calibration_entry() }; 112141cc406Sopenharmony_ci Genesys_Device::Calibration deserialized; 113141cc406Sopenharmony_ci 114141cc406Sopenharmony_ci std::stringstream str; 115141cc406Sopenharmony_ci serialize(static_cast<std::ostream&>(str), calibration); 116141cc406Sopenharmony_ci serialize(static_cast<std::istream&>(str), deserialized); 117141cc406Sopenharmony_ci ASSERT_TRUE(calibration == deserialized); 118141cc406Sopenharmony_ci 119141cc406Sopenharmony_ci int x; 120141cc406Sopenharmony_ci str >> x; 121141cc406Sopenharmony_ci ASSERT_TRUE(str.eof()); 122141cc406Sopenharmony_ci} 123141cc406Sopenharmony_ci 124141cc406Sopenharmony_civoid test_calibration_parsing() 125141cc406Sopenharmony_ci{ 126141cc406Sopenharmony_ci test_calibration_roundtrip(); 127141cc406Sopenharmony_ci} 128141cc406Sopenharmony_ci 129141cc406Sopenharmony_ci} // namespace genesys 130