@@ -44,8 +44,8 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
4444 struct env_set * es )
4545{
4646 function_called ();
47- check_expected (p );
48- check_expected (is_inline );
47+ check_expected_ptr (p );
48+ check_expected_uint (is_inline );
4949}
5050
5151void
@@ -198,31 +198,27 @@ read_single_config(struct options *options, const char *config)
198198 & option_types_found , & es );
199199}
200200
201- /* compat with various versions of cmocka.h
202- * Older versions have LargestIntegralType. Newer
203- * versions use uintmax_t. But LargestIntegralType
204- * is not guaranteed to be equal to uintmax_t, so
205- * we can't use that unconditionally. So we only use
206- * it if cmocka.h does not define LargestIntegralType.
207- */
208- #ifndef LargestIntegralType
209- #define LargestIntegralType uintmax_t
210- #endif
211-
212- union tokens_parameter
201+ #if HAVE_OLD_CMOCKA_API
202+ union token_parameter
213203{
214- LargestIntegralType as_int ;
215- void * as_pointer ;
204+ LargestIntegralType int_val ;
205+ void * ptr ;
216206};
207+ #endif
217208
218209static int
219- check_tokens (const LargestIntegralType value , const LargestIntegralType expected )
210+ check_tokens (const CMockaValueData value , const CMockaValueData expected )
220211{
221- union tokens_parameter temp ;
222- temp .as_int = value ;
223- const char * * p = (const char * * )temp .as_pointer ;
224- temp .as_int = expected ;
225- const char * * expected_p = (const char * * )temp .as_pointer ;
212+ #if HAVE_OLD_CMOCKA_API
213+ union token_parameter temp ;
214+ temp .int_val = value ;
215+ const char * * p = (const char * * )temp .ptr ;
216+ temp .int_val = expected ;
217+ const char * * expected_p = (const char * * )temp .ptr ;
218+ #else
219+ const char * * p = (const char * * )value .ptr ;
220+ const char * * expected_p = (const char * * )expected .ptr ;
221+ #endif
226222 for (int i = 0 ; i < MAX_PARMS ; i ++ )
227223 {
228224 if (!p [i ] && !expected_p [i ])
@@ -271,33 +267,33 @@ test_read_config(void **state)
271267
272268 /* basic test */
273269 expect_function_call (add_option );
274- expect_check (add_option , p , check_tokens , p_expect_someopt );
275- expect_value (add_option , is_inline , 0 );
270+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_someopt ) );
271+ expect_uint_value (add_option , is_inline , 0 );
276272 expect_function_call (add_option );
277- expect_check (add_option , p , check_tokens , p_expect_otheropt );
278- expect_value (add_option , is_inline , 0 );
273+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_otheropt ) );
274+ expect_uint_value (add_option , is_inline , 0 );
279275 read_single_config (& o , "someopt parm1 parm2\n otheropt 1 2" );
280276
281277 /* -- gets stripped */
282278 expect_function_call (add_option );
283- expect_check (add_option , p , check_tokens , p_expect_someopt );
284- expect_value (add_option , is_inline , 0 );
279+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_someopt ) );
280+ expect_uint_value (add_option , is_inline , 0 );
285281 expect_function_call (add_option );
286- expect_check (add_option , p , check_tokens , p_expect_otheropt );
287- expect_value (add_option , is_inline , 0 );
282+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_otheropt ) );
283+ expect_uint_value (add_option , is_inline , 0 );
288284 read_single_config (& o , "someopt parm1 parm2\n\t--otheropt 1 2" );
289285
290286 /* inline options */
291287 expect_function_call (add_option );
292- expect_check (add_option , p , check_tokens , p_expect_inlineopt );
293- expect_value (add_option , is_inline , 1 );
288+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_inlineopt ) );
289+ expect_uint_value (add_option , is_inline , 1 );
294290 read_single_config (& o , "<inlineopt>\nsome text\nother text\n</inlineopt>" );
295291
296292 p_expect_inlineopt [0 ] = "inlineopt" ;
297293 p_expect_inlineopt [1 ] = A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 "\n" ;
298294 expect_function_call (add_option );
299- expect_check (add_option , p , check_tokens , p_expect_inlineopt );
300- expect_value (add_option , is_inline , 1 );
295+ expect_check_data (add_option , p , check_tokens , cast_ptr_to_cmocka_value ( p_expect_inlineopt ) );
296+ expect_uint_value (add_option , is_inline , 1 );
301297 read_single_config (& o , "<inlineopt>\n" A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 "\n</inlineopt>" );
302298
303299 gc_free (& o .gc );
0 commit comments