1141cc406Sopenharmony_ci#include "../../include/sane/config.h" 2141cc406Sopenharmony_ci 3141cc406Sopenharmony_ci#include <stdlib.h> 4141cc406Sopenharmony_ci#include <sys/types.h> 5141cc406Sopenharmony_ci#include <sys/stat.h> 6141cc406Sopenharmony_ci#include <fcntl.h> 7141cc406Sopenharmony_ci#include <errno.h> 8141cc406Sopenharmony_ci#include <string.h> 9141cc406Sopenharmony_ci#include <assert.h> 10141cc406Sopenharmony_ci 11141cc406Sopenharmony_ci/* sane includes for the sanei functions called */ 12141cc406Sopenharmony_ci#include "../include/sane/sane.h" 13141cc406Sopenharmony_ci#include "../include/sane/saneopts.h" 14141cc406Sopenharmony_ci#include "../include/sane/sanei.h" 15141cc406Sopenharmony_ci#include "../include/sane/sanei_config.h" 16141cc406Sopenharmony_ci 17141cc406Sopenharmony_ci#define XSTR(s) STR(s) 18141cc406Sopenharmony_ci#define STR(s) #s 19141cc406Sopenharmony_ci#define CONFIG_PATH XSTR(TESTSUITE_SANEI_SRCDIR) 20141cc406Sopenharmony_ci 21141cc406Sopenharmony_ci/* 22141cc406Sopenharmony_ci * variables and functions used by the tests below 23141cc406Sopenharmony_ci */ 24141cc406Sopenharmony_ci 25141cc406Sopenharmony_ci 26141cc406Sopenharmony_ci/* range for constraint */ 27141cc406Sopenharmony_cistatic const SANE_Range model_range = { 28141cc406Sopenharmony_ci 1000, /* minimum */ 29141cc406Sopenharmony_ci 2000, /* maximum */ 30141cc406Sopenharmony_ci 2 /* quantization */ 31141cc406Sopenharmony_ci}; 32141cc406Sopenharmony_ci 33141cc406Sopenharmony_ci/* range for memory buffer size constraint */ 34141cc406Sopenharmony_cistatic const SANE_Range buffer_range = { 35141cc406Sopenharmony_ci 1024, /* minimum bytes */ 36141cc406Sopenharmony_ci 2048 * 1024, /* maximum bytes */ 37141cc406Sopenharmony_ci 1024 /* quantization */ 38141cc406Sopenharmony_ci}; 39141cc406Sopenharmony_ci 40141cc406Sopenharmony_ci/* range for int value in [0-15] */ 41141cc406Sopenharmony_cistatic const SANE_Range value16_range = { 42141cc406Sopenharmony_ci 0, /* minimum */ 43141cc406Sopenharmony_ci 15, /* maximum */ 44141cc406Sopenharmony_ci 1 /* quantization */ 45141cc406Sopenharmony_ci}; 46141cc406Sopenharmony_ci 47141cc406Sopenharmony_ci/* range for fixed height value */ 48141cc406Sopenharmony_cistatic const SANE_Range height_range = { 49141cc406Sopenharmony_ci SANE_FIX (0), /* minimum */ 50141cc406Sopenharmony_ci SANE_FIX (29.7), /* maximum */ 51141cc406Sopenharmony_ci 0 /* no quantization : hard to do for float values ... */ 52141cc406Sopenharmony_ci}; 53141cc406Sopenharmony_ci 54141cc406Sopenharmony_ci/* list of astra models */ 55141cc406Sopenharmony_cistatic const SANE_String_Const astra_models[] = 56141cc406Sopenharmony_ci { "610", "1220", "1600", "2000", NULL }; 57141cc406Sopenharmony_ci 58141cc406Sopenharmony_ci/* string list */ 59141cc406Sopenharmony_cistatic const SANE_String_Const string_list[] = 60141cc406Sopenharmony_ci { "string1", "string2", "string3", "string4", NULL }; 61141cc406Sopenharmony_ci 62141cc406Sopenharmony_ci/* last device name used for attach callback */ 63141cc406Sopenharmony_cistatic char *lastdevname = NULL; 64141cc406Sopenharmony_ci 65141cc406Sopenharmony_cistatic SANE_Status 66141cc406Sopenharmony_cicheck_config_attach (SANEI_Config * config, const char *devname, 67141cc406Sopenharmony_ci void __sane_unused__ *data) 68141cc406Sopenharmony_ci{ 69141cc406Sopenharmony_ci /* silence compiler warning for now */ 70141cc406Sopenharmony_ci if (config == NULL) 71141cc406Sopenharmony_ci { 72141cc406Sopenharmony_ci return SANE_STATUS_INVAL; 73141cc406Sopenharmony_ci } 74141cc406Sopenharmony_ci 75141cc406Sopenharmony_ci fprintf (stdout, "attaching with devname '%s'\n", devname); 76141cc406Sopenharmony_ci if (lastdevname != NULL) 77141cc406Sopenharmony_ci { 78141cc406Sopenharmony_ci free (lastdevname); 79141cc406Sopenharmony_ci } 80141cc406Sopenharmony_ci lastdevname = strdup (devname); 81141cc406Sopenharmony_ci return SANE_STATUS_GOOD; 82141cc406Sopenharmony_ci} 83141cc406Sopenharmony_ci 84141cc406Sopenharmony_ci/******************************/ 85141cc406Sopenharmony_ci/* start of tests definitions */ 86141cc406Sopenharmony_ci/******************************/ 87141cc406Sopenharmony_ci 88141cc406Sopenharmony_ci/* 89141cc406Sopenharmony_ci * non-existent config file 90141cc406Sopenharmony_ci */ 91141cc406Sopenharmony_cistatic void 92141cc406Sopenharmony_ciinexistent_config (void) 93141cc406Sopenharmony_ci{ 94141cc406Sopenharmony_ci SANE_Status status; 95141cc406Sopenharmony_ci SANEI_Config config; 96141cc406Sopenharmony_ci 97141cc406Sopenharmony_ci config.count = 0; 98141cc406Sopenharmony_ci config.descriptors = NULL; 99141cc406Sopenharmony_ci config.values = NULL; 100141cc406Sopenharmony_ci status = sanei_configure_attach (CONFIG_PATH 101141cc406Sopenharmony_ci "/data/inexistent.conf", &config, 102141cc406Sopenharmony_ci NULL, NULL); 103141cc406Sopenharmony_ci 104141cc406Sopenharmony_ci /* check results */ 105141cc406Sopenharmony_ci assert (status != SANE_STATUS_GOOD); 106141cc406Sopenharmony_ci} 107141cc406Sopenharmony_ci 108141cc406Sopenharmony_ci 109141cc406Sopenharmony_ci/* 110141cc406Sopenharmony_ci * no config struct 111141cc406Sopenharmony_ci */ 112141cc406Sopenharmony_cistatic void 113141cc406Sopenharmony_cinull_config (void) 114141cc406Sopenharmony_ci{ 115141cc406Sopenharmony_ci SANE_Status status; 116141cc406Sopenharmony_ci 117141cc406Sopenharmony_ci status = 118141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/umax_pp.conf", NULL, 119141cc406Sopenharmony_ci check_config_attach, NULL); 120141cc406Sopenharmony_ci 121141cc406Sopenharmony_ci /* check results */ 122141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 123141cc406Sopenharmony_ci} 124141cc406Sopenharmony_ci 125141cc406Sopenharmony_ci 126141cc406Sopenharmony_ci/* 127141cc406Sopenharmony_ci * no attach function 128141cc406Sopenharmony_ci */ 129141cc406Sopenharmony_cistatic void 130141cc406Sopenharmony_cinull_attach (void) 131141cc406Sopenharmony_ci{ 132141cc406Sopenharmony_ci SANE_Status status; 133141cc406Sopenharmony_ci 134141cc406Sopenharmony_ci status = sanei_configure_attach (CONFIG_PATH 135141cc406Sopenharmony_ci "/data/umax_pp.conf", NULL, NULL, NULL); 136141cc406Sopenharmony_ci 137141cc406Sopenharmony_ci /* check results */ 138141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 139141cc406Sopenharmony_ci} 140141cc406Sopenharmony_ci 141141cc406Sopenharmony_ci 142141cc406Sopenharmony_ci/* 143141cc406Sopenharmony_ci * empty config : backend has no configuration option 144141cc406Sopenharmony_ci */ 145141cc406Sopenharmony_cistatic void 146141cc406Sopenharmony_ciempty_config (void) 147141cc406Sopenharmony_ci{ 148141cc406Sopenharmony_ci SANE_Status status; 149141cc406Sopenharmony_ci SANEI_Config config; 150141cc406Sopenharmony_ci 151141cc406Sopenharmony_ci config.count = 0; 152141cc406Sopenharmony_ci config.descriptors = NULL; 153141cc406Sopenharmony_ci config.values = NULL; 154141cc406Sopenharmony_ci status = 155141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/empty.conf", 156141cc406Sopenharmony_ci &config, check_config_attach, NULL); 157141cc406Sopenharmony_ci 158141cc406Sopenharmony_ci /* check results */ 159141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 160141cc406Sopenharmony_ci} 161141cc406Sopenharmony_ci 162141cc406Sopenharmony_ci 163141cc406Sopenharmony_ci/* 164141cc406Sopenharmony_ci * string option 165141cc406Sopenharmony_ci */ 166141cc406Sopenharmony_cistatic void 167141cc406Sopenharmony_cistring_option (void) 168141cc406Sopenharmony_ci{ 169141cc406Sopenharmony_ci SANE_Status status; 170141cc406Sopenharmony_ci SANEI_Config config; 171141cc406Sopenharmony_ci SANE_Char modelname[128]; 172141cc406Sopenharmony_ci SANE_Char vendor[128]; 173141cc406Sopenharmony_ci SANE_Option_Descriptor *options[2]; 174141cc406Sopenharmony_ci void *values[2]; 175141cc406Sopenharmony_ci int i; 176141cc406Sopenharmony_ci 177141cc406Sopenharmony_ci i = 0; 178141cc406Sopenharmony_ci options[i] = 179141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 180141cc406Sopenharmony_ci options[i]->name = "modelname"; 181141cc406Sopenharmony_ci options[i]->title = "model name"; 182141cc406Sopenharmony_ci options[i]->desc = "user provided scanner's model name"; 183141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 184141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 185141cc406Sopenharmony_ci options[i]->size = 128; 186141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 187141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 188141cc406Sopenharmony_ci values[i] = modelname; 189141cc406Sopenharmony_ci i++; 190141cc406Sopenharmony_ci 191141cc406Sopenharmony_ci options[i] = 192141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 193141cc406Sopenharmony_ci options[i]->name = "vendor"; 194141cc406Sopenharmony_ci options[i]->title = "vendor name"; 195141cc406Sopenharmony_ci options[i]->desc = "user provided scanner's vendor name"; 196141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 197141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 198141cc406Sopenharmony_ci options[i]->size = 128; 199141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 200141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 201141cc406Sopenharmony_ci values[i] = vendor; 202141cc406Sopenharmony_ci i++; 203141cc406Sopenharmony_ci 204141cc406Sopenharmony_ci config.count = i; 205141cc406Sopenharmony_ci config.descriptors = options; 206141cc406Sopenharmony_ci config.values = values; 207141cc406Sopenharmony_ci 208141cc406Sopenharmony_ci /* configure and attach */ 209141cc406Sopenharmony_ci status = 210141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/string.conf", 211141cc406Sopenharmony_ci &config, check_config_attach, NULL); 212141cc406Sopenharmony_ci 213141cc406Sopenharmony_ci /* check results */ 214141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 215141cc406Sopenharmony_ci assert (strcmp (modelname, "my model") == 0); 216141cc406Sopenharmony_ci assert (strcmp (vendor, "my vendor") == 0); 217141cc406Sopenharmony_ci} 218141cc406Sopenharmony_ci 219141cc406Sopenharmony_ci 220141cc406Sopenharmony_ci/* 221141cc406Sopenharmony_ci * int option 222141cc406Sopenharmony_ci */ 223141cc406Sopenharmony_cistatic void 224141cc406Sopenharmony_ciint_option (void) 225141cc406Sopenharmony_ci{ 226141cc406Sopenharmony_ci SANE_Status status; 227141cc406Sopenharmony_ci SANEI_Config config; 228141cc406Sopenharmony_ci SANE_Word modelnumber; 229141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 230141cc406Sopenharmony_ci void *values[1]; 231141cc406Sopenharmony_ci int i; 232141cc406Sopenharmony_ci 233141cc406Sopenharmony_ci i = 0; 234141cc406Sopenharmony_ci options[i] = 235141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 236141cc406Sopenharmony_ci options[i]->name = "modelnumber"; 237141cc406Sopenharmony_ci options[i]->title = "model number"; 238141cc406Sopenharmony_ci options[i]->desc = "user provided scanner's model number"; 239141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 240141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 241141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 242141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 243141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 244141cc406Sopenharmony_ci options[i]->constraint.range = &model_range; 245141cc406Sopenharmony_ci values[i] = &modelnumber; 246141cc406Sopenharmony_ci i++; 247141cc406Sopenharmony_ci 248141cc406Sopenharmony_ci config.descriptors = options; 249141cc406Sopenharmony_ci config.values = values; 250141cc406Sopenharmony_ci config.count = i; 251141cc406Sopenharmony_ci 252141cc406Sopenharmony_ci /* configure and attach */ 253141cc406Sopenharmony_ci status = 254141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/int.conf", &config, 255141cc406Sopenharmony_ci check_config_attach, NULL); 256141cc406Sopenharmony_ci 257141cc406Sopenharmony_ci /* check results */ 258141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 259141cc406Sopenharmony_ci assert (modelnumber == 1234); 260141cc406Sopenharmony_ci} 261141cc406Sopenharmony_ci 262141cc406Sopenharmony_ci 263141cc406Sopenharmony_ci/* 264141cc406Sopenharmony_ci * int option out of range 265141cc406Sopenharmony_ci */ 266141cc406Sopenharmony_cistatic void 267141cc406Sopenharmony_ciwrong_range_int_option (void) 268141cc406Sopenharmony_ci{ 269141cc406Sopenharmony_ci SANE_Status status; 270141cc406Sopenharmony_ci SANEI_Config config; 271141cc406Sopenharmony_ci SANE_Word modelnumber = -1; 272141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 273141cc406Sopenharmony_ci void *values[1]; 274141cc406Sopenharmony_ci int i; 275141cc406Sopenharmony_ci 276141cc406Sopenharmony_ci i = 0; 277141cc406Sopenharmony_ci options[i] = 278141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 279141cc406Sopenharmony_ci options[i]->name = "modelnumber"; 280141cc406Sopenharmony_ci options[i]->title = "model number"; 281141cc406Sopenharmony_ci options[i]->desc = "user provided scanner's model number"; 282141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 283141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 284141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 285141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 286141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 287141cc406Sopenharmony_ci options[i]->constraint.range = &model_range; 288141cc406Sopenharmony_ci values[i] = &modelnumber; 289141cc406Sopenharmony_ci i++; 290141cc406Sopenharmony_ci 291141cc406Sopenharmony_ci config.descriptors = options; 292141cc406Sopenharmony_ci config.values = values; 293141cc406Sopenharmony_ci config.count = i; 294141cc406Sopenharmony_ci 295141cc406Sopenharmony_ci /* configure and attach */ 296141cc406Sopenharmony_ci status = 297141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/wrong-range.conf", 298141cc406Sopenharmony_ci &config, check_config_attach, NULL); 299141cc406Sopenharmony_ci 300141cc406Sopenharmony_ci /* check results */ 301141cc406Sopenharmony_ci assert (status == SANE_STATUS_INVAL); 302141cc406Sopenharmony_ci assert (modelnumber == -1); 303141cc406Sopenharmony_ci} 304141cc406Sopenharmony_ci 305141cc406Sopenharmony_ci 306141cc406Sopenharmony_ci/* 307141cc406Sopenharmony_ci * word array 308141cc406Sopenharmony_ci */ 309141cc406Sopenharmony_cistatic void 310141cc406Sopenharmony_ciword_array_option (void) 311141cc406Sopenharmony_ci{ 312141cc406Sopenharmony_ci SANE_Status status; 313141cc406Sopenharmony_ci SANEI_Config config; 314141cc406Sopenharmony_ci SANE_Word numbers[7]; 315141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 316141cc406Sopenharmony_ci void *values[1]; 317141cc406Sopenharmony_ci int i; 318141cc406Sopenharmony_ci 319141cc406Sopenharmony_ci i = 0; 320141cc406Sopenharmony_ci options[i] = 321141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 322141cc406Sopenharmony_ci options[i]->name = "numbers"; 323141cc406Sopenharmony_ci options[i]->title = "some numbers"; 324141cc406Sopenharmony_ci options[i]->desc = "an array of numbers"; 325141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 326141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 327141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word) * 7; 328141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 329141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 330141cc406Sopenharmony_ci options[i]->constraint.range = &model_range; 331141cc406Sopenharmony_ci values[i] = numbers; 332141cc406Sopenharmony_ci i++; 333141cc406Sopenharmony_ci 334141cc406Sopenharmony_ci config.descriptors = options; 335141cc406Sopenharmony_ci config.values = values; 336141cc406Sopenharmony_ci config.count = i; 337141cc406Sopenharmony_ci 338141cc406Sopenharmony_ci /* configure and attach */ 339141cc406Sopenharmony_ci status = 340141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/word-array.conf", 341141cc406Sopenharmony_ci &config, check_config_attach, NULL); 342141cc406Sopenharmony_ci 343141cc406Sopenharmony_ci /* check results */ 344141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 345141cc406Sopenharmony_ci for (i = 0; i < 7; i++) 346141cc406Sopenharmony_ci { 347141cc406Sopenharmony_ci assert (numbers[i] == 1000 + 100 * i); 348141cc406Sopenharmony_ci } 349141cc406Sopenharmony_ci} 350141cc406Sopenharmony_ci 351141cc406Sopenharmony_ci 352141cc406Sopenharmony_ci/* 353141cc406Sopenharmony_ci * string option with string list constraint 354141cc406Sopenharmony_ci */ 355141cc406Sopenharmony_cistatic void 356141cc406Sopenharmony_cistring_list_option (void) 357141cc406Sopenharmony_ci{ 358141cc406Sopenharmony_ci SANE_Status status; 359141cc406Sopenharmony_ci SANEI_Config config; 360141cc406Sopenharmony_ci SANE_Char choice[128]; 361141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 362141cc406Sopenharmony_ci void *values[1]; 363141cc406Sopenharmony_ci int i; 364141cc406Sopenharmony_ci 365141cc406Sopenharmony_ci i = 0; 366141cc406Sopenharmony_ci options[i] = 367141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 368141cc406Sopenharmony_ci options[i]->name = "string-choice"; 369141cc406Sopenharmony_ci options[i]->title = "string choice"; 370141cc406Sopenharmony_ci options[i]->desc = "one string among a fixed list"; 371141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 372141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 373141cc406Sopenharmony_ci options[i]->size = 128; 374141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 375141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_STRING_LIST; 376141cc406Sopenharmony_ci options[i]->constraint.string_list = string_list; 377141cc406Sopenharmony_ci values[i] = choice; 378141cc406Sopenharmony_ci i++; 379141cc406Sopenharmony_ci 380141cc406Sopenharmony_ci config.descriptors = options; 381141cc406Sopenharmony_ci config.values = values; 382141cc406Sopenharmony_ci config.count = i; 383141cc406Sopenharmony_ci 384141cc406Sopenharmony_ci /* configure and attach */ 385141cc406Sopenharmony_ci status = 386141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/string-list.conf", 387141cc406Sopenharmony_ci &config, check_config_attach, NULL); 388141cc406Sopenharmony_ci 389141cc406Sopenharmony_ci /* check results */ 390141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 391141cc406Sopenharmony_ci assert (strcmp (choice, "string3") == 0); 392141cc406Sopenharmony_ci} 393141cc406Sopenharmony_ci 394141cc406Sopenharmony_ci 395141cc406Sopenharmony_ci/* 396141cc406Sopenharmony_ci * string option with string list constraint 397141cc406Sopenharmony_ci */ 398141cc406Sopenharmony_cistatic void 399141cc406Sopenharmony_ciwrong_string_list_option (void) 400141cc406Sopenharmony_ci{ 401141cc406Sopenharmony_ci SANE_Status status; 402141cc406Sopenharmony_ci SANEI_Config config; 403141cc406Sopenharmony_ci SANE_Char choice[128]; 404141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 405141cc406Sopenharmony_ci void *values[1]; 406141cc406Sopenharmony_ci int i; 407141cc406Sopenharmony_ci 408141cc406Sopenharmony_ci i = 0; 409141cc406Sopenharmony_ci options[i] = 410141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 411141cc406Sopenharmony_ci options[i]->name = "string-choice"; 412141cc406Sopenharmony_ci options[i]->title = "string choice"; 413141cc406Sopenharmony_ci options[i]->desc = "one string among a fixed list"; 414141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 415141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 416141cc406Sopenharmony_ci options[i]->size = 128; 417141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 418141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_STRING_LIST; 419141cc406Sopenharmony_ci options[i]->constraint.string_list = string_list; 420141cc406Sopenharmony_ci values[i] = choice; 421141cc406Sopenharmony_ci i++; 422141cc406Sopenharmony_ci 423141cc406Sopenharmony_ci config.descriptors = options; 424141cc406Sopenharmony_ci config.values = values; 425141cc406Sopenharmony_ci config.count = i; 426141cc406Sopenharmony_ci 427141cc406Sopenharmony_ci choice[0] = 0; 428141cc406Sopenharmony_ci 429141cc406Sopenharmony_ci /* configure and attach */ 430141cc406Sopenharmony_ci status = 431141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH 432141cc406Sopenharmony_ci "/data/wrong-string-list.conf", &config, 433141cc406Sopenharmony_ci check_config_attach, NULL); 434141cc406Sopenharmony_ci 435141cc406Sopenharmony_ci /* check results */ 436141cc406Sopenharmony_ci assert (status == SANE_STATUS_INVAL); 437141cc406Sopenharmony_ci assert (strcmp (choice, "") == 0); 438141cc406Sopenharmony_ci} 439141cc406Sopenharmony_ci 440141cc406Sopenharmony_ci 441141cc406Sopenharmony_ci/* 442141cc406Sopenharmony_ci * real umax_pp confiugration file parsing 443141cc406Sopenharmony_ci */ 444141cc406Sopenharmony_cistatic void 445141cc406Sopenharmony_ciumax_pp (void) 446141cc406Sopenharmony_ci{ 447141cc406Sopenharmony_ci SANE_Status status; 448141cc406Sopenharmony_ci SANEI_Config config; 449141cc406Sopenharmony_ci SANE_Option_Descriptor *options[9]; 450141cc406Sopenharmony_ci void *values[9]; 451141cc406Sopenharmony_ci int i = 0; 452141cc406Sopenharmony_ci /* placeholders for options */ 453141cc406Sopenharmony_ci SANE_Word buffersize = -1; 454141cc406Sopenharmony_ci SANE_Word redgain = -1; 455141cc406Sopenharmony_ci SANE_Word greengain = -1; 456141cc406Sopenharmony_ci SANE_Word bluegain = -1; 457141cc406Sopenharmony_ci SANE_Word redoffset = -1; 458141cc406Sopenharmony_ci SANE_Word greenoffset = -1; 459141cc406Sopenharmony_ci SANE_Word blueoffset = -1; 460141cc406Sopenharmony_ci SANE_Char model[128]; 461141cc406Sopenharmony_ci 462141cc406Sopenharmony_ci i = 0; 463141cc406Sopenharmony_ci options[i] = 464141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 465141cc406Sopenharmony_ci options[i]->name = "buffer"; 466141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 467141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 468141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 469141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 470141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 471141cc406Sopenharmony_ci options[i]->constraint.range = &buffer_range; 472141cc406Sopenharmony_ci values[i] = &buffersize; 473141cc406Sopenharmony_ci i++; 474141cc406Sopenharmony_ci 475141cc406Sopenharmony_ci options[i] = 476141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 477141cc406Sopenharmony_ci options[i]->name = "red-gain"; 478141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 479141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 480141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 481141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 482141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 483141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 484141cc406Sopenharmony_ci values[i] = &redgain; 485141cc406Sopenharmony_ci i++; 486141cc406Sopenharmony_ci 487141cc406Sopenharmony_ci options[i] = 488141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 489141cc406Sopenharmony_ci options[i]->name = "green-gain"; 490141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 491141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 492141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 493141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 494141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 495141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 496141cc406Sopenharmony_ci values[i] = &greengain; 497141cc406Sopenharmony_ci i++; 498141cc406Sopenharmony_ci 499141cc406Sopenharmony_ci options[i] = 500141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 501141cc406Sopenharmony_ci options[i]->name = "blue-gain"; 502141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 503141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 504141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 505141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 506141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 507141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 508141cc406Sopenharmony_ci values[i] = &bluegain; 509141cc406Sopenharmony_ci i++; 510141cc406Sopenharmony_ci 511141cc406Sopenharmony_ci options[i] = 512141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 513141cc406Sopenharmony_ci options[i]->name = "red-offset"; 514141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 515141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 516141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 517141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 518141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 519141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 520141cc406Sopenharmony_ci values[i] = &redoffset; 521141cc406Sopenharmony_ci i++; 522141cc406Sopenharmony_ci 523141cc406Sopenharmony_ci options[i] = 524141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 525141cc406Sopenharmony_ci options[i]->name = "green-offset"; 526141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 527141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 528141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 529141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 530141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 531141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 532141cc406Sopenharmony_ci values[i] = &greenoffset; 533141cc406Sopenharmony_ci i++; 534141cc406Sopenharmony_ci 535141cc406Sopenharmony_ci options[i] = 536141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 537141cc406Sopenharmony_ci options[i]->name = "blue-offset"; 538141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_INT; 539141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 540141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 541141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 542141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 543141cc406Sopenharmony_ci options[i]->constraint.range = &value16_range; 544141cc406Sopenharmony_ci values[i] = &blueoffset; 545141cc406Sopenharmony_ci i++; 546141cc406Sopenharmony_ci 547141cc406Sopenharmony_ci options[i] = 548141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 549141cc406Sopenharmony_ci options[i]->name = "astra"; 550141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 551141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 552141cc406Sopenharmony_ci options[i]->size = 128; 553141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 554141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_STRING_LIST; 555141cc406Sopenharmony_ci options[i]->constraint.string_list = astra_models; 556141cc406Sopenharmony_ci values[i] = &model; 557141cc406Sopenharmony_ci i++; 558141cc406Sopenharmony_ci 559141cc406Sopenharmony_ci config.descriptors = options; 560141cc406Sopenharmony_ci config.values = values; 561141cc406Sopenharmony_ci config.count = i; 562141cc406Sopenharmony_ci 563141cc406Sopenharmony_ci model[0] = 0; 564141cc406Sopenharmony_ci 565141cc406Sopenharmony_ci /* configure and attach */ 566141cc406Sopenharmony_ci status = 567141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/umax_pp.conf", 568141cc406Sopenharmony_ci &config, check_config_attach, NULL); 569141cc406Sopenharmony_ci 570141cc406Sopenharmony_ci /* check results */ 571141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 572141cc406Sopenharmony_ci assert (buffersize == 1048576); 573141cc406Sopenharmony_ci assert (redgain == 1); 574141cc406Sopenharmony_ci assert (greengain == 2); 575141cc406Sopenharmony_ci assert (bluegain == 3); 576141cc406Sopenharmony_ci assert (redoffset == 4); 577141cc406Sopenharmony_ci assert (greenoffset == 5); 578141cc406Sopenharmony_ci assert (blueoffset == 6); 579141cc406Sopenharmony_ci assert (strcmp (model, "1600") == 0); 580141cc406Sopenharmony_ci assert (strcmp (lastdevname, "port safe-auto") == 0); 581141cc406Sopenharmony_ci 582141cc406Sopenharmony_ci /* free memory */ 583141cc406Sopenharmony_ci while (i > 0) 584141cc406Sopenharmony_ci { 585141cc406Sopenharmony_ci i--; 586141cc406Sopenharmony_ci free (options[i]); 587141cc406Sopenharmony_ci } 588141cc406Sopenharmony_ci} 589141cc406Sopenharmony_ci 590141cc406Sopenharmony_ci 591141cc406Sopenharmony_ci/* 592141cc406Sopenharmony_ci * boolean option 593141cc406Sopenharmony_ci */ 594141cc406Sopenharmony_cistatic void 595141cc406Sopenharmony_ciwrong_bool_option (void) 596141cc406Sopenharmony_ci{ 597141cc406Sopenharmony_ci SANE_Status status; 598141cc406Sopenharmony_ci SANEI_Config config; 599141cc406Sopenharmony_ci SANE_Option_Descriptor *options[2]; 600141cc406Sopenharmony_ci void *values[2]; 601141cc406Sopenharmony_ci SANE_Bool booltrue, boolfalse; 602141cc406Sopenharmony_ci int i; 603141cc406Sopenharmony_ci 604141cc406Sopenharmony_ci i = 0; 605141cc406Sopenharmony_ci options[i] = 606141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 607141cc406Sopenharmony_ci options[i]->name = "booltrue"; 608141cc406Sopenharmony_ci options[i]->title = "boolean true"; 609141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_BOOL; 610141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 611141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Bool); 612141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 613141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 614141cc406Sopenharmony_ci values[i] = &booltrue; 615141cc406Sopenharmony_ci i++; 616141cc406Sopenharmony_ci 617141cc406Sopenharmony_ci options[i] = 618141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 619141cc406Sopenharmony_ci options[i]->name = "boolfalse"; 620141cc406Sopenharmony_ci options[i]->title = "boolean false"; 621141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_BOOL; 622141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 623141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Bool); 624141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 625141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 626141cc406Sopenharmony_ci values[i] = &boolfalse; 627141cc406Sopenharmony_ci i++; 628141cc406Sopenharmony_ci 629141cc406Sopenharmony_ci config.descriptors = options; 630141cc406Sopenharmony_ci config.values = values; 631141cc406Sopenharmony_ci config.count = i; 632141cc406Sopenharmony_ci 633141cc406Sopenharmony_ci /* configure and attach */ 634141cc406Sopenharmony_ci status = 635141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/wrong-boolean.conf", 636141cc406Sopenharmony_ci &config, check_config_attach, NULL); 637141cc406Sopenharmony_ci 638141cc406Sopenharmony_ci /* check results */ 639141cc406Sopenharmony_ci assert (status == SANE_STATUS_INVAL); 640141cc406Sopenharmony_ci assert (booltrue == SANE_TRUE); 641141cc406Sopenharmony_ci} 642141cc406Sopenharmony_ci 643141cc406Sopenharmony_ci 644141cc406Sopenharmony_ci/* 645141cc406Sopenharmony_ci * boolean option 646141cc406Sopenharmony_ci */ 647141cc406Sopenharmony_cistatic void 648141cc406Sopenharmony_cibool_option (void) 649141cc406Sopenharmony_ci{ 650141cc406Sopenharmony_ci SANE_Status status; 651141cc406Sopenharmony_ci SANEI_Config config; 652141cc406Sopenharmony_ci SANE_Option_Descriptor *options[3]; 653141cc406Sopenharmony_ci void *values[3]; 654141cc406Sopenharmony_ci SANE_Bool booltrue, boolfalse, boolarray[3]; 655141cc406Sopenharmony_ci int i; 656141cc406Sopenharmony_ci 657141cc406Sopenharmony_ci i = 0; 658141cc406Sopenharmony_ci options[i] = 659141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 660141cc406Sopenharmony_ci options[i]->name = "booltrue"; 661141cc406Sopenharmony_ci options[i]->title = "boolean true"; 662141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_BOOL; 663141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 664141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Bool); 665141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 666141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 667141cc406Sopenharmony_ci values[i] = &booltrue; 668141cc406Sopenharmony_ci i++; 669141cc406Sopenharmony_ci 670141cc406Sopenharmony_ci options[i] = 671141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 672141cc406Sopenharmony_ci options[i]->name = "boolfalse"; 673141cc406Sopenharmony_ci options[i]->title = "boolean false"; 674141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_BOOL; 675141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 676141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Bool); 677141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 678141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 679141cc406Sopenharmony_ci values[i] = &boolfalse; 680141cc406Sopenharmony_ci i++; 681141cc406Sopenharmony_ci 682141cc406Sopenharmony_ci options[i] = 683141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 684141cc406Sopenharmony_ci options[i]->name = "boolarray"; 685141cc406Sopenharmony_ci options[i]->title = "boolean array"; 686141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_BOOL; 687141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 688141cc406Sopenharmony_ci options[i]->size = sizeof (boolarray); 689141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 690141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 691141cc406Sopenharmony_ci values[i] = boolarray; 692141cc406Sopenharmony_ci i++; 693141cc406Sopenharmony_ci 694141cc406Sopenharmony_ci config.descriptors = options; 695141cc406Sopenharmony_ci config.values = values; 696141cc406Sopenharmony_ci config.count = i; 697141cc406Sopenharmony_ci 698141cc406Sopenharmony_ci /* configure and attach */ 699141cc406Sopenharmony_ci status = 700141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/boolean.conf", 701141cc406Sopenharmony_ci &config, check_config_attach, NULL); 702141cc406Sopenharmony_ci 703141cc406Sopenharmony_ci /* check results */ 704141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 705141cc406Sopenharmony_ci assert (booltrue == SANE_TRUE); 706141cc406Sopenharmony_ci assert (boolfalse == SANE_FALSE); 707141cc406Sopenharmony_ci for (i = 0; i < 3; i++) 708141cc406Sopenharmony_ci { 709141cc406Sopenharmony_ci assert (boolarray[i] == (SANE_Bool) i % 2); 710141cc406Sopenharmony_ci } 711141cc406Sopenharmony_ci} 712141cc406Sopenharmony_ci 713141cc406Sopenharmony_ci 714141cc406Sopenharmony_ci/* 715141cc406Sopenharmony_ci * fixed option 716141cc406Sopenharmony_ci */ 717141cc406Sopenharmony_cistatic void 718141cc406Sopenharmony_cifixed_option (void) 719141cc406Sopenharmony_ci{ 720141cc406Sopenharmony_ci SANE_Status status; 721141cc406Sopenharmony_ci SANEI_Config config; 722141cc406Sopenharmony_ci SANE_Word width, height, fixedarray[7]; 723141cc406Sopenharmony_ci SANE_Option_Descriptor *options[3]; 724141cc406Sopenharmony_ci void *values[3]; 725141cc406Sopenharmony_ci int i; 726141cc406Sopenharmony_ci 727141cc406Sopenharmony_ci i = 0; 728141cc406Sopenharmony_ci options[i] = 729141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 730141cc406Sopenharmony_ci options[i]->name = "width"; 731141cc406Sopenharmony_ci options[i]->title = "width"; 732141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_FIXED; 733141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 734141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 735141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 736141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 737141cc406Sopenharmony_ci values[i] = &width; 738141cc406Sopenharmony_ci i++; 739141cc406Sopenharmony_ci 740141cc406Sopenharmony_ci options[i] = 741141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 742141cc406Sopenharmony_ci options[i]->name = "height"; 743141cc406Sopenharmony_ci options[i]->title = "height"; 744141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_FIXED; 745141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 746141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 747141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 748141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 749141cc406Sopenharmony_ci values[i] = &height; 750141cc406Sopenharmony_ci i++; 751141cc406Sopenharmony_ci 752141cc406Sopenharmony_ci options[i] = 753141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 754141cc406Sopenharmony_ci options[i]->name = "array-of-fixed"; 755141cc406Sopenharmony_ci options[i]->title = "array of fixed"; 756141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_FIXED; 757141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 758141cc406Sopenharmony_ci options[i]->size = sizeof (fixedarray); 759141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 760141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 761141cc406Sopenharmony_ci options[i]->constraint.range = &height_range; 762141cc406Sopenharmony_ci values[i] = fixedarray; 763141cc406Sopenharmony_ci i++; 764141cc406Sopenharmony_ci 765141cc406Sopenharmony_ci config.descriptors = options; 766141cc406Sopenharmony_ci config.values = values; 767141cc406Sopenharmony_ci config.count = i; 768141cc406Sopenharmony_ci 769141cc406Sopenharmony_ci /* configure and attach */ 770141cc406Sopenharmony_ci status = 771141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/fixed.conf", 772141cc406Sopenharmony_ci &config, check_config_attach, NULL); 773141cc406Sopenharmony_ci 774141cc406Sopenharmony_ci /* check results */ 775141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 776141cc406Sopenharmony_ci assert (width == SANE_FIX (21.0)); 777141cc406Sopenharmony_ci assert (height == SANE_FIX (29.7)); 778141cc406Sopenharmony_ci for (i = 0; i < 7; i++) 779141cc406Sopenharmony_ci { 780141cc406Sopenharmony_ci assert (fixedarray[i] == SANE_FIX (2.0 + 0.1 * ((float) i))); 781141cc406Sopenharmony_ci } 782141cc406Sopenharmony_ci} 783141cc406Sopenharmony_ci 784141cc406Sopenharmony_ci 785141cc406Sopenharmony_ci/* 786141cc406Sopenharmony_ci * fixed option with value out of range 787141cc406Sopenharmony_ci */ 788141cc406Sopenharmony_cistatic void 789141cc406Sopenharmony_ciwrong_fixed_option (void) 790141cc406Sopenharmony_ci{ 791141cc406Sopenharmony_ci SANE_Status status; 792141cc406Sopenharmony_ci SANEI_Config config; 793141cc406Sopenharmony_ci SANE_Word height; 794141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 795141cc406Sopenharmony_ci void *values[1]; 796141cc406Sopenharmony_ci int i; 797141cc406Sopenharmony_ci 798141cc406Sopenharmony_ci i = 0; 799141cc406Sopenharmony_ci options[i] = 800141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 801141cc406Sopenharmony_ci options[i]->name = "height"; 802141cc406Sopenharmony_ci options[i]->title = "height"; 803141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_FIXED; 804141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 805141cc406Sopenharmony_ci options[i]->size = sizeof (SANE_Word); 806141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 807141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_RANGE; 808141cc406Sopenharmony_ci options[i]->constraint.range = &height_range; 809141cc406Sopenharmony_ci values[i] = &height; 810141cc406Sopenharmony_ci i++; 811141cc406Sopenharmony_ci 812141cc406Sopenharmony_ci config.descriptors = options; 813141cc406Sopenharmony_ci config.values = values; 814141cc406Sopenharmony_ci config.count = i; 815141cc406Sopenharmony_ci 816141cc406Sopenharmony_ci /* configure and attach */ 817141cc406Sopenharmony_ci status = 818141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/wrong-fixed.conf", 819141cc406Sopenharmony_ci &config, check_config_attach, NULL); 820141cc406Sopenharmony_ci 821141cc406Sopenharmony_ci /* check results */ 822141cc406Sopenharmony_ci assert (status == SANE_STATUS_INVAL); 823141cc406Sopenharmony_ci} 824141cc406Sopenharmony_ci 825141cc406Sopenharmony_ci 826141cc406Sopenharmony_cistatic void 827141cc406Sopenharmony_cisnapscan (void) 828141cc406Sopenharmony_ci{ 829141cc406Sopenharmony_ci SANE_Status status; 830141cc406Sopenharmony_ci SANEI_Config config; 831141cc406Sopenharmony_ci SANE_Char firmware[128]; 832141cc406Sopenharmony_ci SANE_Option_Descriptor *options[1]; 833141cc406Sopenharmony_ci void *values[1]; 834141cc406Sopenharmony_ci int i; 835141cc406Sopenharmony_ci 836141cc406Sopenharmony_ci i = 0; 837141cc406Sopenharmony_ci options[i] = 838141cc406Sopenharmony_ci (SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor)); 839141cc406Sopenharmony_ci options[i]->name = "firmware"; 840141cc406Sopenharmony_ci options[i]->title = "scanner's firmware path"; 841141cc406Sopenharmony_ci options[i]->desc = "user provided scanner's full path"; 842141cc406Sopenharmony_ci options[i]->type = SANE_TYPE_STRING; 843141cc406Sopenharmony_ci options[i]->unit = SANE_UNIT_NONE; 844141cc406Sopenharmony_ci options[i]->size = sizeof (firmware); 845141cc406Sopenharmony_ci options[i]->cap = SANE_CAP_SOFT_SELECT; 846141cc406Sopenharmony_ci options[i]->constraint_type = SANE_CONSTRAINT_NONE; 847141cc406Sopenharmony_ci values[i] = firmware; 848141cc406Sopenharmony_ci i++; 849141cc406Sopenharmony_ci 850141cc406Sopenharmony_ci config.descriptors = options; 851141cc406Sopenharmony_ci config.values = values; 852141cc406Sopenharmony_ci config.count = i; 853141cc406Sopenharmony_ci 854141cc406Sopenharmony_ci /* configure and attach */ 855141cc406Sopenharmony_ci status = 856141cc406Sopenharmony_ci sanei_configure_attach (CONFIG_PATH "/data/snapscan.conf", 857141cc406Sopenharmony_ci &config, check_config_attach, NULL); 858141cc406Sopenharmony_ci 859141cc406Sopenharmony_ci /* check results */ 860141cc406Sopenharmony_ci assert (status == SANE_STATUS_GOOD); 861141cc406Sopenharmony_ci assert (strcmp (firmware, "/usr/share/sane/snapscan/your-firmwarefile.bin") 862141cc406Sopenharmony_ci == 0); 863141cc406Sopenharmony_ci /* TODO must test attach() done */ 864141cc406Sopenharmony_ci} 865141cc406Sopenharmony_ci 866141cc406Sopenharmony_ci 867141cc406Sopenharmony_ci/** 868141cc406Sopenharmony_ci * create the test suite for sanei config related tests 869141cc406Sopenharmony_ci */ 870141cc406Sopenharmony_cistatic void 871141cc406Sopenharmony_cisanei_config_suite (void) 872141cc406Sopenharmony_ci{ 873141cc406Sopenharmony_ci /* tests */ 874141cc406Sopenharmony_ci inexistent_config (); 875141cc406Sopenharmony_ci empty_config (); 876141cc406Sopenharmony_ci null_config (); 877141cc406Sopenharmony_ci null_attach (); 878141cc406Sopenharmony_ci string_option (); 879141cc406Sopenharmony_ci int_option (); 880141cc406Sopenharmony_ci string_list_option (); 881141cc406Sopenharmony_ci word_array_option (); 882141cc406Sopenharmony_ci bool_option (); 883141cc406Sopenharmony_ci fixed_option (); 884141cc406Sopenharmony_ci wrong_range_int_option (); 885141cc406Sopenharmony_ci wrong_string_list_option (); 886141cc406Sopenharmony_ci wrong_bool_option (); 887141cc406Sopenharmony_ci wrong_fixed_option (); 888141cc406Sopenharmony_ci 889141cc406Sopenharmony_ci /* backend real conf inspired cases */ 890141cc406Sopenharmony_ci umax_pp (); 891141cc406Sopenharmony_ci snapscan (); 892141cc406Sopenharmony_ci} 893141cc406Sopenharmony_ci 894141cc406Sopenharmony_ci/** 895141cc406Sopenharmony_ci * main function to run the test suites 896141cc406Sopenharmony_ci */ 897141cc406Sopenharmony_ciint 898141cc406Sopenharmony_cimain (void) 899141cc406Sopenharmony_ci{ 900141cc406Sopenharmony_ci /* set up config dir for local conf files */ 901141cc406Sopenharmony_ci putenv("SANE_CONFIG_DIR=.:/"); 902141cc406Sopenharmony_ci 903141cc406Sopenharmony_ci /* run suites */ 904141cc406Sopenharmony_ci sanei_config_suite (); 905141cc406Sopenharmony_ci 906141cc406Sopenharmony_ci return 0; 907141cc406Sopenharmony_ci} 908141cc406Sopenharmony_ci 909141cc406Sopenharmony_ci/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */ 910