test_main.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /****************************************************************************
  2. *
  3. * MODULE: test.gpde.lib
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert <at> gmx <dot> de
  7. * 05 Sep 2007 Berlin
  8. *
  9. * PURPOSE: Unit and integration tests for the gmath library
  10. *
  11. * COPYRIGHT: (C) 2007 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 "test_rtree_lib.h"
  23. /*- Parameters and global variables -----------------------------------------*/
  24. typedef struct {
  25. struct Option *unit, *integration, *solverbenchmark, *blasbenchmark, *rows;
  26. struct Flag *full, *testunit, *testint;
  27. } paramType;
  28. paramType param; /*Parameters */
  29. /*- prototypes --------------------------------------------------------------*/
  30. static void set_params(void); /*Fill the paramType structure */
  31. /* ************************************************************************* */
  32. /* Set up the arguments we are expecting ********************************** */
  33. /* ************************************************************************* */
  34. void set_params(void) {
  35. param.unit = G_define_option();
  36. param.unit->key = "unit";
  37. param.unit->type = TYPE_STRING;
  38. param.unit->required = YES;
  39. param.unit->options = "basics";
  40. param.unit->description = _("Choose the unit tests to run");
  41. param.testunit = G_define_flag();
  42. param.testunit->key = 'u';
  43. param.testunit->description = _("Run all unit tests");
  44. }
  45. /* ************************************************************************* */
  46. /* ************************************************************************* */
  47. /* ************************************************************************* */
  48. int main(int argc, char *argv[]) {
  49. struct GModule *module;
  50. int returnstat = 0, i;
  51. /* Initialize GRASS */
  52. G_gisinit(argv[0]);
  53. module = G_define_module();
  54. module->description
  55. = _("Performs benchmarks, unit and integration tests for the gmath library");
  56. /* Get parameters from user */
  57. set_params();
  58. if (G_parser(argc, argv))
  59. exit(EXIT_FAILURE);
  60. /*unit tests */
  61. i = 0;
  62. if (param.unit->answers) {
  63. while (param.unit->answers[i]) {
  64. if (strcmp(param.unit->answers[i], "basics") == 0)
  65. returnstat += unit_test_basics();
  66. i++;
  67. }
  68. }
  69. if (returnstat != 0)
  70. G_warning("Errors detected while testing the gmath lib");
  71. else
  72. G_message("\n-- gmath lib tests finished successfully --");
  73. return (returnstat);
  74. }