[sane-devel] [PATCH] [RFC] add sanei_usb test program

Paul Menzel paulepanter at users.sourceforge.net
Mon Mar 18 14:31:40 UTC 2013


Dear Stef,


sorry that it took me so long to reply.


Am Samstag, den 16.03.2013, 11:11 +0100 schrieb Stef:

[…]

>     it is a handy format that ease the review process. I'll consider it 
> for another occasion if there is a consensus on receiving sometimes 
> about 12 mails and on raising the mail size limit (one of the patches is 
> ~40k if inlined).
> For this time I'd appreciate that you comment on the patches with their 
> current form.

I edited the patch right away. You can save this message and apply it
with `git am --scissors patch/to/file`.

Some typos, grammar, return value comments and coding style [1] is
hopefully improved. Here is the diff.

$ git diff stefs-patch stefs-patch-my > /tmp/git-diff-stef-and-my-changes.diff
diff --git a/testsuite/sanei/Makefile.am b/testsuite/sanei/Makefile.am
index a05108e..49c1a97 100644
--- a/testsuite/sanei/Makefile.am
+++ b/testsuite/sanei/Makefile.am
@@ -1,11 +1,11 @@
 ##  Makefile.am -- an automake template for Makefile.in file
 ##  Copyright (C) 2009 Chris Bagwell and Sane Developers.
 ##
-##  This file is part of the "Sane" build infra-structure.  See
+##  This file is part of the "Sane" build infrastructure.  See
 ##  included LICENSE file for license information.
 
-MATH_LIB = @MATH_LIB@ 
-USB_LIBS = @USB_LIBS@ 
+MATH_LIB = @MATH_LIB@
+USB_LIBS = @USB_LIBS@
 PTHREAD_LIBS = @PTHREAD_LIBS@
 
 EXTRA_PROGRAMS = sanei_usb_test
@@ -19,7 +19,7 @@ clean-local:
 	rm -f sanei_usb_test
 
 all:
-	@echo "'run make tests' to run tests"
+	@echo "run 'make tests' to run tests"
 
 tests: $(EXTRA_PROGRAMS)
 	sanei_usb_test
diff --git a/testsuite/sanei/Makefile.in b/testsuite/sanei/Makefile.in
index ab92780..379ce69 100644
--- a/testsuite/sanei/Makefile.in
+++ b/testsuite/sanei/Makefile.in
@@ -162,7 +162,7 @@ MAINT = @MAINT@
 MAKEINDEX = @MAKEINDEX@
 MAKEINFO = @MAKEINFO@
 MANIFEST_TOOL = @MANIFEST_TOOL@
-MATH_LIB = @MATH_LIB@ 
+MATH_LIB = @MATH_LIB@
 MKDIR_P = @MKDIR_P@
 MSGFMT = @MSGFMT@
 MSGMERGE = @MSGMERGE@
@@ -202,7 +202,7 @@ STRIP = @STRIP@
 SYSLOG_LIBS = @SYSLOG_LIBS@
 SYSTEMD_LIBS = @SYSTEMD_LIBS@
 TIFF_LIBS = @TIFF_LIBS@
-USB_LIBS = @USB_LIBS@ 
+USB_LIBS = @USB_LIBS@
 VERSION = @VERSION@
 V_MAJOR = @V_MAJOR@
 V_MINOR = @V_MINOR@
@@ -300,7 +300,7 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
-sanei_usb_test$(EXEEXT): $(sanei_usb_test_OBJECTS) $(sanei_usb_test_DEPENDENCIES) $(EXTRA_sanei_usb_test_DEPENDENCIES) 
+sanei_usb_test$(EXEEXT): $(sanei_usb_test_OBJECTS) $(sanei_usb_test_DEPENDENCIES) $(EXTRA_sanei_usb_test_DEPENDENCIES)
 	@rm -f sanei_usb_test$(EXEEXT)
 	$(LINK) $(sanei_usb_test_OBJECTS) $(sanei_usb_test_LDADD) $(LIBS)
 
diff --git a/testsuite/sanei/README b/testsuite/sanei/README
index fba421e..7b8af5b 100644
--- a/testsuite/sanei/README
+++ b/testsuite/sanei/README
@@ -1,8 +1,8 @@
 SANEI test suite
 ===============
