test_main.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*****************************************************************************
  2. *
  3. * MODULE: Grass g3d Library
  4. * AUTHOR(S): Soeren Gebbert, Braunschweig (GER) Jun 2011
  5. * soerengebbert <at> googlemail <dot> com
  6. *
  7. * PURPOSE: Unit and Integration tests
  8. *
  9. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "test_g3d_lib.h"
  19. /*- Parameters and global variables -----------------------------------------*/
  20. typedef struct {
  21. struct Option *unit, *integration, *depths, *rows, *cols;
  22. struct Flag *full, *testunit, *testint;
  23. } paramType;
  24. paramType param; /*Parameters */
  25. /*- prototypes --------------------------------------------------------------*/
  26. static void set_params(void); /*Fill the paramType structure */
  27. /* ************************************************************************* */
  28. /* Set up the arguments we are expecting ********************************** */
  29. /* ************************************************************************* */
  30. void set_params(void) {
  31. param.unit = G_define_option();
  32. param.unit->key = "unit";
  33. param.unit->type = TYPE_STRING;
  34. param.unit->required = NO;
  35. param.unit->options = "coord,putget,large";
  36. param.unit->description = _("Choose the unit tests to run");
  37. param.integration = G_define_option();
  38. param.integration->key = "integration";
  39. param.integration->type = TYPE_STRING;
  40. param.integration->required = NO;
  41. param.integration->options = "";
  42. param.integration->description = _("Choose the integration tests to run");
  43. param.depths = G_define_option();
  44. param.depths->key = "depths";
  45. param.depths->type = TYPE_INTEGER;
  46. param.depths->required = NO;
  47. param.depths->answer = "20";
  48. param.depths->description = _("The number of depths to be used for the large file put value test");
  49. param.rows = G_define_option();
  50. param.rows->key = "rows";
  51. param.rows->type = TYPE_INTEGER;
  52. param.rows->required = NO;
  53. param.rows->answer = "5400";
  54. param.rows->description = _("The number of rows to be used for the large file put value test");
  55. param.cols = G_define_option();
  56. param.cols->key = "cols";
  57. param.cols->type = TYPE_INTEGER;
  58. param.cols->required = NO;
  59. param.cols->answer = "10800";
  60. param.cols->description = _("The number of columns to be used for the large file put value test");
  61. param.testunit = G_define_flag();
  62. param.testunit->key = 'u';
  63. param.testunit->description = _("Run all unit tests");
  64. param.testint = G_define_flag();
  65. param.testint->key = 'i';
  66. param.testint->description = _("Run all integration tests");
  67. param.full = G_define_flag();
  68. param.full->key = 'a';
  69. param.full->description = _("Run all unit and integration tests");
  70. }
  71. /* ************************************************************************* */
  72. /* ************************************************************************* */
  73. /* ************************************************************************* */
  74. int main(int argc, char *argv[]) {
  75. struct GModule *module;
  76. int returnstat = 0, i;
  77. int depths, rows, cols;
  78. /* Initialize GRASS */
  79. G_gisinit(argv[0]);
  80. module = G_define_module();
  81. module->description
  82. = _("Performs unit and integration tests for the g3d library");
  83. /* Get parameters from user */
  84. set_params();
  85. if (G_parser(argc, argv))
  86. exit(EXIT_FAILURE);
  87. depths = atoi(param.depths->answer);
  88. rows = atoi(param.rows->answer);
  89. cols = atoi(param.cols->answer);
  90. /* Initiate the defaults for testing */
  91. Rast3d_init_defaults();
  92. /*Run the unit tests */
  93. if (param.testunit->answer || param.full->answer) {
  94. returnstat += unit_test_coordinate_transform();
  95. returnstat += unit_test_put_get_value();
  96. returnstat += unit_test_put_get_value_large_file(depths, rows, cols);
  97. }
  98. /*Run the integration tests */
  99. if (param.testint->answer || param.full->answer) {
  100. ;
  101. }
  102. /*Run single tests */
  103. if (!param.full->answer) {
  104. /*unit tests */
  105. if (!param.testunit->answer) {
  106. i = 0;
  107. if (param.unit->answers)
  108. while (param.unit->answers[i]) {
  109. if (strcmp(param.unit->answers[i], "coord") == 0)
  110. returnstat += unit_test_coordinate_transform();
  111. if (strcmp(param.unit->answers[i], "putget") == 0)
  112. returnstat += unit_test_put_get_value();
  113. if (strcmp(param.unit->answers[i], "large") == 0)
  114. returnstat += unit_test_put_get_value_large_file(depths, rows, cols);
  115. i++;
  116. }
  117. }
  118. /*integration tests */
  119. if (!param.testint->answer) {
  120. i = 0;
  121. if (param.integration->answers)
  122. while (param.integration->answers[i]) {
  123. ;
  124. }
  125. }
  126. }
  127. if (returnstat != 0)
  128. G_warning("Errors detected while testing the g3d lib");
  129. else
  130. G_message("\n-- g3d lib tests finished successfully --");
  131. return (returnstat);
  132. }