Patched to compile on C89 compilers.
1 /* See COPYING.txt for the full license governing this code. */
3 * \file variator_exhaustive.c
5 * Source file for the variator that tests the SUT with all the different
6 * variations of input parameters that are valid.
11 #include "SDL_visualtest_sut_configparser.h"
12 #include "SDL_visualtest_exhaustive_variator.h"
15 NextVariation(SDLVisualTest_Variation* variation,
16 SDLVisualTest_SUTConfig* config)
21 SDLTest_LogError("variation argument cannot be NULL");
26 SDLTest_LogError("config argument cannot be NULL");
31 for(i = 0; i < variation->num_vars; i++)
33 carry = SDLVisualTest_NextValue(&variation->vars[i], &config->options[i]);
38 if(carry == 1) /* we're done, we've tried all possible variations */
42 SDLTest_LogError("NextVariation() failed");
47 SDLVisualTest_InitExhaustiveVariator(SDLVisualTest_ExhaustiveVariator* variator,
48 SDLVisualTest_SUTConfig* config)
52 SDLTest_LogError("variator argument cannot be NULL");
57 SDLTest_LogError("config argument cannot be NULL");
61 SDLTest_FuzzerInit(time(NULL));
63 variator->config = *config;
64 variator->variation.num_vars = 0;
65 variator->variation.vars = NULL;
70 /* TODO: Right now variations where an option is not specified at all are not
71 tested for. This can be implemented by switching the on attribute for integer,
72 enum and string options to true and false. */
74 SDLVisualTest_GetNextExhaustiveVariation(SDLVisualTest_ExhaustiveVariator* variator)
79 SDLTest_LogError("variator argument cannot be NULL");
83 if(!variator->variation.vars) /* the first time this function is called */
85 success = SDLVisualTest_InitVariation(&variator->variation,
89 SDLTest_LogError("SDLVisualTest_InitVariation() failed");
92 success = SDLVisualTest_MakeStrFromVariation(&variator->variation,
93 &variator->config, variator->buffer, MAX_SUT_ARGS_LEN);
96 SDLTest_LogError("SDLVisualTest_MakeStrFromVariation() failed");
99 return variator->buffer;
103 success = NextVariation(&variator->variation, &variator->config);
106 success = SDLVisualTest_MakeStrFromVariation(&variator->variation,
107 &variator->config, variator->buffer, MAX_SUT_ARGS_LEN);
110 SDLTest_LogError("SDLVisualTest_MakeStrFromVariation() failed");
113 return variator->buffer;
115 else if(success == -1)
116 SDLTest_LogError("NextVariation() failed.");
123 SDLVisualTest_FreeExhaustiveVariator(SDLVisualTest_ExhaustiveVariator* variator)
127 SDLTest_LogError("variator argument cannot be NULL");
130 SDL_free(variator->variation.vars);
131 variator->variation.vars = NULL;