visualtest/include/SDL_visualtest_variator_common.h
changeset 7924 fcb86d323770
child 11382 2c50e79b19e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/visualtest/include/SDL_visualtest_variator_common.h	Sun Nov 10 00:32:23 2013 -0500
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* See COPYING.txt for the full license governing this code. */
     1.5 +/**
     1.6 + * \file SDL_visualtest_variator_common.h
     1.7 + *
     1.8 + * Header for common functionality used by variators.
     1.9 + */
    1.10 +
    1.11 +#include <SDL_types.h>
    1.12 +#include "SDL_visualtest_sut_configparser.h"
    1.13 +
    1.14 +#ifndef _SDL_visualtest_variator_common_h
    1.15 +#define _SDL_visualtest_variator_common_h
    1.16 +
    1.17 +/** The number of variations one integer option would generate */
    1.18 +#define SDL_SUT_INTEGER_OPTION_TEST_STEPS 3
    1.19 +
    1.20 +/* Set up for C function definitions, even when using C++ */
    1.21 +#ifdef __cplusplus
    1.22 +extern "C" {
    1.23 +#endif
    1.24 +
    1.25 +/** enum for indicating the type of variator being used */
    1.26 +typedef enum SDLVisualTest_VariatorType
    1.27 +{
    1.28 +    SDL_VARIATOR_NONE = 0,
    1.29 +    SDL_VARIATOR_EXHAUSTIVE,
    1.30 +    SDL_VARIATOR_RANDOM
    1.31 +} SDLVisualTest_VariatorType;
    1.32 +
    1.33 +/**
    1.34 + * One possible value for a command line option to the SUT.
    1.35 + */
    1.36 +typedef union SDLVisualTest_SUTOptionValue
    1.37 +{
    1.38 +    /*! Value if the option is of type boolean */
    1.39 +    SDL_bool bool_value;
    1.40 +    /*! Value if the option is of type integer. If on is true then the option
    1.41 +        will be passed to the SUT, otherwise it will be ignored. */
    1.42 +    struct {
    1.43 +        int value;
    1.44 +        SDL_bool on;
    1.45 +    } integer;
    1.46 +    /*! Index of the string in the enum_values field of the corresponding
    1.47 +        SDLVisualTest_SUTOption object. If on is true the option will passed
    1.48 +        to the SUT, otherwise it will be ignored. */
    1.49 +    struct {
    1.50 +        int index;
    1.51 +        SDL_bool on;
    1.52 +    } enumerated;
    1.53 +    /*! Value if the option is of type string. If on is true the option will 
    1.54 +        be passed to the SUT, otherwise it will be ignored. */
    1.55 +    struct {
    1.56 +        char* value;
    1.57 +        SDL_bool on;
    1.58 +    } string;
    1.59 +} SDLVisualTest_SUTOptionValue;
    1.60 +
    1.61 +/**
    1.62 + * Represents a valid combination of parameters that can be passed to the SUT.
    1.63 + * The ordering of the values here is the same as the ordering of the options in
    1.64 + * the SDLVisualTest_SUTConfig object for this variation.
    1.65 + */
    1.66 +typedef struct SDLVisualTest_Variation
    1.67 +{
    1.68 +    /*! Pointer to array of option values */
    1.69 +    SDLVisualTest_SUTOptionValue* vars;
    1.70 +    /*! Number of option values in \c vars */
    1.71 +    int num_vars;
    1.72 +} SDLVisualTest_Variation;
    1.73 +
    1.74 +/**
    1.75 + * "Increments" the value of the option by one and returns the carry. We wrap
    1.76 + * around to the initial value on overflow which makes the carry one.
    1.77 + * For example: "incrementing" an SDL_FALSE option makes it SDL_TRUE with no
    1.78 + * carry, and "incrementing" an SDL_TRUE option makes it SDL_FALSE with carry
    1.79 + * one. For integers, a random value in the valid range for the option is used.
    1.80 + *
    1.81 + * \param var Value of the option
    1.82 + * \param opt Object with metadata about the option
    1.83 + *
    1.84 + * \return 1 if there is a carry for enum and bool type options, 0 otherwise.
    1.85 + *         1 is always returned for integer and string type options. -1 is
    1.86 + *         returned on error.
    1.87 + */
    1.88 +int SDLVisualTest_NextValue(SDLVisualTest_SUTOptionValue* var,
    1.89 +                            SDLVisualTest_SUTOption* opt);
    1.90 +
    1.91 +/**
    1.92 + * Converts a variation object into a string of command line arguments.
    1.93 + *
    1.94 + * \param variation Variation object to be converted.
    1.95 + * \param config Config object for the SUT.
    1.96 + * \param buffer Pointer to the buffer the arguments string will be copied into.
    1.97 + * \param size Size of the buffer.
    1.98 + *
    1.99 + * \return 1 on success, 0 on failure
   1.100 + */
   1.101 +int SDLVisualTest_MakeStrFromVariation(SDLVisualTest_Variation* variation,
   1.102 +                                       SDLVisualTest_SUTConfig* config,
   1.103 +                                       char* buffer, int size);
   1.104 +
   1.105 +/**
   1.106 + * Initializes the variation using the following rules:
   1.107 + * - Boolean options are initialized to SDL_FALSE.
   1.108 + * - Integer options are initialized to the minimum valid value they can hold.
   1.109 + * - Enum options are initialized to the first element in the list of values they
   1.110 + *   can take.
   1.111 + * - String options are initialized to the name of the option.
   1.112 + *
   1.113 + * \return 1 on success, 0 on failure.
   1.114 + */
   1.115 +int SDLVisualTest_InitVariation(SDLVisualTest_Variation* variation,
   1.116 +                                SDLVisualTest_SUTConfig* config);
   1.117 +
   1.118 +/* Ends C function definitions when using C++ */
   1.119 +#ifdef __cplusplus
   1.120 +}
   1.121 +#endif
   1.122 +
   1.123 +#endif /* _SDL_visualtest_variator_common_h */
   1.124 \ No newline at end of file