-St\E9phane Voltz <stef.dev at free.fr>
+Stéphane Voltz <stef.dev at free.fr>
 
-This directory contains tests programs for sanei functions. They are compiled 
+This directory contains test programs for sanei functions. They are compiled
 and run by 'make tests'.
 
 sanei_usb tested functions, at least one USB scanner needs to be plugged:
diff --git a/testsuite/sanei/sanei_usb_test.c b/testsuite/sanei/sanei_usb_test.c
index 8cd45dd..d7541f7 100644
--- a/testsuite/sanei/sanei_usb_test.c
+++ b/testsuite/sanei/sanei_usb_test.c
@@ -30,7 +30,7 @@
 #include "../../include/_stdint.h"
 
 /*
- * In order to avoid modifying sanei_usb.c to allow for unit tests
+ * In order to avoid modifying sanei_usb.c to be suitable for unit tests
  * we include it so we can use its private variables and structures
  * and still test the code.
  */
@@ -40,102 +40,102 @@
 /** test sanei_usb_init()
  * calls sanei_usb_init
  * @param expected expected use count
- * @return 0 on success, else 1
+ * @return 0 on success, else 1 or 2
  */
-static int test_init(int expected)
+static int test_init (int expected)
 {
   /* initialize USB */
-  printf("%s starting ...\n", __FUNCTION__);
+  printf ("%s starting ...\n", __FUNCTION__);
   sanei_usb_init ();
-  if (initialized==0)
+  if (initialized == 0)
     {
-      printf("ERROR: sanei_usb not initialized!\n");
+      printf ("ERROR: sanei_usb not initialized!\n");
       return 1;
     }
   if (initialized != expected)
     {
-      printf("ERROR: incorrect use count, expected %d, got %d!\n",expected, initialized);
+      printf ("ERROR: incorrect use count, expected %d, got %d!\n", expected, initialized);
       return 2;
     }
-  
-  printf("sanei_usb initialized, use count is %d ...\n", initialized);
-  printf("%s success\n\n", __FUNCTION__);
+
+  printf ("sanei_usb initialized, use count is %d ...\n", initialized);
+  printf ("%s success\n\n", __FUNCTION__);
   return 0;
 }
 
 /** test sanei_usb_exit()
  * calls sanei_usb_exit
  * @param expected use count after exit call
- * @return 0 on success, else 1
+ * @return 0 on success, else 2
  */
-static int test_exit(int expected)
+static int test_exit (int expected)
 {
-  printf("%s starting ...\n", __FUNCTION__);
+  printf ("%s starting ...\n", __FUNCTION__);
 
   /* end of USB use test */
   sanei_usb_exit ();
   if (initialized != expected)
     {
-      printf("ERROR: incorrect use count, expected %d, got %d!\n",expected, initialized);
+      printf ("ERROR: incorrect use count, expected %d, got %d!\n", expected, initialized);
       return 2;
     }
-  
-  printf("%s success\n\n", __FUNCTION__);
+
+  printf ("%s success\n\n", __FUNCTION__);
   return 0;
 }
 
 
 /** count detected devices
- * count al opended devices and check i against expected value
+ * count all opened devices and check it against expected value
  * @param expected use opened count
  * @return 0 on success, else 3
  */
-static int count_detected(int expected)
+static int count_detected (int expected)
 {
-  int num=0;
+  int num = 0;
   int i;
 
   for (i = 0; i < device_number; i++)
     {
-      if(devices[i].missing==0 && devices[i].devname!=NULL
-         && devices[i].open==SANE_TRUE)
+      if (devices[i].missing == 0 && devices[i].devname != NULL
+          && devices[i].open == SANE_TRUE)
         {
           num++;
         }
     }
-  if(num!=expected)
+  if (num != expected)
     {
-      printf("ERROR: %d detected devices, expected %d!\n", num, expected);
+      printf ("ERROR: %d detected devices, expected %d!\n", num, expected);
       return 3;
     }
-  printf("%d devices still detected.\n", num);
+  printf ("%d devices still detected.\n", num);
   return 0;
 }
 
 /** count opened devices
- * count al opended devices and check i against expected value
+ * count all opended devices and check it against expected value
  * @param expected use opened count
  * @return 0 on success, else 3
  */
