vector.com|Contact
Search tips

apple banana
Find rows that contain at least one of the two words.

+apple +juice
Find rows that contain both words.

+apple macintosh
Find rows that contain the word 'apple', but rank rows higher if they also contain 'macintosh'.

+apple -macintosh
Find rows that contain the word 'apple' but not 'macintosh'.

+apple ~macintosh
Find rows that contain the word 'apple', but if the row also contains the word 'macintosh', rate it lower than if row does not. This is "softer" than a search for '+apple -macintosh', for which the presence of 'macintosh' causes the row not to be returned at all.

+apple +(>turnover >strudel)
Find rows that contain the words 'apple' and 'turnover', or 'apple' and 'strudel' (in any order), but rank 'apple turnover' higher than 'apple strudel'.

apple*
Find rows that contain words such as 'apple', 'apples', 'applesauce', or 'applet'.

"some words"
Find rows that contain the exact phrase 'some words' (for example, rows that contain 'some words of wisdom' but not "some noise words").

By continuing to use this site you agree to the use of cookies. For more information and to find out how to change this click here. Accept Cookies
Please enable cookies in your browser for this website.
Search:
Advanced search

How to Test Variadic Functions

Last updated: 2019-11-13
Question:
How can I test variadic functions (functions which take a variable number of arguments)?
Answer:

To test variadic functions you can use unit appendix user code to create a wrapper function for each combination of argument types you wish to use to call your variadic function. For example, let's say you want to test a function called formatted_print that works like sprintf but returns a malloc-ed string.

The prototype is:


char* formatted_print (const char* format, ...);


Let's say you want to test this function with 1 and 2 additional arguments of type int and char*, in all possible combinations. You would therefore add the following code to your unit appendix user code. (The function suffixes are based on the specifiers used in the format string which indicate the type of the given argument.)
 

char* formatted_print_d (const char* format, int arg1)
{
  return formatted_print( format, arg1 );
}
char* formatted_print_s (const char* format, const char* arg1)
{
  return formatted_print( format, arg1 );
}
char* formatted_print_d_d (const char* format, int arg1, int arg2)
{
  return formatted_print( format, arg1, arg2 );
}
char* formatted_print_d_s (const char* format, int arg1, const char* arg2)
{
  return formatted_print( format, arg1, arg2 );
}
char* formatted_print_s_d (const char* format, const char* arg1, int arg2)
{
  return formatted_print( format, arg1, arg2 );
}
char* formatted_print_s_s (const char* format, const char* arg1, const char* arg2)
{
  return formatted_print( format, arg1, arg2 );
}


If you add the code to unit appendix user code after you have built the environment, rebuild the environment to have the new functions appear in your test case tree. After rebuilding the environment, you can add test cases for the new functions as you normally would. 
 

 
Article Options
2019-11-13
Views: 8