@@ -85,14 +85,14 @@ typedef struct ipptool_expect_s // Expected attribute info
8585 char * name , // Attribute name
8686 * of_type , // Type name
8787 * same_count_as , // Parallel attribute name
88- * if_defined , // Only required if variable defined
89- * if_not_defined , // Only required if variable is not defined
9088 * with_value , // Attribute must include this value
9189 * with_value_from , // Attribute must have one of the values in this attribute
9290 * define_match , // Variable to define on match
9391 * define_no_match , // Variable to define on no-match
9492 * define_value , // Variable to define with value
9593 * display_match ; // Message to display on a match
94+ cups_array_t * if_defined , // Only required if variable(s) defined
95+ * if_not_defined ; // Only required if variable(s) are not defined
9696 ipptool_content_t with_content ; // WITH-*-CONTENT value
9797 cups_array_t * with_mime_types ; // WITH-*-MIME-TYPES value(s)
9898 char * save_filespec ; // SAVE-*-CONTENT filespec
@@ -122,9 +122,9 @@ typedef struct ipptool_generate_s //// GENERATE-FILE parameters
122122typedef struct ipptool_status_s // Status info
123123{
124124 ipp_status_t status ; // Expected status code
125- char * if_defined , // Only if variable is defined
126- * if_not_defined , // Only if variable is not defined
127- * define_match , // Variable to define on match
125+ cups_array_t * if_defined , // Only required if variable(s) defined
126+ * if_not_defined ; // Only required if variable(s) are not defined
127+ char * define_match , // Variable to define on match
128128 * define_no_match , // Variable to define on no-match
129129 * define_value ; // Variable to define with value
130130 int repeat_limit ; // Maximum number of times to repeat
@@ -218,6 +218,7 @@ static bool Cancel = false; // Cancel test?
218218
219219static void add_stringf (cups_array_t * a , const char * s , ...) _CUPS_FORMAT (2 , 3 );
220220static ipptool_test_t * alloc_data (void );
221+ static bool check_vars (ipp_file_t * f , cups_array_t * vars , bool need_all );
221222static void clear_data (ipptool_test_t * data );
222223static int compare_uris (const char * a , const char * b );
223224static http_t * connect_printer (ipptool_test_t * data );
@@ -825,6 +826,39 @@ alloc_data(void)
825826}
826827
827828
829+ //
830+ // 'check_vars()' - Check for the existence of the listed variables.
831+ //
832+
833+ static bool // O - `true` if vars are defined, `false` otherwise
834+ check_vars (ipp_file_t * f , // I - IPP file
835+ cups_array_t * vars , // I - Variables to look for
836+ bool need_all ) // I - Do we need all of them to exist?
837+ {
838+ bool ret = false; // Return value
839+ const char * var ; // Current variable
840+
841+
842+ if (!vars )
843+ return (true);
844+
845+ for (var = (const char * )cupsArrayGetFirst (vars ); var ; var = (const char * )cupsArrayGetNext (vars ))
846+ {
847+ if (ippFileGetVar (f , var ))
848+ {
849+ if (getenv ("IPPTOOL_DEBUG" ))
850+ fprintf (stderr , "ipptool: %s is present\n" , var );
851+
852+ ret = true;
853+ }
854+ else if (need_all )
855+ return (false);
856+ }
857+
858+ return (ret );
859+ }
860+
861+
828862//
829863// 'clear_data()' - Clear per-test data...
830864//
@@ -847,8 +881,8 @@ clear_data(ipptool_test_t *data) // I - Test data
847881 free (expect -> name );
848882 free (expect -> of_type );
849883 free (expect -> same_count_as );
850- free (expect -> if_defined );
851- free (expect -> if_not_defined );
884+ cupsArrayDelete (expect -> if_defined );
885+ cupsArrayDelete (expect -> if_not_defined );
852886 free (expect -> with_value );
853887 free (expect -> define_match );
854888 free (expect -> define_no_match );
@@ -861,8 +895,8 @@ clear_data(ipptool_test_t *data) // I - Test data
861895
862896 for (i = 0 ; i < data -> num_statuses ; i ++ )
863897 {
864- free (data -> statuses [i ].if_defined );
865- free (data -> statuses [i ].if_not_defined );
898+ cupsArrayDelete (data -> statuses [i ].if_defined );
899+ cupsArrayDelete (data -> statuses [i ].if_not_defined );
866900 free (data -> statuses [i ].define_match );
867901 free (data -> statuses [i ].define_no_match );
868902 free (data -> statuses [i ].define_value );
@@ -877,8 +911,8 @@ clear_data(ipptool_test_t *data) // I - Test data
877911 free (expect -> name );
878912 free (expect -> of_type );
879913 free (expect -> same_count_as );
880- free (expect -> if_defined );
881- free (expect -> if_not_defined );
914+ cupsArrayDelete (expect -> if_defined );
915+ cupsArrayDelete (expect -> if_not_defined );
882916 free (expect -> with_value );
883917 free (expect -> define_match );
884918 free (expect -> define_no_match );
@@ -1243,10 +1277,10 @@ do_monitor_printer_state(
12431277
12441278 for (i = data -> num_monitor_expects , expect = data -> monitor_expects ; i > 0 ; i -- , expect ++ )
12451279 {
1246- if (expect -> if_defined && !ippFileGetVar (data -> parent , expect -> if_defined ))
1280+ if (expect -> if_defined && !check_vars (data -> parent , expect -> if_defined , /*need_all*/ true ))
12471281 continue ;
12481282
1249- if (expect -> if_not_defined && ippFileGetVar (data -> parent , expect -> if_not_defined ))
1283+ if (expect -> if_not_defined && check_vars (data -> parent , expect -> if_not_defined , /*need_all*/ false ))
12501284 continue ;
12511285
12521286 found = ippFindAttribute (response , expect -> name , IPP_TAG_ZERO );
@@ -1828,10 +1862,10 @@ do_test(ipp_file_t *f, // I - IPP data file
18281862 {
18291863 for (i = 0 , status_ok = false; i < data -> num_statuses ; i ++ )
18301864 {
1831- if (data -> statuses [i ].if_defined && !ippFileGetVar ( f , data -> statuses [i ].if_defined ))
1865+ if (data -> statuses [i ].if_defined && !check_vars ( data -> parent , data -> statuses [i ].if_defined , /*need_all*/ true ))
18321866 continue ;
18331867
1834- if (data -> statuses [i ].if_not_defined && ippFileGetVar ( f , data -> statuses [i ].if_not_defined ))
1868+ if (data -> statuses [i ].if_not_defined && check_vars ( data -> parent , data -> statuses [i ].if_not_defined , /*need_all*/ false ))
18351869 continue ;
18361870
18371871 if (ippGetStatusCode (response ) == data -> statuses [i ].status )
@@ -1862,10 +1896,10 @@ do_test(ipp_file_t *f, // I - IPP data file
18621896 {
18631897 for (i = 0 ; i < data -> num_statuses ; i ++ )
18641898 {
1865- if (data -> statuses [i ].if_defined && !ippFileGetVar ( f , data -> statuses [i ].if_defined ))
1899+ if (data -> statuses [i ].if_defined && !check_vars ( data -> parent , data -> statuses [i ].if_defined , /*need_all*/ true ))
18661900 continue ;
18671901
1868- if (data -> statuses [i ].if_not_defined && ippFileGetVar ( f , data -> statuses [i ].if_not_defined ))
1902+ if (data -> statuses [i ].if_not_defined && check_vars ( data -> parent , data -> statuses [i ].if_not_defined , /*need_all*/ false ))
18691903 continue ;
18701904
18711905 if (!data -> statuses [i ].repeat_match || repeat_count >= data -> statuses [i ].repeat_limit )
@@ -1883,10 +1917,10 @@ do_test(ipp_file_t *f, // I - IPP data file
18831917 exp_pass ; // Did this expect pass?
18841918 ipp_attribute_t * group_found ; // Found parent attribute for group tests
18851919
1886- if (expect -> if_defined && !ippFileGetVar ( f , expect -> if_defined ))
1920+ if (expect -> if_defined && !check_vars ( data -> parent , expect -> if_defined , /*need_all*/ true ))
18871921 continue ;
18881922
1889- if (expect -> if_not_defined && ippFileGetVar ( f , expect -> if_not_defined ))
1923+ if (expect -> if_not_defined && check_vars ( data -> parent , expect -> if_not_defined , /*need_all*/ false ))
18901924 continue ;
18911925
18921926 if ((found = ippFindAttribute (response , expect -> name , IPP_TAG_ZERO )) != NULL && expect -> in_group && expect -> in_group != ippGetGroupTag (found ))
@@ -2076,6 +2110,9 @@ do_test(ipp_file_t *f, // I - IPP data file
20762110
20772111 if (found && expect -> define_match )
20782112 {
2113+ if (getenv ("IPPTOOL_DEBUG" ))
2114+ fprintf (stderr , "ipptool: %s=1\n" , expect -> define_match );
2115+
20792116 ippFileSetVar (data -> parent , expect -> define_match , "1" );
20802117 exp_pass = true;
20812118 }
@@ -2136,6 +2173,9 @@ do_test(ipp_file_t *f, // I - IPP data file
21362173 }
21372174 }
21382175
2176+ if (getenv ("IPPTOOL_DEBUG" ))
2177+ fprintf (stderr , "ipptool: %s=%s\n" , expect -> define_value , data -> buffer );
2178+
21392179 ippFileSetVar (data -> parent , expect -> define_value , data -> buffer );
21402180 }
21412181
@@ -3838,7 +3878,10 @@ parse_monitor_printer_state(
38383878
38393879 if (data -> last_expect )
38403880 {
3841- data -> last_expect -> if_defined = strdup (temp );
3881+ if (data -> last_expect -> if_defined )
3882+ cupsArrayAddStrings (data -> last_expect -> if_defined , temp , ',' );
3883+ else
3884+ data -> last_expect -> if_defined = cupsArrayNewStrings (temp , ',' );
38423885 }
38433886 else
38443887 {
@@ -3856,7 +3899,10 @@ parse_monitor_printer_state(
38563899
38573900 if (data -> last_expect )
38583901 {
3859- data -> last_expect -> if_not_defined = strdup (temp );
3902+ if (data -> last_expect -> if_not_defined )
3903+ cupsArrayAddStrings (data -> last_expect -> if_not_defined , temp , ',' );
3904+ else
3905+ data -> last_expect -> if_not_defined = cupsArrayNewStrings (temp , ',' );
38603906 }
38613907 else
38623908 {
@@ -5859,11 +5905,17 @@ token_cb(ipp_file_t *f, // I - IPP file data
58595905
58605906 if (data -> last_expect )
58615907 {
5862- data -> last_expect -> if_defined = strdup (temp );
5908+ if (data -> last_expect -> if_defined )
5909+ cupsArrayAddStrings (data -> last_expect -> if_defined , temp , ',' );
5910+ else
5911+ data -> last_expect -> if_defined = cupsArrayNewStrings (temp , ',' );
58635912 }
58645913 else if (data -> last_status )
58655914 {
5866- data -> last_status -> if_defined = strdup (temp );
5915+ if (data -> last_status -> if_defined )
5916+ cupsArrayAddStrings (data -> last_status -> if_defined , temp , ',' );
5917+ else
5918+ data -> last_status -> if_defined = cupsArrayNewStrings (temp , ',' );
58675919 }
58685920 else
58695921 {
@@ -5881,11 +5933,17 @@ token_cb(ipp_file_t *f, // I - IPP file data
58815933
58825934 if (data -> last_expect )
58835935 {
5884- data -> last_expect -> if_not_defined = strdup (temp );
5936+ if (data -> last_expect -> if_not_defined )
5937+ cupsArrayAddStrings (data -> last_expect -> if_not_defined , temp , ',' );
5938+ else
5939+ data -> last_expect -> if_not_defined = cupsArrayNewStrings (temp , ',' );
58855940 }
58865941 else if (data -> last_status )
58875942 {
5888- data -> last_status -> if_not_defined = strdup (temp );
5943+ if (data -> last_status -> if_not_defined )
5944+ cupsArrayAddStrings (data -> last_status -> if_not_defined , temp , ',' );
5945+ else
5946+ data -> last_status -> if_not_defined = cupsArrayNewStrings (temp , ',' );
58895947 }
58905948 else
58915949 {
0 commit comments