test_main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /****************************************************************************
  2. *
  3. * MODULE: test.gpde.lib
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert <at> gmx <dot> de
  7. * 27 11 2006 Berlin
  8. *
  9. * PURPOSE: Unit and integration tests for the gpde library
  10. *
  11. * COPYRIGHT: (C) 2006 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <grass/gis.h>
  21. #include <grass/N_pde.h>
  22. #include <grass/gmath.h>
  23. #include "test_gpde_lib.h"
  24. /*- Parameters and global variables -----------------------------------------*/
  25. typedef struct
  26. {
  27. struct Option *unit, *integration;
  28. struct Flag *full, *testunit, *testint;
  29. } paramType;
  30. paramType param; /*Parameters */
  31. /*- prototypes --------------------------------------------------------------*/
  32. static void set_params(void); /*Fill the paramType structure */
  33. /* ************************************************************************* */
  34. /* Set up the arguments we are expecting ********************************** */
  35. /* ************************************************************************* */
  36. void set_params(void)
  37. {
  38. param.unit = G_define_option();
  39. param.unit->key = "unit";
  40. param.unit->type = TYPE_STRING;
  41. param.unit->required = NO;
  42. param.unit->options = "array,assemble,geom,gradient,les,tools";
  43. param.unit->description = "Choose the unit tests to run";
  44. param.integration = G_define_option();
  45. param.integration->key = "integration";
  46. param.integration->type = TYPE_STRING;
  47. param.integration->required = NO;
  48. param.integration->options = "gwflow,heatflow,transport";
  49. param.integration->description = "Choose the integration tests to run";
  50. param.testunit = G_define_flag();
  51. param.testunit->key = 'u';
  52. param.testunit->description = "Run all unit tests";
  53. param.testint = G_define_flag();
  54. param.testint->key = 'i';
  55. param.testint->description = "Run all integration tests";
  56. param.full = G_define_flag();
  57. param.full->key = 'a';
  58. param.full->description = "Run all unit and integration tests";
  59. }
  60. /* ************************************************************************* */
  61. /* Main function, open the RASTER3D map and create the raster maps ************** */
  62. /* ************************************************************************* */
  63. int main(int argc, char *argv[])
  64. {
  65. struct GModule *module;
  66. int returnstat = 0, i;
  67. /* Initialize GRASS */
  68. G_gisinit(argv[0]);
  69. module = G_define_module();
  70. G_add_keyword("test");
  71. G_add_keyword("gpde");
  72. module->description =
  73. _("Performs unit and integration tests for gpde library");
  74. /* Get parameters from user */
  75. set_params();
  76. if (G_parser(argc, argv))
  77. exit(EXIT_FAILURE);
  78. /*Run the unit tests */
  79. if (param.testunit->answer || param.full->answer) {
  80. returnstat += unit_test_arrays();
  81. returnstat += unit_test_assemble();
  82. returnstat += unit_test_gradient();
  83. returnstat += unit_test_geom_data();
  84. returnstat += unit_test_les_creation();
  85. returnstat += unit_test_tools();
  86. }
  87. /*Run the integration tests */
  88. if (param.testint->answer || param.full->answer) {
  89. returnstat += integration_test_gwflow();
  90. returnstat += integration_test_solute_transport();
  91. }
  92. /*Run single tests */
  93. if (!param.full->answer) {
  94. /*unit tests */
  95. if (!param.testunit->answer) {
  96. i = 0;
  97. if (param.unit->answers)
  98. while (param.unit->answers[i]) {
  99. if (strcmp(param.unit->answers[i], "array") == 0)
  100. returnstat += unit_test_arrays();
  101. if (strcmp(param.unit->answers[i], "assemble") == 0)
  102. returnstat += unit_test_assemble();
  103. if (strcmp(param.unit->answers[i], "gradient") == 0)
  104. returnstat += unit_test_gradient();
  105. if (strcmp(param.unit->answers[i], "geom") == 0)
  106. returnstat += unit_test_geom_data();
  107. if (strcmp(param.unit->answers[i], "les") == 0)
  108. returnstat += unit_test_les_creation();
  109. if (strcmp(param.unit->answers[i], "tools") == 0)
  110. returnstat += unit_test_tools();
  111. i++;
  112. }
  113. }
  114. /*integration tests */
  115. if (!param.testint->answer) {
  116. i = 0;
  117. if (param.integration->answers)
  118. while (param.integration->answers[i]) {
  119. if (strcmp(param.integration->answers[i], "gwflow") == 0)
  120. returnstat += integration_test_gwflow();
  121. if (strcmp(param.integration->answers[i], "heatflow") == 0); /*nothing to do for now */
  122. if (strcmp(param.integration->answers[i], "transport") == 0)
  123. returnstat += integration_test_solute_transport();
  124. i++;
  125. }
  126. }
  127. }
  128. if(returnstat != 0)
  129. G_warning("Errors detected while testing the gpde lib");
  130. else
  131. G_message("\n-- gpde lib tests finished successfully --");
  132. return (returnstat);
  133. }