diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2023-01-06 10:02:49 +0200 |
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2023-01-06 10:04:59 +0200 |
| commit | 1145733c29db0a678537ce99ff60e21613f622a8 (patch) | |
| tree | 63d5d6c324629d4eef1354db3c97f857d6016a34 /backend/tests | |
| download | iscan-1145733c29db0a678537ce99ff60e21613f622a8.tar.gz | |
Import iscan 2.30.4-2
Diffstat (limited to 'backend/tests')
| -rw-r--r-- | backend/tests/45532d48333030.xml | 28 | ||||
| -rw-r--r-- | backend/tests/47542d58393730.xml | 38 | ||||
| -rw-r--r-- | backend/tests/50657266656374696f6e363130.xml | 27 | ||||
| -rw-r--r-- | backend/tests/Makefile.am | 79 | ||||
| -rw-r--r-- | backend/tests/network.c | 86 | ||||
| -rw-r--r-- | backend/tests/test-cfg-obj.cc | 60 | ||||
| -rw-r--r-- | backend/tests/test-cfg-obj.hh | 254 | ||||
| -rw-r--r-- | backend/tests/test-model-info.cc | 83 | ||||
| -rw-r--r-- | backend/tests/test-model-info.hh | 241 | ||||
| -rw-r--r-- | backend/tests/test-net-obj.cc | 35 | ||||
| -rw-r--r-- | backend/tests/test-net-obj.hh | 126 | ||||
| -rwxr-xr-x | backend/tests/xmltest-runner.sh | 87 | ||||
| -rw-r--r-- | backend/tests/xmltest.c | 247 | ||||
| -rw-r--r-- | backend/tests/xmltest.h | 190 |
14 files changed, 1581 insertions, 0 deletions
diff --git a/backend/tests/45532d48333030.xml b/backend/tests/45532d48333030.xml new file mode 100644 index 0000000..e7d6a04 --- /dev/null +++ b/backend/tests/45532d48333030.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<scanner_entry> + + <interfaces> + <usb vendor="04b8" product="012b"/> + <net status="unsupported" note="option"/> + </interfaces> + + <device> + <firmware name="ES-H300"/> + <model name="GT-2500"/> + <model name="ES-H300" region="japan"/> + </device> + + <profile-set> + <profile type="reflective"> + <rr value=" 1.0359"/><rg value="-0.0146"/><rb value="-0.0213"/> + <gr value="-0.0752"/><gg value=" 1.0963"/><gb value="-0.0211"/> + <br value="-0.0456"/><bg value="-0.3238"/><bb value=" 1.3693"/> + </profile> + </profile-set> + + <command-set type="extended" level="B8"> + <command name="set_focus_position" code="1B70" status="disabled"/> + <command name="feed" code="19" status="disabled"/> + </command-set> + +</scanner_entry> diff --git a/backend/tests/47542d58393730.xml b/backend/tests/47542d58393730.xml new file mode 100644 index 0000000..26cb7e7 --- /dev/null +++ b/backend/tests/47542d58393730.xml @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<scanner_entry> + + <interfaces> + <usb vendor="04b8" product="012b"/> + <net status="unsupported" note="option"/> + </interfaces> + + <profile-set> + <profile type="reflective"> + <rr value=" 1.1978"/><rg value="-0.1417"/><rb value="-0.0561"/> + <gr value="-0.0852"/><gg value=" 1.161"/><gb value="-0.0758"/> + <br value="-0.0395"/><bg value="-0.3212"/><bb value=" 1.3607"/> + </profile> + <profile type="color negative"> + <rr value=" 1.000"/><rg value="0.0009"/><rb value="-0.0009"/> + <gr value="-0.1268"/><gg value=" 1.0523"/><gb value="0.0745"/> + <br value="-0.0075"/><bg value="-0.0873"/><bb value=" 1.0948"/> + </profile> + <profile type="positive"> + <rr value=" 1.4475"/><rg value="-0.3957"/><rb value="-0.0518"/> + <gr value="-0.0138"/><gg value=" 1.0644"/><gb value="-0.0506"/> + <br value="-0.0199"/><bg value="-0.205"/><bb value=" 1.2249"/> + </profile> + </profile-set> + + <device> + <firmware name="GT-X970"/> + </device> + + <command-set type="extended" level="B8"> + <command name="set_focus_position" code="1B70" status="disabled"/> + <command name="feed" code="19" status="disabled"/> + <command name="lock"/> + <command name="unlock"/> + </command-set> + +</scanner_entry> diff --git a/backend/tests/50657266656374696f6e363130.xml b/backend/tests/50657266656374696f6e363130.xml new file mode 100644 index 0000000..2ac6c46 --- /dev/null +++ b/backend/tests/50657266656374696f6e363130.xml @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<scanner_entry> + + <interfaces> + <usb vendor="04b8" product="012b"/> + <net status="unsupported" note="option"/> + </interfaces> + + <device> + <firmware name="Perfection610"/> + <model name="Perfection 610"/> + </device> + + <profile-set> + <profile type="reflective"> + <rr value=" 1.1442"/><rg value="-0.0705"/><rb value="-0.0737"/> + <gr value="-0.0702"/><gg value=" 1.1013"/><gb value="-0.0311"/> + <br value="-0.0080"/><bg value="-0.3588"/><bb value=" 1.3668"/> + </profile> + </profile-set> + + <command-set type="extended" level="B8"> + <command name="set_focus_position" code="1B70" status="disabled"/> + <command name="feed" code="19" status="disabled"/> + </command-set> + +</scanner_entry> diff --git a/backend/tests/Makefile.am b/backend/tests/Makefile.am new file mode 100644 index 0000000..ef275d1 --- /dev/null +++ b/backend/tests/Makefile.am @@ -0,0 +1,79 @@ +## Makefile.am -- an -*- automake -*- template for Makefile.in +## Copyright (C) 2008 SEIKO EPSON CORPORATION +## +## License: GPLv2+ +## Authors: AVASYS CORPORATION +## +## This file is part of the "Image Scan!" build infra-structure. +## +## The "Image Scan!" build infra-structure 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 ought to have received a copy of the GNU General Public License +## along with this package. If not, see <http://www.gnu.org/licenses/>. + + +AM_CPPFLAGS = $(XML_CFLAGS) + +check_PROGRAMS = \ + xmltest + +TESTS = + +xmltest_LDADD = ../libepkowa.la +xmltest_SOURCES = xmltest.c xmltest.h + +EXTRA_DIST = \ + 47542d58393730.xml \ + 45532d48333030.xml \ + 50657266656374696f6e363130.xml \ + xmltest-runner.sh + +if HAVE_CXXTESTGEN + +check_PROGRAMS += \ + cfg-obj \ + net-obj \ + network \ + model-info + +TESTS += \ + cfg-obj \ + net-obj \ + model-info + +cfg_obj_LDADD = ../libepkowa.la +cfg_obj_SOURCES = \ + test-cfg-obj.cc \ + test-cfg-obj.hh + +net_obj_LDADD = ../libepkowa.la +net_obj_SOURCES = \ + test-net-obj.cc \ + test-net-obj.hh + +model_info_LDADD = ../libepkowa.la +model_info_SOURCES = \ + test-model-info.cc \ + test-model-info.hh + +# Use the CxxTest code generator on all files matching test-*.hh to +# create the corresponding test-*.cc file. This convention is used +# so that we can still use regular source code without this getting +# clobbered as soon as we change the header file. + +.hh.cc: + @if test xtest- = "x`echo $^ | sed -n 's|^\(test-\).*|\1|p'`"; \ + then \ + echo "$(CXXTESTGEN) $(CXXTESTGEN_OPTS) -o $@ $^"; \ + $(CXXTESTGEN) $(CXXTESTGEN_OPTS) -o $@ $^; \ + fi + +endif ## HAVE_CXXTESTGEN diff --git a/backend/tests/network.c b/backend/tests/network.c new file mode 100644 index 0000000..8dd6dec --- /dev/null +++ b/backend/tests/network.c @@ -0,0 +1,86 @@ +/* network.c -- a network mock program for use by unit tests + * Copyright (C) 2008 SEIKO EPSON CORPORATION + * + * License: GPLv2+ + * Authors: AVASYS CORPORATION + * + * This file is part of Image Scan!'s SANE backend test suite. + * + * Image Scan!'s SANE backend test suite 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 ought to have received a copy of the GNU General Public License + * along with this package. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <arpa/inet.h> +#include <netinet/in.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <unistd.h> + +int +main (int argc, char *argv[]) +{ + socklen_t n; + int r; + int s; + int as; + struct sockaddr_in addr; + + s = socket (AF_INET, SOCK_STREAM, 0); + if (0 > s) + { + perror ("socket"); + return EXIT_FAILURE; + } + + memset (&addr, 0, sizeof (addr)); + addr.sin_family = PF_INET; + addr.sin_port = 0; + addr.sin_addr.s_addr = INADDR_ANY; + + r = bind (s, (struct sockaddr *) &addr, sizeof (addr)); + if (0 > r) + { + perror ("bind"); + return EXIT_FAILURE; + } + + n = sizeof (addr); + r = getsockname (s, (struct sockaddr *) &addr, &n); + if (0 > r) + { + perror ("getsockname"); + return EXIT_FAILURE; + } + + setvbuf (stdout, NULL, _IONBF, BUFSIZ); + fprintf (stdout, "%d\n", ntohs (addr.sin_port)); + fclose (stdout); /* not strictly needed */ + + listen (s, 0); + as = accept (s, (struct sockaddr*) &addr, (socklen_t*) &n); + + pause (); + + close (s); + close (as); + + return EXIT_SUCCESS; +} diff --git a/backend/tests/test-cfg-obj.cc b/backend/tests/test-cfg-obj.cc new file mode 100644 index 0000000..9fe213f --- /dev/null +++ b/backend/tests/test-cfg-obj.cc @@ -0,0 +1,60 @@ +/* Generated file, do not edit */ + +#ifndef CXXTEST_RUNNING +#define CXXTEST_RUNNING +#endif + +#define _CXXTEST_HAVE_STD +#include <cxxtest/TestListener.h> +#include <cxxtest/TestTracker.h> +#include <cxxtest/TestRunner.h> +#include <cxxtest/RealDescriptions.h> +#include <cxxtest/ErrorPrinter.h> + +int main() { + return CxxTest::ErrorPrinter().run(); +} +#include "test-cfg-obj.hh" + +static test_cfg_obj suite_test_cfg_obj; + +static CxxTest::List Tests_test_cfg_obj = { 0, 0 }; +CxxTest::StaticSuiteDescription suiteDescription_test_cfg_obj( "test-cfg-obj.hh", 89, "test_cfg_obj", suite_test_cfg_obj, Tests_test_cfg_obj ); + +static class TestDescription_test_cfg_obj_test_life_cycle : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_life_cycle() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 93, "test_life_cycle" ) {} + void runTest() { suite_test_cfg_obj.test_life_cycle(); } +} testDescription_test_cfg_obj_test_life_cycle; + +static class TestDescription_test_cfg_obj_test_life_cycle_status : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_life_cycle_status() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 102, "test_life_cycle_status" ) {} + void runTest() { suite_test_cfg_obj.test_life_cycle_status(); } +} testDescription_test_cfg_obj_test_life_cycle_status; + +static class TestDescription_test_cfg_obj_test_key_query : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_key_query() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 115, "test_key_query" ) {} + void runTest() { suite_test_cfg_obj.test_key_query(); } +} testDescription_test_cfg_obj_test_key_query; + +static class TestDescription_test_cfg_obj_test_option_value_query : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_option_value_query() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 123, "test_option_value_query" ) {} + void runTest() { suite_test_cfg_obj.test_option_value_query(); } +} testDescription_test_cfg_obj_test_option_value_query; + +static class TestDescription_test_cfg_obj_test_key_mutator : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_key_mutator() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 134, "test_key_mutator" ) {} + void runTest() { suite_test_cfg_obj.test_key_mutator(); } +} testDescription_test_cfg_obj_test_key_mutator; + +static class TestDescription_test_cfg_obj_test_net_registration : public CxxTest::RealTestDescription { +public: + TestDescription_test_cfg_obj_test_net_registration() : CxxTest::RealTestDescription( Tests_test_cfg_obj, suiteDescription_test_cfg_obj, 146, "test_net_registration" ) {} + void runTest() { suite_test_cfg_obj.test_net_registration(); } +} testDescription_test_cfg_obj_test_net_registration; + +#include <cxxtest/Root.cpp> diff --git a/backend/tests/test-cfg-obj.hh b/backend/tests/test-cfg-obj.hh new file mode 100644 index 0000000..ab8b851 --- /dev/null +++ b/backend/tests/test-cfg-obj.hh @@ -0,0 +1,254 @@ +// test-cfg-obj.hh -- test suite for configuration objects +// Copyright (C) 2008 SEIKO EPSON CORPORATION +// +// License: GPLv2+|iscan +// Authors: AVASYS CORPORATION +// +// This file is part of Image Scan!'s SANE backend test suite. +// +// Image Scan!'s SANE backend test suite 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 ought to have received a copy of the GNU General Public License +// along with this package. If not, see <http://www.gnu.org/licenses/>. +// +// +// Linking Image Scan!'s SANE backend statically or dynamically with +// other modules is making a combined work based on this SANE backend. +// Thus, the terms and conditions of the GNU General Public License +// cover the whole combination. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// SANE frontends that communicate with Image Scan!'s SANE backend +// solely through the SANE Application Programming Interface, +// regardless of the license terms of these SANE frontends, and to +// copy and distribute the resulting combined work under terms of your +// choice, provided that every copy of the combined work is +// accompanied by a complete copy of the source code of Image Scan!'s +// SANE backend (the version of Image Scan!'s SANE backend used to +// produce the combined work), being distributed under the terms of +// the GNU General Public License plus this exception. An independent +// module is a module which is not derived from or based on Image +// Scan!'s SANE backend. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// independent modules that communicate with Image Scan!'s SANE +// backend solely through the "Interpreter" interface, regardless of +// the license terms of these independent modules, and to copy and +// distribute the resulting combined work under terms of your choice, +// provided that every copy of the combined work is accompanied by a +// complete copy of the source code of Image Scan!'s SANE backend (the +// version of Image Scan!'s SANE backend used to produce the combined +// work), being distributed under the terms of the GNU General Public +// License plus this exception. An independent module is a module +// which is not derived from or based on Image Scan!'s SANE backend. +// +// Note that people who make modified versions of Image Scan!'s SANE +// backend are not obligated to grant special exceptions for their +// modified versions; it is their choice whether to do so. The GNU +// General Public License gives permission to release a modified +// version without this exception; this exception also makes it +// possible to release a modified version which carries forward this +// exception. + + +#ifndef included_test_cfg_obj_hh +#define included_test_cfg_obj_hh + +#ifndef __cplusplus +#error "This is a C++ include file. Use a C++ compiler to compile" +#error "code that includes this file." +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "../cfg-obj.h" +#include <cxxtest/TestSuite.h> + +#include <cerrno> +#include <cstdlib> +#include <cstring> +#include <fstream> +#include <string> +#include <unistd.h> + +#include "../message.h" + + +class test_cfg_obj : public CxxTest::TestSuite +{ +public: + + void test_life_cycle (void) + { + cfg = cfg_init (dir.c_str (), NULL); + TS_ASSERT (cfg); + + cfg = cfg_exit (cfg); + TS_ASSERT (!cfg); + } + + void test_life_cycle_status (void) + { + SANE_Status status = SANE_STATUS_NO_MEM; + + cfg = cfg_init (dir.c_str (), &status); + TS_ASSERT (cfg); + + TS_ASSERT (SANE_STATUS_NO_MEM != status); + + cfg = cfg_exit (cfg); + TS_ASSERT (!cfg); + } + + void test_key_query (void) + { + cfg = cfg_init (dir.c_str (), NULL); + TS_ASSERT (cfg); + + TS_ASSERT (cfg_has (cfg, CFG_KEY_USB)); + } + + void test_option_value_query (void) + { + cfg = cfg_init (dir.c_str (), NULL); + TS_ASSERT (cfg); + + TS_ASSERT (cfg_has (cfg, CFG_KEY_OPTION)); + TS_ASSERT (cfg_has_value (cfg, CFG_KEY_OPTION, "prefer-adf")); + TS_ASSERT (!cfg_has_value (cfg, CFG_KEY_OPTION, "not-a-valid-option")); + TS_ASSERT (!cfg_has_value (cfg, CFG_KEY_OPTION, "not-in-config")); + } + + void test_key_mutator (void) + { + cfg = cfg_init (dir.c_str (), NULL); + TS_ASSERT (cfg); + + TS_ASSERT (cfg_has (cfg, CFG_KEY_USB)); + cfg_set (cfg, CFG_KEY_USB, false); + TS_ASSERT (!cfg_has (cfg, CFG_KEY_USB)); + cfg_set (cfg, CFG_KEY_USB, true); + TS_ASSERT (cfg_has (cfg, CFG_KEY_USB)); + } + + void test_net_registration (void) + { + add_cfg_entry ("net\n"); + + cfg = cfg_init (dir.c_str (), NULL); + TS_ASSERT (!cfg_has (cfg, CFG_KEY_NET)); + } + +private: + + void *cfg; + std::string dir; + + /*! Create a temporary, minimal configuration directory. + + The configuration directory is made available to the unit test + environment via the \c SANE_CONFIG_DIR environment variable so + configuration objects (should) take note. In addition, a very + minimal configuration file, containing the \c usb keyword and + a few options is created in this directory as well. + */ + void setUp (void) + { + int result; + msg_init (); + + char dirname_template[] = ".cfg-obj-XXXXXX"; + char *dirname = mkdtemp (dirname_template); + if (!dirname) + { + err_fatal ("mkdtemp: %s", strerror (errno)); + } + require (dirname); + + result = chdir (dirname); + require (0 == result); + + std::ofstream ofs (cfg_file_name); + ofs << "usb\n"; + ofs << "option prefer-adf \n"; + ofs << "option not-a-valid-option\n"; + + result = chdir (".."); + require (0 == result); + + result = setenv ("SANE_CONFIG_DIR", dirname, true); + require (0 == result); + + cfg = NULL; + dir = dirname; + } + + /*! Attempts to undo the effects of setUp(). + + The environment's \c SANE_CONFIG_DIR is unset and the temporary + configuration directory is recursively removed. Failures to + undo any of the necessary actions are logged but will not cause + a test to fail. + */ + void tearDown (void) + { + int result; + + if (0 != unsetenv ("SANE_CONFIG_DIR")) + { + err_minor ("unsetenv: %s", strerror (errno)); + } + + if (0 != chdir (dir.c_str ())) + { + err_minor ("%s: %s", dir.c_str (), strerror (errno)); + } + else + { + if (0 != unlink (cfg_file_name)) + { + err_minor ("%s: %s", cfg_file_name, strerror (errno)); + } + if (0 != unlink ("usb")) + { + err_minor ("%s: %s", "usb", strerror (errno)); + } + result = chdir (".."); + require (0 == result); + } + + if (0 != rmdir (dir.c_str ())) + { + err_minor ("%s: %s", dir.c_str (), strerror (errno)); + } + dir = ""; + + cfg = cfg_exit (cfg); + promise (!cfg); + } + + void add_cfg_entry (const char *str) + { + chdir (dir.c_str ()); + std::ofstream ofs (cfg_file_name, + std::ios_base::out | std::ios_base::app); + + ofs << str; + chdir (".."); + } +}; + + +#endif /* !defined (included_test_cfg_obj_hh) */ diff --git a/backend/tests/test-model-info.cc b/backend/tests/test-model-info.cc new file mode 100644 index 0000000..bb5eb7e --- /dev/null +++ b/backend/tests/test-model-info.cc @@ -0,0 +1,83 @@ +/* Generated file, do not edit */ + +#ifndef CXXTEST_RUNNING +#define CXXTEST_RUNNING +#endif + +#define _CXXTEST_HAVE_STD +#include <cxxtest/TestListener.h> +#include <cxxtest/TestTracker.h> +#include <cxxtest/TestRunner.h> +#include <cxxtest/RealDescriptions.h> +#include <cxxtest/ErrorPrinter.h> + +int main() { + return CxxTest::ErrorPrinter().run(); +} +#include "test-model-info.hh" + +static test_model_cache_info suite_test_model_cache_info; + +static CxxTest::List Tests_test_model_cache_info = { 0, 0 }; +CxxTest::StaticSuiteDescription suiteDescription_test_model_cache_info( "test-model-info.hh", 111, "test_model_cache_info", suite_test_model_cache_info, Tests_test_model_cache_info ); + +static class TestDescription_test_model_cache_info_test_cache_life_cycle : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_cache_info_test_cache_life_cycle() : CxxTest::RealTestDescription( Tests_test_model_cache_info, suiteDescription_test_model_cache_info, 115, "test_cache_life_cycle" ) {} + void runTest() { suite_test_model_cache_info.test_cache_life_cycle(); } +} testDescription_test_model_cache_info_test_cache_life_cycle; + +static class TestDescription_test_model_cache_info_test_cache_life_cycle_status : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_cache_info_test_cache_life_cycle_status() : CxxTest::RealTestDescription( Tests_test_model_cache_info, suiteDescription_test_model_cache_info, 124, "test_cache_life_cycle_status" ) {} + void runTest() { suite_test_model_cache_info.test_cache_life_cycle_status(); } +} testDescription_test_model_cache_info_test_cache_life_cycle_status; + +static class TestDescription_test_model_cache_info_test_cache_unique_entries : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_cache_info_test_cache_unique_entries() : CxxTest::RealTestDescription( Tests_test_model_cache_info, suiteDescription_test_model_cache_info, 137, "test_cache_unique_entries" ) {} + void runTest() { suite_test_model_cache_info.test_cache_unique_entries(); } +} testDescription_test_model_cache_info_test_cache_unique_entries; + +static test_model_info suite_test_model_info; + +static CxxTest::List Tests_test_model_info = { 0, 0 }; +CxxTest::StaticSuiteDescription suiteDescription_test_model_info( "test-model-info.hh", 154, "test_model_info", suite_test_model_info, Tests_test_model_info ); + +static class TestDescription_test_model_info_test_get_non_existent_model : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_get_non_existent_model() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 158, "test_get_non_existent_model" ) {} + void runTest() { suite_test_model_info.test_get_non_existent_model(); } +} testDescription_test_model_info_test_get_non_existent_model; + +static class TestDescription_test_model_info_test_get_non_existent_info : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_get_non_existent_info() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 165, "test_get_non_existent_info" ) {} + void runTest() { suite_test_model_info.test_get_non_existent_info(); } +} testDescription_test_model_info_test_get_non_existent_info; + +static class TestDescription_test_model_info_test_get_info_from_loaded_cache : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_get_info_from_loaded_cache() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 171, "test_get_info_from_loaded_cache" ) {} + void runTest() { suite_test_model_info.test_get_info_from_loaded_cache(); } +} testDescription_test_model_info_test_get_info_from_loaded_cache; + +static class TestDescription_test_model_info_test_get_existing_model : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_get_existing_model() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 186, "test_get_existing_model" ) {} + void runTest() { suite_test_model_info.test_get_existing_model(); } +} testDescription_test_model_info_test_get_existing_model; + +static class TestDescription_test_model_info_test_default_values : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_default_values() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 195, "test_default_values" ) {} + void runTest() { suite_test_model_info.test_default_values(); } +} testDescription_test_model_info_test_default_values; + +static class TestDescription_test_model_info_test_profile_equality_values : public CxxTest::RealTestDescription { +public: + TestDescription_test_model_info_test_profile_equality_values() : CxxTest::RealTestDescription( Tests_test_model_info, suiteDescription_test_model_info, 207, "test_profile_equality_values" ) {} + void runTest() { suite_test_model_info.test_profile_equality_values(); } +} testDescription_test_model_info_test_profile_equality_values; + +#include <cxxtest/Root.cpp> diff --git a/backend/tests/test-model-info.hh b/backend/tests/test-model-info.hh new file mode 100644 index 0000000..1796b03 --- /dev/null +++ b/backend/tests/test-model-info.hh @@ -0,0 +1,241 @@ +// test-model-info.hh -- test suite for model info objects +// Copyright (C) 2010 SEIKO EPSON CORPORATION +// +// License: GPLv2+|iscan +// Authors: AVASYS CORPORATION +// +// This file is part of Image Scan!'s SANE backend test suite. +// +// Image Scan!'s SANE backend test suite 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 ought to have received a copy of the GNU General Public License +// along with this package. If not, see <http://www.gnu.org/licenses/>. +// +// +// Linking Image Scan!'s SANE backend statically or dynamically with +// other modules is making a combined work based on this SANE backend. +// Thus, the terms and conditions of the GNU General Public License +// cover the whole combination. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// SANE frontends that communicate with Image Scan!'s SANE backend +// solely through the SANE Application Programming Interface, +// regardless of the license terms of these SANE frontends, and to +// copy and distribute the resulting combined work under terms of your +// choice, provided that every copy of the combined work is +// accompanied by a complete copy of the source code of Image Scan!'s +// SANE backend (the version of Image Scan!'s SANE backend used to +// produce the combined work), being distributed under the terms of +// the GNU General Public License plus this exception. An independent +// module is a module which is not derived from or based on Image +// Scan!'s SANE backend. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// independent modules that communicate with Image Scan!'s SANE +// backend solely through the "Interpreter" interface, regardless of +// the license terms of these independent modules, and to copy and +// distribute the resulting combined work under terms of your choice, +// provided that every copy of the combined work is accompanied by a +// complete copy of the source code of Image Scan!'s SANE backend (the +// version of Image Scan!'s SANE backend used to produce the combined +// work), being distributed under the terms of the GNU General Public +// License plus this exception. An independent module is a module +// which is not derived from or based on Image Scan!'s SANE backend. +// +// Note that people who make modified versions of Image Scan!'s SANE +// backend are not obligated to grant special exceptions for their +// modified versions; it is their choice whether to do so. The GNU +// General Public License gives permission to release a modified +// version without this exception; this exception also makes it +// possible to release a modified version which carries forward this +// exception. + + +#ifndef included_test_model_info_hh +#define included_test_model_info_hh + +#ifndef __cplusplus +#error "This is a C++ include file. Use a C++ compiler to compile" +#error "code that includes this file." +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "../model-info.h" +#include <cxxtest/TestSuite.h> + +#include <cstdlib> +#include <cstring> +#include <string> + +#include "../list.h" +#include "../message.h" +#include "../get-infofile.h" + +struct base +{ + std::string dir; + void *cache; + + void setUp (void) + { + // Log at least broken promises and unmet requirements. + setenv ("SANE_DEBUG_EPKOWA", "FATAL", false); + msg_init (); + + char *srcdir = getenv ("srcdir"); + dir = (srcdir ? srcdir : "."); + + cache = NULL; + } + + void tearDown (void) + { + cache = model_info_cache_exit (cache); + promise (!cache); + } +}; + +class test_model_cache_info : public CxxTest::TestSuite, public base +{ +public: + + void test_cache_life_cycle (void) + { + cache = model_info_cache_init (dir.c_str (), NULL); + TS_ASSERT (cache); + + cache = model_info_cache_exit (cache); + TS_ASSERT (!cache); + } + + void test_cache_life_cycle_status (void) + { + SANE_Status status = SANE_STATUS_NO_MEM; + + cache = model_info_cache_init (dir.c_str (), &status); + TS_ASSERT (cache); + + TS_ASSERT (SANE_STATUS_NO_MEM != status); + + cache = model_info_cache_exit (cache); + TS_ASSERT (!cache); + } + + void test_cache_unique_entries (void) + { + cache = model_info_cache_init (dir.c_str (), NULL); + TS_ASSERT (cache); + + for (int i = 0; i < 10; ++i) { + model_info_cache_get_info ("GT-X970", NULL); + model_info_cache_get_info ("ES-H300", NULL); + } + TS_ASSERT_EQUALS (2, list_size (static_cast<list *> (cache))); + } + +private: + void setUp (void) { base::setUp (); } + void tearDown (void) { base::setUp (); } +}; + +class test_model_info : public CxxTest::TestSuite, public base +{ +public: + + void test_get_non_existent_model (void) + { + char *model = model_info_cache_get_model (bad_fw_name); + TS_ASSERT_EQUALS (std::string (model), std::string (bad_fw_name)); + free (model); + } + + void test_get_non_existent_info (void) + { + const void *info = model_info_cache_get_info (bad_fw_name, NULL); + TS_ASSERT (info); + } + + void test_get_info_from_loaded_cache (void) + { + // load cache + model_info_cache_get_info (bad_fw_name, NULL); + model_info_cache_get_info ("GT-X970", NULL); // XML data + model_info_cache_get_info ("ES-H300", NULL); // XML data + + // get info + const void *info = model_info_cache_get_info ("GT-X970", NULL); + TS_ASSERT (info); + TS_ASSERT (model_info_cache_get_info ("ES-H300", NULL)); + TS_ASSERT (model_info_cache_get_info (bad_fw_name, NULL)); + TS_ASSERT_EQUALS (info, model_info_cache_get_info ("GT-X970", NULL)); + } + + void test_get_existing_model (void) + { + setenv ("TZ", "", true); // force UTC, i.e. overseas model name + + char *model = model_info_cache_get_model ("ES-H300"); + TS_ASSERT_EQUALS (std::string ("GT-2500"), std::string (model)); + free (model); + } + + void test_default_values (void) + { + const void *p = model_info_cache_get_info (bad_fw_name, NULL); + + const char *name = model_info_get_name (p); + TS_ASSERT_EQUALS (std::string (bad_fw_name), std::string (name)); + + const EpsonScanHard profile = model_info_get_profile (p); + TS_ASSERT_SAME_DATA (profile, &epson_scan_hard[0], + sizeof (profile)); + } + + void test_profile_equality_values (void) + { + // Identical models but for their fw_names. + const void *p1 = model_info_cache_get_info ("GT-10000", NULL); + const void *p2 = model_info_cache_get_info ("ES-6000", NULL); + + TS_ASSERT_DIFFERS (p1, p2); + TS_ASSERT_SAME_DATA (model_info_get_profile (p1), + model_info_get_profile (p2), + sizeof (const EpsonScanHard)); + } + +private: + + // A firmware name that is guaranteed not to be used. + static const char *bad_fw_name; + + void setUp (void) + { + base::setUp (); + cache = model_info_cache_init (dir.c_str (), NULL); + TS_ASSERT (cache); + // The ESC/I spec has a 16 byte limit on the F/W name. + TS_ASSERT (16 < strlen (bad_fw_name)); + } + + void tearDown (void) + { + base::tearDown (); + } +}; + +const char * test_model_info::bad_fw_name = " __ BAD F/W NAME __ "; + +#endif /* !defined (included_test_model_info_hh) */ diff --git a/backend/tests/test-net-obj.cc b/backend/tests/test-net-obj.cc new file mode 100644 index 0000000..c43610d --- /dev/null +++ b/backend/tests/test-net-obj.cc @@ -0,0 +1,35 @@ +/* Generated file, do not edit */ + +#ifndef CXXTEST_RUNNING +#define CXXTEST_RUNNING +#endif + +#include <cxxtest/TestListener.h> +#include <cxxtest/TestTracker.h> +#include <cxxtest/TestRunner.h> +#include <cxxtest/RealDescriptions.h> +#include <cxxtest/ErrorPrinter.h> + +int main() { + return CxxTest::ErrorPrinter().run(); +} +#include "test-net-obj.hh" + +static test_net_obj suite_test_net_obj; + +static CxxTest::List Tests_test_net_obj = { 0, 0 }; +CxxTest::StaticSuiteDescription suiteDescription_test_net_obj( "test-net-obj.hh", 88, "test_net_obj", suite_test_net_obj, Tests_test_net_obj ); + +static class TestDescription_test_net_obj_test_lifecycle : public CxxTest::RealTestDescription { +public: + TestDescription_test_net_obj_test_lifecycle() : CxxTest::RealTestDescription( Tests_test_net_obj, suiteDescription_test_net_obj, 92, "test_lifecycle" ) {} + void runTest() { suite_test_net_obj.test_lifecycle(); } +} testDescription_test_net_obj_test_lifecycle; + +static class TestDescription_test_net_obj_test_missing_program : public CxxTest::RealTestDescription { +public: + TestDescription_test_net_obj_test_missing_program() : CxxTest::RealTestDescription( Tests_test_net_obj, suiteDescription_test_net_obj, 100, "test_missing_program" ) {} + void runTest() { suite_test_net_obj.test_missing_program(); } +} testDescription_test_net_obj_test_missing_program; + +#include <cxxtest/Root.cpp> diff --git a/backend/tests/test-net-obj.hh b/backend/tests/test-net-obj.hh new file mode 100644 index 0000000..ef0c557 --- /dev/null +++ b/backend/tests/test-net-obj.hh @@ -0,0 +1,126 @@ +// test-net-obj.hh -- test suite for network objects +// Copyright (C) 2008 SEIKO EPSON CORPORATION +// +// License: GPLv2+|iscan +// Authors: AVASYS CORPORATION +// +// This file is part of Image Scan!'s SANE backend test suite. +// +// Image Scan!'s SANE backend test suite 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 ought to have received a copy of the GNU General Public License +// along with this package. If not, see <http://www.gnu.org/licenses/>. +// +// +// Linking Image Scan!'s SANE backend statically or dynamically with +// other modules is making a combined work based on this SANE backend. +// Thus, the terms and conditions of the GNU General Public License +// cover the whole combination. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// SANE frontends that communicate with Image Scan!'s SANE backend +// solely through the SANE Application Programming Interface, +// regardless of the license terms of these SANE frontends, and to +// copy and distribute the resulting combined work under terms of your +// choice, provided that every copy of the combined work is +// accompanied by a complete copy of the source code of Image Scan!'s +// SANE backend (the version of Image Scan!'s SANE backend used to +// produce the combined work), being distributed under the terms of +// the GNU General Public License plus this exception. An independent +// module is a module which is not derived from or based on Image +// Scan!'s SANE backend. +// +// As a special exception, the copyright holders of Image Scan!'s SANE +// backend give you permission to link Image Scan!'s SANE backend with +// independent modules that communicate with Image Scan!'s SANE +// backend solely through the "Interpreter" interface, regardless of +// the license terms of these independent modules, and to copy and +// distribute the resulting combined work under terms of your choice, +// provided that every copy of the combined work is accompanied by a +// complete copy of the source code of Image Scan!'s SANE backend (the +// version of Image Scan!'s SANE backend used to produce the combined +// work), being distributed under the terms of the GNU General Public +// License plus this exception. An independent module is a module +// which is not derived from or based on Image Scan!'s SANE backend. +// +// Note that people who make modified versions of Image Scan!'s SANE +// backend are not obligated to grant special exceptions for their +// modified versions; it is their choice whether to do so. The GNU +// General Public License gives permission to release a modified +// version without this exception; this exception also makes it +// possible to release a modified version which carries forward this +// exception. + + +#ifndef included_test_net_obj_hh +#define included_test_net_obj_hh + +#ifndef __cplusplus +#error "This is a C++ include file. Use a C++ compiler to compile" +#error "code that includes this file." +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "../net-obj.h" + +#include <cxxtest/TestSuite.h> + +#include <cerrno> +#include <cstdlib> +#include <cstring> +#include <unistd.h> + +#include "../message.h" + + +class test_net_obj : public CxxTest::TestSuite +{ +public: + + void test_lifecycle (void) + { + void *net = net_init (get_current_dir_name (), NULL); + TS_ASSERT (net); + net = net_exit (net); + TS_ASSERT (!net); + } + + void test_missing_program (void) + { + char dirname_template[] = "network-XXXXXX"; + char *dirname = mkdtemp (dirname_template); + TS_ASSERT (dirname); + + void *net = net_init (dirname, NULL); + TS_ASSERT (!net); + net = net_exit (net); + TS_ASSERT (!net); + + if (0 != rmdir (dirname)) + { + err_minor ("%s: %s", dirname, strerror (errno)); + } + } + +private: + + void setUp (void) + { + msg_init (); + } +}; + + +#endif /* !defined (included_test_net_obj_hh) */ diff --git a/backend/tests/xmltest-runner.sh b/backend/tests/xmltest-runner.sh new file mode 100755 index 0000000..8bc3383 --- /dev/null +++ b/backend/tests/xmltest-runner.sh @@ -0,0 +1,87 @@ +#! /bin/sh + +test_result=PASS + +run_test () { + ./xmltest "$@" + if test 0 = $?; then + echo "PASS: xmltest $@" + else + echo "FAIL: xmltest $@" + test_result=FAIL + fi +} + +run_test GT-X970 +run_test PM-A820 +run_test EP-210F +run_test GT-X970 ES-H300 +run_test GT-X970 LP-M5600 +run_test LP-M5600 PM-A820 +run_test PM-A820 GT-X970 +run_test GT-X970 GT-X970 +run_test LP-M5600 LP-M5600 +run_test EP-210F hoge +run_test GT-X970 hoge +run_test PM-A820 MAN +run_test EP-210F ES-H300 +run_test EP-210F LP-M5600 +run_test GT-X970 ES-H300 Perfection610 +run_test GT-X970 ES-H300 PM-A820 +run_test GT-X970 ES-H300 MAN +run_test GT-X970 LP-M5600 Perfection610 +run_test GT-X970 LP-M5600 CX4600 +run_test GT-X970 LP-M5600 EP-210F +run_test ES-H300 hoge GT-X970 +run_test ES-H300 hoge PM-A820 +run_test ES-H300 hoge EP-210F +run_test PM-A820 LP-M5600 CX4600 +run_test PM-A820 LP-M5600 GT-X970 +run_test PM-A820 LP-M5600 MAN +run_test LP-M5600 Perfection610 GT-X970 +run_test LP-M5600 Perfection610 PM-A820 +run_test LP-M5600 Perfection610 EP-210F +run_test LP-M5600 EP-210F GT-X970 +run_test LP-M5600 EP-210F CX4600 +run_test LP-M5600 EP-210F MAN +run_test EP-210F MAN hoge +run_test EP-210F MAN ES-H300 +run_test EP-210F MAN LP-M5600 +run_test EP-210F GT-X970 ES-H300 +run_test EP-210F GT-X970 PM-A820 +run_test EP-210F GT-X970 hoge +run_test EP-210F CX4600 Perfection610 +run_test EP-210F CX4600 PM-A820 +run_test EP-210F CX4600 hoge +run_test ES-H300 ES-H300 ES-H300 +run_test PM-A820 PM-A820 PM-A820 +run_test GT-X970 GT-X970 CX4600 +run_test Perfection610 Perfection610 MAN +run_test Perfection610 Perfection610 GT-X970 +run_test LP-M5600 LP-M5600 GT-X970 +run_test LP-M5600 LP-M5600 PM-A820 +run_test CX4600 CX4600 hoge +run_test EP-210F EP-210F ES-H300 +run_test EP-210F EP-210F LP-M5600 +run_test EP-210F EP-210F MAN +run_test ES-H300 GT-X970 GT-X970 +run_test ES-H300 PM-A820 PM-A820 +run_test GT-X970 hoge hoge +run_test CX4600 Perfection610 Perfection610 +run_test PM-A820 LP-M5600 LP-M5600 +run_test LP-M5600 MAN MAN +run_test hoge GT-X970 GT-X970 +run_test MAN PM-A820 PM-A820 +run_test hoge EP-210F EP-210F +run_test GT-X970 CX4600 GT-X970 +run_test GT-X970 ES-H300 GT-X970 +run_test GT-X970 EP-210F GT-X970 +run_test PM-A820 ES-H300 PM-A820 +run_test LP-M5600 CX4600 LP-M5600 +run_test PM-A820 MAN PM-A820 +run_test hoge GT-X970 hoge +run_test EP-210F CX4600 EP-210F +run_test MAN hoge MAN + +test PASS = "$test_result" +exit $? diff --git a/backend/tests/xmltest.c b/backend/tests/xmltest.c new file mode 100644 index 0000000..0f3a277 --- /dev/null +++ b/backend/tests/xmltest.c @@ -0,0 +1,247 @@ +/* xmltest.c -- simple model cache info checker + * Copyright (C) 2010 SEIKO EPSON CORPORATION + * + * License: GPLv2+|iscan + * Authors: SEIKO EPSON CORPORATION + * AVASYS CORPORATION + * + * This file is part of the SANE backend distributed with Image Scan! + * + * Image Scan!'s SANE backend 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 ought to have received a copy of the GNU General Public License + * along with this package. If not, see <http://www.gnu.org/licenses/>. + * + * + * Linking Image Scan!'s SANE backend statically or dynamically with + * other modules is making a combined work based on this SANE backend. + * Thus, the terms and conditions of the GNU General Public License + * cover the whole combination. + * + * As a special exception, the copyright holders of Image Scan!'s SANE + * backend give you permission to link Image Scan!'s SANE backend with + * SANE frontends that communicate with Image Scan!'s SANE backend + * solely through the SANE Application Programming Interface, + * regardless of the license terms of these SANE frontends, and to + * copy and distribute the resulting combined work under terms of your + * choice, provided that every copy of the combined work is + * accompanied by a complete copy of the source code of Image Scan!'s + * SANE backend (the version of Image Scan!'s SANE backend used to + * produce the combined work), being distributed under the terms of + * the GNU General Public License plus this exception. An independent + * module is a module which is not derived from or based on Image + * Scan!'s SANE backend. + * + * As a special exception, the copyright holders of Image Scan!'s SANE + * backend give you permission to link Image Scan!'s SANE backend with + * independent modules that communicate with Image Scan!'s SANE + * backend solely through the "Interpreter" interface, regardless of + * the license terms of these independent modules, and to copy and + * distribute the resulting combined work under terms of your choice, + * provided that every copy of the combined work is accompanied by a + * complete copy of the source code of Image Scan!'s SANE backend (the + * version of Image Scan!'s SANE backend used to produce the combined + * work), being distributed under the terms of the GNU General Public + * License plus this exception. An independent module is a module + * which is not derived from or based on Image Scan!'s SANE backend. + * + * Note that people who make modified versions of Image Scan!'s SANE + * backend are not obligated to grant special exceptions for their + * modified versions; it is their choice whether to do so. The GNU + * General Public License gives permission to release a modified + * version without this exception; this exception also makes it + * possible to release a modified version which carries forward this + * exception. + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "xmltest.h" + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +#include "../list.h" +#include "../message.h" +#include "../model-info.h" +#include "../utils.h" + +static bool check_cache_content (list *info); +static bool check_info_content (const _model_info_t *info); +static bool model_info_test_cmp (const _model_info_t *info, + const _model_info_t_test *reference); + +int +main (int argc, char** argv) +{ + bool pass = false; + list *cache = NULL; + SANE_Status status = SANE_STATUS_GOOD; + + /* Log at least broken promises and unmet requirements. + */ + setenv ("SANE_DEBUG_EPKOWA", "FATAL", false); + msg_init (); + + cache = (list *) model_info_cache_init (getenv ("srcdir"), &status); + if (!cache) + { + err_fatal ("cannot initialise model info cache (%s)", + sane_strstatus (status)); + return EXIT_FAILURE; + } + + while (--argc && ++argv) + { + const void *info = model_info_cache_get_info (*argv, &status); + if (!info) + { + err_major ("cannot get info for '%s' (%s)", *argv, + sane_strstatus (status)); + } + } + + pass = check_cache_content (cache); + cache = model_info_cache_exit (cache); + + return (pass ? EXIT_SUCCESS : EXIT_FAILURE); +} + +/*! \brief Loops over all cache entries and checks each one of them. + */ +static bool +check_cache_content (list *cache) +{ + bool pass = true; + _model_info_t *info; + + list_reset (cache); + while ((info = list_next (cache))) + { + pass &= check_info_content (info); + } + return pass; +} + +/*! \brief Checks a cache entry against known good data. + * + * \note Unknown entries are skipped. + */ +static bool +check_info_content (const _model_info_t *info) +{ + if (0 == strcmp_c (info->fw_name, gt_x970.fw_name)) + return model_info_test_cmp (info, >_x970); + + if (0 == strcmp_c (info->fw_name, es_h300.fw_name)) + return model_info_test_cmp (info, &es_h300); + + if (0 == strcmp_c (info->fw_name, perfection_610.fw_name)) + return model_info_test_cmp (info, &perfection_610); + + if (0 == strcmp_c (info->fw_name, lp_m5600.fw_name)) + return model_info_test_cmp (info, &lp_m5600); + + if (0 == strcmp_c (info->fw_name, pm_a820.fw_name)) + return model_info_test_cmp (info, &pm_a820); + + if (0 == strcmp_c (info->fw_name, cx_4600.fw_name)) + return model_info_test_cmp (info, &cx_4600); + + /* cannot do remaining tests */ + printf (" SKIP: unexpected fw_name (%s)\n", info->fw_name); + return true; +} + +/*! \brief Compares \a info against a \a reference. + */ +static bool +model_info_test_cmp (const _model_info_t *info, + const _model_info_t_test *reference) +{ + bool pass = true; + int i, j; + + require (info && reference); + + /* Compare model names */ + if (0 != strcmp_c (info->overseas, reference->overseas)) + { + pass = false; + printf ("FAIL: overseas -> %s != %s\n", info->overseas, + reference->overseas); + } + + if (0 != strcmp_c (info->japan, reference->japan)) + { + pass = false; + printf ("FAIL: japan -> %s != %s\n", info->japan, reference->japan); + } + + /* Compare color profiles */ + for (i = 0; i < 4; i++) + { + for (j = 0; j < 9; j++) + { + if (info->profile->color_profile[i][j] + != reference->profile.color_profile[i][j]) + { + pass = false; + printf ("FAIL: profile[%i][%i] -> %f != %f\n", i, j, + info->profile->color_profile[i][j], + reference->profile.color_profile[i][j]); + } + } + } + + /* Compare custom command entries */ + if (info->command->set_focus_position + != reference->command.set_focus_position) + { + pass = false; + printf ("FAIL: focus -> %d != %d\n", info->command->set_focus_position, + reference->command.set_focus_position); + } + + if (info->command->feed != reference->command.feed) + { + pass = false; + printf ("FAIL: feed -> %d != %d\n", info->command->feed, + reference->command.feed); + } + + if (info->command->eject != reference->command.eject) + { + pass = false; + printf ("FAIL: eject -> %d != %d\n", info->command->eject, + reference->command.eject); + } + + if (info->command->lock != reference->command.lock) + { + pass = false; + printf ("FAIL: lock -> %d != %d\n", info->command->lock, + reference->command.lock); + } + + if (info->command->unlock != reference->command.unlock) + { + pass = false; + printf ("FAIL: unlock -> %d != %d\n", info->command->unlock, + reference->command.lock); + } + + return pass; +} diff --git a/backend/tests/xmltest.h b/backend/tests/xmltest.h new file mode 100644 index 0000000..02404e1 --- /dev/null +++ b/backend/tests/xmltest.h @@ -0,0 +1,190 @@ +/* xmltest.c -- simple model cache info checker + * Copyright (C) 2010 SEIKO EPSON CORPORATION + * + * License: GPLv2+|iscan + * Authors: SEIKO EPSON CORPORATION + * + * This file is part of the SANE backend distributed with Image Scan! + * + * Image Scan!'s SANE backend 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 ought to have received a copy of the GNU General Public License + * along with this package. If not, see <http://www.gnu.org/licenses/>. + * + * + * Linking Image Scan!'s SANE backend statically or dynamically with + * other modules is making a combined work based on this SANE backend. + * Thus, the terms and conditions of the GNU General Public License + * cover the whole combination. + * + * As a special exception, the copyright holders of Image Scan!'s SANE + * backend give you permission to link Image Scan!'s SANE backend with + * SANE frontends that communicate with Image Scan!'s SANE backend + * solely through the SANE Application Programming Interface, + * regardless of the license terms of these SANE frontends, and to + * copy and distribute the resulting combined work under terms of your + * choice, provided that every copy of the combined work is + * accompanied by a complete copy of the source code of Image Scan!'s + * SANE backend (the version of Image Scan!'s SANE backend used to + * produce the combined work), being distributed under the terms of + * the GNU General Public License plus this exception. An independent + * module is a module which is not derived from or based on Image + * Scan!'s SANE backend. + * + * As a special exception, the copyright holders of Image Scan!'s SANE + * backend give you permission to link Image Scan!'s SANE backend with + * independent modules that communicate with Image Scan!'s SANE + * backend solely through the "Interpreter" interface, regardless of + * the license terms of these independent modules, and to copy and + * distribute the resulting combined work under terms of your choice, + * provided that every copy of the combined work is accompanied by a + * complete copy of the source code of Image Scan!'s SANE backend (the + * version of Image Scan!'s SANE backend used to produce the combined + * work), being distributed under the terms of the GNU General Public + * License plus this exception. An independent module is a module + * which is not derived from or based on Image Scan!'s SANE backend. + * + * Note that people who make modified versions of Image Scan!'s SANE + * backend are not obligated to grant special exceptions for their + * modified versions; it is their choice whether to do so. The GNU + * General Public License gives permission to release a modified + * version without this exception; this exception also makes it + * possible to release a modified version which carries forward this + * exception. + */ + + +#ifndef included_xmltest_h +#define included_xmltest_h + +#include "../get-infofile.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct +{ + char *fw_name; /* key for _model_info_cache_get_info */ + char *overseas; /* model name */ + char *japan; /* model name */ + char *name; /* points to one of overseas, japan or + * fw_name, never NULL */ + scan_command_t *command; /* command customisation info */ + EpsonScanHard profile; /* colour profiles */ + + bool from_file; /* origin of our data, used to control + * which members need to be free()d at + * destruction time */ + +} _model_info_t; + +typedef struct +{ + char *fw_name; /* key for _model_info_cache_get_info */ + char *overseas; /* model name */ + char *japan; /* model name */ + + scan_command_t command; /* command customisation info */ + EpsonScanHardRec profile; /* colour profiles */ + +} _model_info_t_test; + +const _model_info_t_test gt_x970 = { + "GT-X970", + NULL, + NULL, + + {0x01, 0, 0, 0xFF, true, true}, + {0x87, + {{1.1978,-0.1417,-0.0561,-0.0852, 1.1610,-0.0758,-0.0395,-0.3212, 1.3607}, + {1.0000, 0.0009,-0.0009,-0.1268, 1.0523, 0.0745,-0.0075,-0.0873, 1.0948}, + {1.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 1.0000}, + {1.4475,-0.3957,-0.0518,-0.0138, 1.0644,-0.0506,-0.0199,-0.2050, 1.2249}}}, + +}; + +const _model_info_t_test es_h300 = { + "ES-H300", + "GT-2500", + "ES-H300", + + {0x01, 0, 0, 0xFF, false, false}, + {0x87, + {{1.0359,-0.0146,-0.0213,-0.0752, 1.0963,-0.0211,-0.0456,-0.3238, 1.3693}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}}}, + +}; + +const _model_info_t_test perfection_610 = { + "Perfection610", + "Perfection 610", + NULL, + + {0x01, 0, 0, 0xFF, false, false}, + {0x87, + {{1.1442,-0.0705,-0.0737,-0.0702, 1.1013,-0.0311,-0.0080,-0.3588, 1.3668}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}}}, + +}; + +const _model_info_t_test lp_m5600 = { + "LP-M5600", + NULL, + "LP-M5600", + + {0x01, 0, 0x19, 0xFF, false, false}, + {0x87, + {{1.0784,-0.0560,-0.0224,-0.1793, 1.2234,-0.0441,-0.0041,-0.2636, 1.2677}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}}}, + +}; + +const _model_info_t_test pm_a820 = { + "PM-A820", + "Stylus Photo RX560/RX580/RX590", + "PM-A820", + + {0x01, 0, 0, 0xFF, false, false}, + {0x87, + {{0.9533, 0.0885,-0.0418, 0.0033, 1.0627,-0.0660,-0.0137,-0.1904, 1.2041}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}}}, + +}; + +const _model_info_t_test cx_4600 = { + "CX4600", + "Stylus CX4500/CX4600", + NULL, + + {0x01, 0, 0, 0xFF, false, false}, + {0x87, + {{0.9828, 0.0924,-0.0752, 0.0255, 1.151,-0.1765, 0.0049,-0.325, 1.3201}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 0, 0, 1}}}, + +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !defined (included_xmltest_h) */ |