-static int count_opened(int expected)
+static int count_opened (int expected)
 {
-  int num=0;
+  int num = 0;
   int i;
 
   for (i = 0; i < device_number; i++)
     {
-      if(devices[i].missing==0 && devices[i].devname!=NULL
-         && devices[i].open==SANE_TRUE)
+      if (devices[i].missing == 0 && devices[i].devname != NULL
+          && devices[i].open == SANE_TRUE)
         {
           num++;
         }
     }
-  if(num!=expected)
+  if(num != expected)
     {
-      printf("ERROR: %d opened devices, expected %d!\n", num, expected);
+      printf ("ERROR: %d opened devices, expected %d!\n", num, expected);
       return 3;
     }
-  printf("%d devices still opened.\n", num);
+  printf ("%d devices still opened.\n", num);
   return 0;
 }
 
@@ -145,7 +145,7 @@ static int count_opened(int expected)
  * @param expected number of devices to be opened
  * @return 0 on success, else error value
  */
-static int test_open_all(SANE_Int *dn,int expected)
+static int test_open_all (SANE_Int *dn, int expected)
 {
   int opened = 0;
   int i;
@@ -189,7 +189,7 @@ static int test_open_all(SANE_Int *dn,int expected)
  * @param expected number of devices to be closed
  * @return 0 on success, else error value
  */
-static int test_close_all(SANE_Int *dn, int expected)
+static int test_close_all (SANE_Int *dn, int expected)
 {
   int closed = 0;
   int i;
@@ -224,28 +224,28 @@ static int test_id_all(void)
 {
 int i;
 SANE_Status status;
-SANE_Word vendor,product;
+SANE_Word vendor, product;
 
   /* loop on detected devices and open them */
   for (i = 0; i < device_number; i++)
     {
-      if(devices[i].missing==0 && devices[i].devname!=NULL)
+      if (devices[i].missing == 0 && devices[i].devname != NULL)
         {
           /* open device */
-          status=sanei_usb_get_vendor_product_byname (devices[i].devname,
-                                                     &vendor,
-                                                     &product);
-          if(status!=SANE_STATUS_GOOD)
+          status = sanei_usb_get_vendor_product_byname (devices[i].devname,
+                                                        &vendor,
+                                                        &product);
+          if (status != SANE_STATUS_GOOD)
             {
-              printf("ERROR: couldn't query device %s!\n",devices[i].devname);
+              printf("ERROR: couldn't query device %s!\n", devices[i].devname);
               return 5;
             }
-          if(vendor==0 || product==0)
+          if (vendor == 0 || product == 0)
             {
-              printf("ERROR: incomplete device id for %s!\n",devices[i].devname);
+              printf("ERROR: incomplete device id for %s!\n", devices[i].devname);
               return 5;
             }
-          printf("%s is %04x:%04x\n",devices[i].devname,vendor,product);
+          printf("%s is %04x:%04x\n",devices[i].devname, vendor, product);
         }
     }
   printf("\n");
@@ -259,98 +259,98 @@ int rc, detected, i;
 SANE_Int dn[MAX_DEVICES];
 
   /* start sanei_usb */
-  rc=test_init(1);
-  if(rc!=0)
+  rc = test_init(1);
+  if (rc != 0)
     {
       return rc;
     }
 
   /* count available devices */
-  detected=0;
+  detected = 0;
   for (i = 0; i < device_number; i++)
     {
-      if(devices[i].missing==0 && devices[i].devname!=NULL)
+      if (devices[i].missing == 0 && devices[i].devname != NULL)
         {
           detected++;
         }
     }
-  printf("%d devices found.\n", detected);
- 
-  /* get vendor/product id for all available devices */ 
-  rc=test_id_all();
-  if(rc!=0)
+  printf ("%d devices found.\n", detected);
+
+  /* get vendor/product id for all available devices */
+  rc = test_id_all();
+  if (rc != 0)
     {
       return rc;
     }
- 
-  /* open all available devices */ 
-  rc=test_open_all(dn, detected);
-  if(rc!=0)
+
+  /* open all available devices */
+  rc=test_open_all (dn, detected);
+  if (rc != 0)
     {
       return rc;
     }
- 
-  /* increase use count */ 
-  rc=test_init(2);
-  if(rc!=0)
+
+  /* increase use count */
+  rc = test_init (2);
+  if (rc != 0)
     {
       return rc;
     }
-  
+
   /* there should be still as many detected devices */
-  rc=count_detected(detected);
-  if(rc!=0)
+  rc = count_detected (detected);
+  if (rc != 0)
     {
       return rc;
     }
-  
-  /* there should be still as many opened devices than detected devices */
-  rc=count_opened(detected);
-  if(rc!=0)
+
+  /* there should be still as many opened devices as detected devices */
+  rc = count_opened(detected);
+  if (rc != 0)
     {
       return rc;
     }
 
-  rc=test_exit(1);
-  if(rc!=0)
+  rc = test_exit (1);
+  if (rc != 0)
     {
       return rc;
     }
-  
-  /* there should be still as many opened devices than detected devices */
-  rc=count_opened(detected);
-  if(rc!=0)
+
+  /* there should be still as many opened devices as detected devices */
+  rc = count_opened (detected);
+  if (rc != 0)
     {
       return rc;
     }
-  
+
   /* count devices again , sanei_usb_exit() shouldn't have
-   * change the count */
-  
+   * changed the count */
+
   /* close all opened devices */
-  rc=test_close_all(dn, detected);
-  if(rc!=0)
+  rc = test_close_all (dn, detected);
+  if (rc != 0)
     {
       return rc;
     }
 
   /* check there is no opened device */
-  rc=count_opened(0);
-  if(rc!=0)
+  rc = count_opened (0);
+  if (rc != 0)
     {
       return rc;
     }
 
   /* finally free resources */
-  rc=test_exit(0);
-  if(rc!=0)
+  rc = test_exit (0);
+  if (rc != 0)
     {
       return rc;
     }
 
-  /* check there is no more devices */
-  rc=count_detected(0);
-  if(rc!=0)
+  /* check there are no more devices */
+  rc = count_detected (0);
+  if (rc != 0)
     {
       return rc;
     }


Thanks,

Paul

[1] http://www.gnu.org/prep/standards/standards.html#Formatting

--- 8< ---- >8 ---
From 6da19a0055349a211385855fa4a7d197106de86a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Voltz?= <stef.dev at free.fr>
Date: Wed, 6 Mar 2013 22:12:12 +0100
Subject: [PATCH] Add test sanei_usb_test to testsuite/sanei

1. Add test program for sanei_usb
2. Add testsuite/sanei subdirectory
3. Add sanei_usb_test.c for testing sanei_usb functions
---
 configure                        |    3 +-
 configure.in                     |    2 +-
 testsuite/sanei/Makefile.am      |   25 ++
 testsuite/sanei/Makefile.in      |  555 ++++++++++++++++++++++++++++++++++++++
 testsuite/sanei/README           |   13 +
 testsuite/sanei/sanei_usb_test.c |  361 +++++++++++++++++++++++++
 6 files changed, 957 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/sanei/Makefile.am
 create mode 100644 testsuite/sanei/Makefile.in
 create mode 100644 testsuite/sanei/README
 create mode 100644 testsuite/sanei/sanei_usb_test.c

diff --git a/configure b/configure
index 69ec329..0c853a4 100755
--- a/configure
+++ b/configure
@@ -18095,7 +18095,7 @@ fi
 DISTCLEAN_FILES="*~ .*~ *.log *.bak *.old *.orig *.out *.rej \"\#\"* \".\\#\"*"
 
 
-ac_config_files="$ac_config_files Makefile lib/Makefile sanei/Makefile frontend/Makefile japi/Makefile backend/Makefile include/Makefile doc/Makefile po/Makefile testsuite/Makefile tools/Makefile doc/doxygen-sanei.conf doc/doxygen-genesys.conf"
+ac_config_files="$ac_config_files Makefile lib/Makefile sanei/Makefile frontend/Makefile japi/Makefile backend/Makefile include/Makefile doc/Makefile po/Makefile testsuite/Makefile testsuite/sanei/Makefile tools/Makefile doc/doxygen-sanei.conf doc/doxygen-genesys.conf"
 
 ac_config_files="$ac_config_files tools/sane-config"
 
@@ -19167,6 +19167,7 @@ do
     "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;;
     "po/Makefile") CONFIG_FILES="$CONFIG_FILES po/Makefile" ;;
     "testsuite/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;;
+    "testsuite/sanei/Makefile") CONFIG_FILES="$CONFIG_FILES testsuite/sanei/Makefile" ;;
     "tools/Makefile") CONFIG_FILES="$CONFIG_FILES tools/Makefile" ;;
     "doc/doxygen-sanei.conf") CONFIG_FILES="$CONFIG_FILES doc/doxygen-sanei.conf" ;;
     "doc/doxygen-genesys.conf") CONFIG_FILES="$CONFIG_FILES doc/doxygen-genesys.conf" ;;
