test_main.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. *
  3. * MODULE: test.dbmi_base.lib
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert <at> googlemail <dot> com
  7. * 2010 Braunschweig, Germany
  8. *
  9. * PURPOSE: Unit and integration tests for the dbmi_base 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 <grass/dbmi.h>
  23. #include "test_dbmi_base_lib.h"
  24. /*- Parameters and global variables -----------------------------------------*/
  25. typedef struct {
  26. struct Option *integration, *unit;
  27. struct Flag *full, *testunit, *testint;
  28. } paramType;
  29. paramType param; /*Parameters */
  30. /*- prototypes --------------------------------------------------------------*/
  31. static void set_params(void); /*Fill the paramType structure */
  32. /* ************************************************************************* */
  33. /* Set up the arguments we are expecting ********************************** */
  34. /* ************************************************************************* */
  35. void set_params(void) {
  36. param.unit = G_define_option();
  37. param.unit->key = "unit";
  38. param.unit->type = TYPE_STRING;
  39. param.unit->required = NO;
  40. param.unit->options = "column,table";
  41. param.unit->description = _("Choose the unit tests to run");
  42. param.integration = G_define_option();
  43. param.integration->key = "integration";
  44. param.integration->type = TYPE_STRING;
  45. param.integration->required = NO;
  46. param.integration->options = "";
  47. param.integration->description = _("Choose the integration tests to run");
  48. param.testunit = G_define_flag();
  49. param.testunit->key = 'u';
  50. param.testunit->description = _("Run all unit tests");
  51. param.testint = G_define_flag();
  52. param.testint->key = 'i';
  53. param.testint->description = _("Run all integration tests");
  54. param.full = G_define_flag();
  55. param.full->key = 'a';
  56. param.full->description = _("Run all unit and integration tests");
  57. }
  58. /* ************************************************************************* */
  59. /* ************************************************************************* */
  60. /* ************************************************************************* */
  61. int main(int argc, char *argv[]) {
  62. struct GModule *module;
  63. int returnstat = 0, i;
  64. /* Initialize GRASS */
  65. G_gisinit(argv[0]);
  66. module = G_define_module();
  67. module->description
  68. = _("Performs unit and integration tests for the dbmi base library");
  69. /* Get parameters from user */
  70. set_params();
  71. if (G_parser(argc, argv))
  72. exit(EXIT_FAILURE);
  73. /*Run the unit tests */
  74. if (param.testunit->answer || param.full->answer) {
  75. returnstat += unit_test_column();
  76. returnstat += unit_test_table();
  77. }
  78. /*Run the integration tests */
  79. if (param.testint->answer || param.full->answer) {
  80. ;
  81. }
  82. /*Run single tests */
  83. if (!param.full->answer) {
  84. /*unit tests */
  85. if (!param.testunit->answer) {
  86. i = 0;
  87. if (param.unit->answers)
  88. while (param.unit->answers[i]) {
  89. if (strcmp(param.unit->answers[i], "column") == 0)
  90. returnstat += unit_test_column();
  91. if (strcmp(param.unit->answers[i], "table") == 0)
  92. returnstat += unit_test_table();
  93. i++;
  94. }
  95. }
  96. /*integration tests */
  97. if (!param.testint->answer) {
  98. i = 0;
  99. if (param.integration->answers)
  100. while (param.integration->answers[i]) {
  101. ;
  102. }
  103. }
  104. }
  105. if (returnstat != 0)
  106. G_warning("Errors detected while testing the dbmi_base lib");
  107. else
  108. G_message("\n-- dbmi_base lib tests finished successfully --");
  109. return (returnstat);
  110. }