From 15819a7d12eef1e10921b0f4b1f1d10746786bcb Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 23 Nov 2019 12:38:43 +0200 Subject: [PATCH] genesys: Add tests for sanei_genesys_create_slope_table3() --- testsuite/backend/genesys/Makefile.am | 1 + testsuite/backend/genesys/tests.cpp | 1 + testsuite/backend/genesys/tests.h | 1 + testsuite/backend/genesys/tests_motor.cpp | 165 ++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 testsuite/backend/genesys/tests_motor.cpp diff --git a/testsuite/backend/genesys/Makefile.am b/testsuite/backend/genesys/Makefile.am index 525310e19..818a523c6 100644 --- a/testsuite/backend/genesys/Makefile.am +++ b/testsuite/backend/genesys/Makefile.am @@ -24,6 +24,7 @@ genesys_unit_tests_SOURCES = tests.cpp tests.h \ tests_calibration.cpp \ tests_image.cpp \ tests_image_pipeline.cpp \ + tests_motor.cpp \ tests_row_buffer.cpp \ tests_utilities.cpp diff --git a/testsuite/backend/genesys/tests.cpp b/testsuite/backend/genesys/tests.cpp index 4c172ddea..5fe00844d 100644 --- a/testsuite/backend/genesys/tests.cpp +++ b/testsuite/backend/genesys/tests.cpp @@ -30,6 +30,7 @@ int main() genesys::test_calibration_parsing(); genesys::test_image(); genesys::test_image_pipeline(); + genesys::test_motor(); genesys::test_row_buffer(); genesys::test_utilities(); return finish_tests(); diff --git a/testsuite/backend/genesys/tests.h b/testsuite/backend/genesys/tests.h index 3459c2b02..c48c58606 100644 --- a/testsuite/backend/genesys/tests.h +++ b/testsuite/backend/genesys/tests.h @@ -28,6 +28,7 @@ namespace genesys { void test_calibration_parsing(); void test_image(); void test_image_pipeline(); +void test_motor(); void test_row_buffer(); void test_utilities(); diff --git a/testsuite/backend/genesys/tests_motor.cpp b/testsuite/backend/genesys/tests_motor.cpp new file mode 100644 index 000000000..443b51802 --- /dev/null +++ b/testsuite/backend/genesys/tests_motor.cpp @@ -0,0 +1,165 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Povilas Kanapickas + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. +*/ + +#define DEBUG_DECLARE_ONLY + +#include "tests.h" +#include "minigtest.h" +#include "tests_printers.h" + +#include "../../../backend/genesys/low.h" +#include "../../../backend/genesys/enums.h" + +namespace genesys { + +void test_create_slope_table() +{ + Genesys_Motor_Slope slope; + + Genesys_Motor motor; + motor.id = MotorId::CANON_LIDE_200; + motor.base_ydpi = 1200; + motor.optical_ydpi = 6400; + + slope = Genesys_Motor_Slope(); // full step + slope.maximum_start_speed = 10000; + slope.maximum_speed = 1000; + slope.minimum_steps = 20; + slope.g = 0.80; + motor.slopes.push_back(slope); + + slope = Genesys_Motor_Slope(); // half step + slope.maximum_start_speed = 10000; + slope.maximum_speed = 1000; + slope.minimum_steps = 20; + slope.g = 0.80; + motor.slopes.push_back(slope); + + slope = Genesys_Motor_Slope(); // quarter step 0.75*2712 + slope.maximum_start_speed = 10000; + slope.maximum_speed = 1000; + slope.minimum_steps = 16; + slope.g = 0.80f; + motor.slopes.push_back(slope); + + unsigned used_steps = 0; + unsigned final_exposure = 0; + unsigned sum_time = 0; + std::vector slope_table; + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::FULL, + 10000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 10000u); + ASSERT_EQ(used_steps, 1u); + ASSERT_EQ(final_exposure, 10000u); + + std::vector expected_steps = { + 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, + 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, + }; + + ASSERT_EQ(slope_table, expected_steps); + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::FULL, + 2000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 98183u); + ASSERT_EQ(used_steps, 18u); + ASSERT_EQ(final_exposure, 1766u); + + expected_steps = { + 10000, 9146, 8513, 7944, 7412, 6906, 6421, 5951, 5494, 5049, + 4614, 4187, 3768, 3356, 2950, 2550, 2156, 1766, 1766, 1766, + }; + + ASSERT_EQ(slope_table, expected_steps); + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::HALF, + 10000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 5000u); + ASSERT_EQ(used_steps, 1u); + ASSERT_EQ(final_exposure, 5000u); + + expected_steps = { + 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, + 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, + }; + + ASSERT_EQ(slope_table, expected_steps); + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::HALF, + 2000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 72131u); + ASSERT_EQ(used_steps, 20u); + ASSERT_EQ(final_exposure, 2575u); + + expected_steps = { + 5000, 4759, 4581, 4421, 4272, 4129, 3993, 3861, 3732, 3607, + 3485, 3365, 3247, 3131, 3017, 2904, 2793, 2684, 2575, 2575, + }; + + ASSERT_EQ(slope_table, expected_steps); + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::QUARTER, + 10000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 2500u); + ASSERT_EQ(used_steps, 1u); + ASSERT_EQ(final_exposure, 2500u); + + expected_steps = { + 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, + 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, + }; + + ASSERT_EQ(slope_table, expected_steps); + + sum_time = sanei_genesys_create_slope_table3(motor, slope_table, 20, 20, StepType::QUARTER, + 2000, motor.base_ydpi, &used_steps, + &final_exposure); + + ASSERT_EQ(sum_time, 40503u); + ASSERT_EQ(used_steps, 20u); + ASSERT_EQ(final_exposure, 1674u); + + expected_steps = { + 2500, 2418, 2357, 2303, 2252, 2203, 2157, 2112, 2068, 2025, + 1983, 1943, 1902, 1863, 1824, 1786, 1748, 1711, 1674, 1674, + }; + + ASSERT_EQ(slope_table, expected_steps); +} + +void test_motor() +{ + test_create_slope_table(); +} + +} // namespace genesys