diff --git a/configure.in b/configure.in
index 90fc7c9..a9fc01c 100644
--- a/configure.in
+++ b/configure.in
@@ -772,7 +772,7 @@ AC_SUBST(DISTCLEAN_FILES)
 
 AC_CONFIG_FILES([Makefile lib/Makefile sanei/Makefile frontend/Makefile \
   japi/Makefile backend/Makefile include/Makefile doc/Makefile \
-  po/Makefile testsuite/Makefile tools/Makefile doc/doxygen-sanei.conf doc/doxygen-genesys.conf])
+  po/Makefile testsuite/Makefile testsuite/sanei/Makefile tools/Makefile doc/doxygen-sanei.conf doc/doxygen-genesys.conf])
 AC_CONFIG_FILES([tools/sane-config], [chmod a+x tools/sane-config])
 AC_CONFIG_FILES([tools/sane-backends.pc])
 AC_OUTPUT
diff --git a/testsuite/sanei/Makefile.am b/testsuite/sanei/Makefile.am
new file mode 100644
index 0000000..49c1a97
--- /dev/null
+++ b/testsuite/sanei/Makefile.am
@@ -0,0 +1,25 @@
+##  Makefile.am -- an automake template for Makefile.in file
+##  Copyright (C) 2009 Chris Bagwell and Sane Developers.
+##
+##  This file is part of the "Sane" build infrastructure.  See
+##  included LICENSE file for license information.
+
+MATH_LIB = @MATH_LIB@
+USB_LIBS = @USB_LIBS@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+
+EXTRA_PROGRAMS = sanei_usb_test
+
+AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
+
+sanei_usb_test_SOURCES = sanei_usb_test.c
+sanei_usb_test_LDADD = ../../sanei/libsanei.la ../../lib/liblib.la ../../lib/libfelib.la $(MATH_LIB) $(USB_LIBS) $(PTHREAD_LIBS)
+
+clean-local:
+	rm -f sanei_usb_test
+
+all:
+	@echo "run 'make tests' to run tests"
+
+tests: $(EXTRA_PROGRAMS)
+	sanei_usb_test
diff --git a/testsuite/sanei/Makefile.in b/testsuite/sanei/Makefile.in
new file mode 100644
index 0000000..379ce69
--- /dev/null
+++ b/testsuite/sanei/Makefile.in
@@ -0,0 +1,555 @@
+# Makefile.in generated by automake 1.11.5 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+EXTRA_PROGRAMS = sanei_usb_test$(EXEEXT)
+subdir = testsuite/sanei
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/stdint.m4 $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/include/sane/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am_sanei_usb_test_OBJECTS = sanei_usb_test.$(OBJEXT)
+sanei_usb_test_OBJECTS = $(am_sanei_usb_test_OBJECTS)
+am__DEPENDENCIES_1 =
+sanei_usb_test_DEPENDENCIES = ../../sanei/libsanei.la \
+	../../lib/liblib.la ../../lib/libfelib.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
+DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)/include/sane
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(sanei_usb_test_SOURCES)
+DIST_SOURCES = $(sanei_usb_test_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AVAHI_CFLAGS = @AVAHI_CFLAGS@
+AVAHI_LIBS = @AVAHI_LIBS@
+AWK = @AWK@
+BACKENDS = @BACKENDS@
+BACKEND_CONFS_ENABLED = @BACKEND_CONFS_ENABLED@
+BACKEND_LIBS_ENABLED = @BACKEND_LIBS_ENABLED@
+BACKEND_MANS_ENABLED = @BACKEND_MANS_ENABLED@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DISTCLEAN_FILES = @DISTCLEAN_FILES@
+DLLTOOL = @DLLTOOL@
+DL_LIBS = @DL_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+DVIPS = @DVIPS@
+DYNAMIC_FLAG = @DYNAMIC_FLAG@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GPHOTO2_CPPFLAGS = @GPHOTO2_CPPFLAGS@
+GPHOTO2_LDFLAGS = @GPHOTO2_LDFLAGS@
+GPHOTO2_LIBS = @GPHOTO2_LIBS@
+GREP = @GREP@
+HAVE_GPHOTO2 = @HAVE_GPHOTO2@
+IEEE1284_LIBS = @IEEE1284_LIBS@
+INCLUDES = @INCLUDES@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_LOCKPATH = @INSTALL_LOCKPATH@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+JPEG_LIBS = @JPEG_LIBS@
+LATEX = @LATEX@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBUSB_1_0_CFLAGS = @LIBUSB_1_0_CFLAGS@
+LIBUSB_1_0_LIBS = @LIBUSB_1_0_LIBS@
+LIBV4L_CFLAGS = @LIBV4L_CFLAGS@
+LIBV4L_LIBS = @LIBV4L_LIBS@
+LINKER_RPATH = @LINKER_RPATH@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOCKPATH_GROUP = @LOCKPATH_GROUP@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINDEX = @MAKEINDEX@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MATH_LIB = @MATH_LIB@
+MKDIR_P = @MKDIR_P@
+MSGFMT = @MSGFMT@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+NUMBER_VERSION = @NUMBER_VERSION@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PRELOADABLE_BACKENDS = @PRELOADABLE_BACKENDS@
+PRELOADABLE_BACKENDS_ENABLED = @PRELOADABLE_BACKENDS_ENABLED@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+RANLIB = @RANLIB@
+RESMGR_LIBS = @RESMGR_LIBS@
+SANEI_SANEI_JPEG_LO = @SANEI_SANEI_JPEG_LO@
+SANE_CONFIG_PATH = @SANE_CONFIG_PATH@
+SCSI_LIBS = @SCSI_LIBS@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SNMP_CONFIG_PATH = @SNMP_CONFIG_PATH@
+SOCKET_LIBS = @SOCKET_LIBS@
+STRICT_LDFLAGS = @STRICT_LDFLAGS@
+STRIP = @STRIP@
+SYSLOG_LIBS = @SYSLOG_LIBS@
+SYSTEMD_LIBS = @SYSTEMD_LIBS@
+TIFF_LIBS = @TIFF_LIBS@
+USB_LIBS = @USB_LIBS@
+VERSION = @VERSION@
+V_MAJOR = @V_MAJOR@
+V_MINOR = @V_MINOR@
+V_REV = @V_REV@
+XGETTEXT = @XGETTEXT@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+configdir = @configdir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+locksanedir = @locksanedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
+sanei_usb_test_SOURCES = sanei_usb_test.c
+sanei_usb_test_LDADD = ../../sanei/libsanei.la ../../lib/liblib.la ../../lib/libfelib.la $(MATH_LIB) $(USB_LIBS) $(PTHREAD_LIBS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu testsuite/sanei/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu testsuite/sanei/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+sanei_usb_test$(EXEEXT): $(sanei_usb_test_OBJECTS) $(sanei_usb_test_DEPENDENCIES) $(EXTRA_sanei_usb_test_DEPENDENCIES)
+	@rm -f sanei_usb_test$(EXEEXT)
+	$(LINK) $(sanei_usb_test_OBJECTS) $(sanei_usb_test_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/sanei_usb_test.Po at am__quote@
+
+.c.o:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+ at am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ at am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+ at am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-local mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-libtool clean-local ctags distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am
+
+
+clean-local:
+	rm -f sanei_usb_test
+
+all:
+	@echo "'run make tests' to run tests"
+
+tests: $(EXTRA_PROGRAMS)
+	sanei_usb_test
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/testsuite/sanei/README b/testsuite/sanei/README
new file mode 100644
index 0000000..7b8af5b
--- /dev/null
+++ b/testsuite/sanei/README
@@ -0,0 +1,13 @@
+SANEI test suite
+===============
+Stéphane Voltz <stef.dev at free.fr>
+
+This directory contains test programs for sanei functions. They are compiled
+and run by 'make tests'.
+
+sanei_usb tested functions, at least one USB scanner needs to be plugged:
+	- sanei_usb_init()
+	- sanei_usb_open()
+	- sanei_usb_get_vendor_product_byname()
+	- sanei_usb_close()
+	- sanei_usb_exit()
diff --git a/testsuite/sanei/sanei_usb_test.c b/testsuite/sanei/sanei_usb_test.c
new file mode 100644
index 0000000..d7541f7
--- /dev/null
+++ b/testsuite/sanei/sanei_usb_test.c
@@ -0,0 +1,361 @@
+#include "../../include/sane/config.h"
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <math.h>
+#include <stddef.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_MKDIR
+#include <sys/stat.h>
+#include <sys/types.h>
+#endif
+
+#define BACKEND_NAME	sanei_usb
+
+#include "../../include/sane/sane.h"
+#include "../../include/sane/sanei.h"
+#include "../../include/sane/saneopts.h"
+
+#include "../../include/sane/sanei_backend.h"
+#include "../../include/sane/sanei_usb.h"
+
+#include "../../include/_stdint.h"
+
+/*
+ * In order to avoid modifying sanei_usb.c to be suitable for unit tests
+ * we include it so we can use its private variables and structures
+ * and still test the code.
+ */
+#include "../../sanei/sanei_usb.c"
+
+
+/** test sanei_usb_init()
+ * calls sanei_usb_init
+ * @param expected expected use count
+ * @return 0 on success, else 1 or 2
+ */
+static int test_init (int expected)
+{
+  /* initialize USB */
+  printf ("%s starting ...\n", __FUNCTION__);
+  sanei_usb_init ();
+  if (initialized == 0)
+    {
+      printf ("ERROR: sanei_usb not initialized!\n");
+      return 1;
+    }
+  if (initialized != expected)
+    {
+      printf ("ERROR: incorrect use count, expected %d, got %d!\n", expected, initialized);
+      return 2;
+    }
+
+  printf ("sanei_usb initialized, use count is %d ...\n", initialized);
+  printf ("%s success\n\n", __FUNCTION__);
+  return 0;
+}
+
+/** test sanei_usb_exit()
+ * calls sanei_usb_exit
+ * @param expected use count after exit call
+ * @return 0 on success, else 2
+ */
+static int test_exit (int expected)
+{
+  printf ("%s starting ...\n", __FUNCTION__);
+
+  /* end of USB use test */
+  sanei_usb_exit ();
+  if (initialized != expected)
+    {
+      printf ("ERROR: incorrect use count, expected %d, got %d!\n", expected, initialized);
+      return 2;
+    }
+
+  printf ("%s success\n\n", __FUNCTION__);
+  return 0;
+}
+
+
+/** count detected devices
+ * count all opened devices and check it against expected value
+ * @param expected use opened count
+ * @return 0 on success, else 3
+ */
+static int count_detected (int expected)
+{
+  int num = 0;
+  int i;
+
+  for (i = 0; i < device_number; i++)
+    {
+      if (devices[i].missing == 0 && devices[i].devname != NULL
+          && devices[i].open == SANE_TRUE)
+        {
+          num++;
+        }
+    }
+  if (num != expected)
+    {
+      printf ("ERROR: %d detected devices, expected %d!\n", num, expected);
+      return 3;
+    }
+  printf ("%d devices still detected.\n", num);
+  return 0;
+}
+
+/** count opened devices
+ * count all opended devices and check it against expected value
+ * @param expected use opened count
+ * @return 0 on success, else 3
+ */
+static int count_opened (int expected)
+{
+  int num = 0;
+  int i;
+
+  for (i = 0; i < device_number; i++)
+    {
+      if (devices[i].missing == 0 && devices[i].devname != NULL
+          && devices[i].open == SANE_TRUE)
+        {
+          num++;
+        }
+    }
+  if(num != expected)
+    {
+      printf ("ERROR: %d opened devices, expected %d!\n", num, expected);
+      return 3;
+    }
+  printf ("%d devices still opened.\n", num);
+  return 0;
+}
+
+/** open all devices
+ * loop on all existing devices and open them
+ * @param dn array to store opened device number
+ * @param expected number of devices to be opened
+ * @return 0 on success, else error value
+ */
+static int test_open_all (SANE_Int *dn, int expected)
+{
+  int opened = 0;
+  int i;
+  int rc;
+  SANE_Status status;
+
+  /* loop on detected devices and open them */
+  for (i = 0; i < device_number; i++)
+    {
+      if (devices[i].missing == 0 && devices[i].devname != NULL)
+	{
+	  /* open device */
+	  status = sanei_usb_open (devices[i].devname, dn + opened);
+	  if (status == SANE_STATUS_GOOD)
+	    {
+	      opened++;
+	    }
+	  else
+	    {
+	      printf ("ERROR: couldn't open device %s!\n",
+		      devices[i].devname);
+	      return 4;
+	    }
+	}
+    }
+  printf ("opened %d devices\n", opened);
+
+  /* there should be as many opened devices than detected devices */
+  rc = count_opened (expected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+  printf ("\n");
+  return 0;
+}
+
+/** close all devices
+ * loop on all opened devices and close them
+ * @param dn array of opened device number
+ * @param expected number of devices to be closed
+ * @return 0 on success, else error value
+ */
+static int test_close_all (SANE_Int *dn, int expected)
+{
+  int closed = 0;
+  int i;
+  int rc;
+
+  /* loop on detected devices and open them */
+  for (i = 0; i < expected; i++)
+    {
+      /* close device */
+      sanei_usb_close (dn[i]);
+      closed++;
+    }
+  printf ("closed %d devices\n", closed);
+
+  /* there should be any more opened devices */
+  rc = count_opened (0);
+  if (rc != 0)
+    {
+      return rc;
+    }
+  printf ("\n");
+  return 0;
+}
+
+/** get id for all devices
+ * loop on all existing devices and get vendor
+ * and product id.
+ * @param expected count
+ * @return 0 on success, else error value
+ */
+static int test_id_all(void)
+{
+int i;
+SANE_Status status;
+SANE_Word vendor, product;
+
+  /* loop on detected devices and open them */
+  for (i = 0; i < device_number; i++)
+    {
+      if (devices[i].missing == 0 && devices[i].devname != NULL)
+        {
+          /* open device */
+          status = sanei_usb_get_vendor_product_byname (devices[i].devname,
+                                                        &vendor,
+                                                        &product);
+          if (status != SANE_STATUS_GOOD)
+            {
+              printf("ERROR: couldn't query device %s!\n", devices[i].devname);
+              return 5;
+            }
+          if (vendor == 0 || product == 0)
+            {
+              printf("ERROR: incomplete device id for %s!\n", devices[i].devname);
+              return 5;
+            }
+          printf("%s is %04x:%04x\n",devices[i].devname, vendor, product);
+        }
+    }
+  printf("\n");
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+int rc, detected, i;
+SANE_Int dn[MAX_DEVICES];
+
+  /* start sanei_usb */
+  rc = test_init(1);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* count available devices */
+  detected = 0;
+  for (i = 0; i < device_number; i++)
+    {
+      if (devices[i].missing == 0 && devices[i].devname != NULL)
+        {
+          detected++;
+        }
+    }
+  printf ("%d devices found.\n", detected);
+
+  /* get vendor/product id for all available devices */
+  rc = test_id_all();
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* open all available devices */
+  rc=test_open_all (dn, detected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* increase use count */
+  rc = test_init (2);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* there should be still as many detected devices */
+  rc = count_detected (detected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* there should be still as many opened devices as detected devices */
+  rc = count_opened(detected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  rc = test_exit (1);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* there should be still as many opened devices as detected devices */
+  rc = count_opened (detected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* count devices again , sanei_usb_exit() shouldn't have
+   * changed the count */
+
+  /* close all opened devices */
+  rc = test_close_all (dn, detected);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* check there is no opened device */
+  rc = count_opened (0);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* finally free resources */
+  rc = test_exit (0);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  /* check there are no more devices */
+  rc = count_detected (0);
+  if (rc != 0)
+    {
+      return rc;
+    }
+
+  return 0;
+}
+
+/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */
-- 
1.7.10.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20130318/dc18f705/attachment-0001.pgp>


More information about the sane-devel mailing list