🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.0 KiB

  1. /* See COPYING.txt for the full license governing this code. */
  2. /**
  3. * \file SDL_visualtest_variator_common.h
  4. *
  5. * Header for common functionality used by variators.
  6. */
  7. #include <SDL_types.h>
  8. #include "SDL_visualtest_sut_configparser.h"
  9. #ifndef SDL_visualtest_variator_common_h_
  10. #define SDL_visualtest_variator_common_h_
  11. /** The number of variations one integer option would generate */
  12. #define SDL_SUT_INTEGER_OPTION_TEST_STEPS 3
  13. /* Set up for C function definitions, even when using C++ */
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /** enum for indicating the type of variator being used */
  18. typedef enum SDLVisualTest_VariatorType
  19. {
  20. SDL_VARIATOR_NONE = 0,
  21. SDL_VARIATOR_EXHAUSTIVE,
  22. SDL_VARIATOR_RANDOM
  23. } SDLVisualTest_VariatorType;
  24. /**
  25. * One possible value for a command line option to the SUT.
  26. */
  27. typedef union SDLVisualTest_SUTOptionValue
  28. {
  29. /*! Value if the option is of type boolean */
  30. SDL_bool bool_value;
  31. /*! Value if the option is of type integer. If on is true then the option
  32. will be passed to the SUT, otherwise it will be ignored. */
  33. struct {
  34. int value;
  35. SDL_bool on;
  36. } integer;
  37. /*! Index of the string in the enum_values field of the corresponding
  38. SDLVisualTest_SUTOption object. If on is true the option will passed
  39. to the SUT, otherwise it will be ignored. */
  40. struct {
  41. int index;
  42. SDL_bool on;
  43. } enumerated;
  44. /*! Value if the option is of type string. If on is true the option will
  45. be passed to the SUT, otherwise it will be ignored. */
  46. struct {
  47. char* value;
  48. SDL_bool on;
  49. } string;
  50. } SDLVisualTest_SUTOptionValue;
  51. /**
  52. * Represents a valid combination of parameters that can be passed to the SUT.
  53. * The ordering of the values here is the same as the ordering of the options in
  54. * the SDLVisualTest_SUTConfig object for this variation.
  55. */
  56. typedef struct SDLVisualTest_Variation
  57. {
  58. /*! Pointer to array of option values */
  59. SDLVisualTest_SUTOptionValue* vars;
  60. /*! Number of option values in \c vars */
  61. int num_vars;
  62. } SDLVisualTest_Variation;
  63. /**
  64. * "Increments" the value of the option by one and returns the carry. We wrap
  65. * around to the initial value on overflow which makes the carry one.
  66. * For example: "incrementing" an SDL_FALSE option makes it SDL_TRUE with no
  67. * carry, and "incrementing" an SDL_TRUE option makes it SDL_FALSE with carry
  68. * one. For integers, a random value in the valid range for the option is used.
  69. *
  70. * \param var Value of the option
  71. * \param opt Object with metadata about the option
  72. *
  73. * \return 1 if there is a carry for enum and bool type options, 0 otherwise.
  74. * 1 is always returned for integer and string type options. -1 is
  75. * returned on error.
  76. */
  77. int SDLVisualTest_NextValue(SDLVisualTest_SUTOptionValue* var,
  78. SDLVisualTest_SUTOption* opt);
  79. /**
  80. * Converts a variation object into a string of command line arguments.
  81. *
  82. * \param variation Variation object to be converted.
  83. * \param config Config object for the SUT.
  84. * \param buffer Pointer to the buffer the arguments string will be copied into.
  85. * \param size Size of the buffer.
  86. *
  87. * \return 1 on success, 0 on failure
  88. */
  89. int SDLVisualTest_MakeStrFromVariation(SDLVisualTest_Variation* variation,
  90. SDLVisualTest_SUTConfig* config,
  91. char* buffer, int size);
  92. /**
  93. * Initializes the variation using the following rules:
  94. * - Boolean options are initialized to SDL_FALSE.
  95. * - Integer options are initialized to the minimum valid value they can hold.
  96. * - Enum options are initialized to the first element in the list of values they
  97. * can take.
  98. * - String options are initialized to the name of the option.
  99. *
  100. * \return 1 on success, 0 on failure.
  101. */
  102. int SDLVisualTest_InitVariation(SDLVisualTest_Variation* variation,
  103. SDLVisualTest_SUTConfig* config);
  104. /* Ends C function definitions when using C++ */
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif /* SDL_visualtest_variator_common_h_ */
  109. /* vi: set ts=4 sw=4 expandtab: */