test_main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/glocale.h>
  22. #include <grass/N_pde.h>
  23. #include <grass/gmath.h>
  24. #include "test_gpde_lib.h"
  25. /*- Parameters and global variables -----------------------------------------*/
  26. typedef struct
  27. {
  28. struct Option *unit, *integration;
  29. struct Flag *full, *testunit, *testint;
  30. } paramType;
  31. paramType param; /*Parameters */
  32. /*- prototypes --------------------------------------------------------------*/
  33. static void set_params(void); /*Fill the paramType structure */
  34. /* ************************************************************************* */
  35. /* Set up the arguments we are expecting ********************************** */
  36. /* ************************************************************************* */
  37. void set_params(void)
  38. {
  39. param.unit = G_define_option();
  40. param.unit->key = "unit";
  41. param.unit->type = TYPE_STRING;
  42. param.unit->required = NO;
  43. param.unit->options = "array,assemble,geom,gradient,les,tools";
  44. param.unit->description = _("Choose the unit tests to run");
  45. param.integration = G_define_option();
  46. param.integration->key = "integration";
  47. param.integration->type = TYPE_STRING;
  48. param.integration->required = NO;
  49. param.integration->options = "gwflow,heatflow,transport";
  50. param.integration->description = _("Choose the integration tests to run");
  51. param.testunit = G_define_flag();
  52. param.testunit->key = 'u';
  53. param.testunit->description = _("Run all unit tests");
  54. param.testint = G_define_flag();
  55. param.testint->key = 'i';
  56. param.testint->description = _("Run all integration tests");
  57. param.full = G_define_flag();
  58. param.full->key = 'a';
  59. param.full->description = _("Run all unit and integration tests");
  60. }
  61. /* ************************************************************************* */
  62. /* Main function, open the RASTER3D map and create the raster maps ************** */
  63. /* ************************************************************************* */
  64. int main(int argc, char *argv[])
  65. {
  66. struct GModule *module;
  67. int returnstat = 0, i;
  68. /* Initialize GRASS */
  69. G_gisinit(argv[0]);
  70. module = G_define_module();
  71. G_add_keyword("test");
  72. G_add_keyword("gpde");
  73. module->description =
  74. _("Performs unit and integration tests for gpde library");
  75. /* Get parameters from user */
  76. set_params();
  77. if (G_parser(argc, argv))
  78. exit(EXIT_FAILURE);
  79. /*Run the unit tests */
  80. if (param.testunit->answer || param.full->answer) {
  81. returnstat += unit_test_arrays();
  82. returnstat += unit_test_assemble();
  83. returnstat += unit_test_gradient();
  84. returnstat += unit_test_geom_data();
  85. returnstat += unit_test_les_creation();
  86. returnstat += unit_test_tools();
  87. }
  88. /*Run the integration tests */
  89. if (param.testint->answer || param.full->answer) {
  90. returnstat += integration_test_gwflow();
  91. returnstat += integration_test_solute_transport();
  92. }
  93. /*Run single tests */
  94. if (!param.full->answer) {
  95. /*unit tests */
  96. if (!param.testunit->answer) {
  97. i = 0;
  98. if (param.unit->answers)
  99. while (param.unit->answers[i]) {
  100. if (strcmp(param.unit->answers[i], "array") == 0)
  101. returnstat += unit_test_arrays();
  102. if (strcmp(param.unit->answers[i], "assemble") == 0)
  103. returnstat += unit_test_assemble();
  104. if (strcmp(param.unit->answers[i], "gradient") == 0)
  105. returnstat += unit_test_gradient();
  106. if (strcmp(param.unit->answers[i], "geom") == 0)
  107. returnstat += unit_test_geom_data();
  108. if (strcmp(param.unit->answers[i], "les") == 0)
  109. returnstat += unit_test_les_creation();
  110. if (strcmp(param.unit->answers[i], "tools") == 0)
  111. returnstat += unit_test_tools();
  112. i++;
  113. }
  114. }
  115. /*integration tests */
  116. if (!param.testint->answer) {
  117. i = 0;
  118. if (param.integration->answers)
  119. while (param.integration->answers[i]) {
  120. if (strcmp(param.integration->answers[i], "gwflow") == 0)
  121. returnstat += integration_test_gwflow();
  122. if (strcmp(param.integration->answers[i], "heatflow") == 0); /*nothing to do for now */
  123. if (strcmp(param.integration->answers[i], "transport") == 0)
  124. returnstat += integration_test_solute_transport();
  125. i++;
  126. }
  127. }
  128. }
  129. if(returnstat != 0)
  130. G_warning("Errors detected while testing the gpde lib");
  131. else
  132. G_message("\n-- gpde lib tests finished successfully --");
  133. return (returnstat);
  134. }