test_main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*****************************************************************************
  2. *
  3. * MODULE: Grass raster3d 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_raster3d_lib.h"
  19. /*- Parameters and global variables -----------------------------------------*/
  20. typedef struct {
  21. struct Option *unit, *integration, *depths, *rows, *cols, *tile_size;
  22. struct Flag *full, *testunit, *testint, *rle, *compression;
  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/get 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/get 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/get value test";
  61. param.tile_size = G_define_option();
  62. param.tile_size->key = "tile_size";
  63. param.tile_size->type = TYPE_INTEGER;
  64. param.tile_size->required = NO;
  65. param.tile_size->answer = "32";
  66. param.tile_size->description = "The tile size in kilo bytes to be used for the large file put/get value test. Set the tile size to 2048 and the number of row*cols*depths > 130000 to reproduce the tile rle error.";
  67. param.testunit = G_define_flag();
  68. param.testunit->key = 'u';
  69. param.testunit->description = "Run all unit tests";
  70. param.testint = G_define_flag();
  71. param.testint->key = 'i';
  72. param.testint->description = "Run all integration tests";
  73. param.full = G_define_flag();
  74. param.full->key = 'a';
  75. param.full->description = "Run all unit and integration tests";
  76. param.compression = G_define_flag();
  77. param.compression->key = 'l';
  78. param.compression->description = "Switch zip compression on";
  79. }
  80. /* ************************************************************************* */
  81. /* ************************************************************************* */
  82. /* ************************************************************************* */
  83. int main(int argc, char *argv[]) {
  84. struct GModule *module;
  85. int returnstat = 0, i;
  86. int depths, rows, cols, tile_size;
  87. int doCompress = RASTER3D_COMPRESSION;
  88. /* Initialize GRASS */
  89. G_gisinit(argv[0]);
  90. module = G_define_module();
  91. module->description
  92. = "Performs unit and integration tests for the raster3d library";
  93. /* Get parameters from user */
  94. set_params();
  95. if (G_parser(argc, argv))
  96. exit(EXIT_FAILURE);
  97. depths = atoi(param.depths->answer);
  98. rows = atoi(param.rows->answer);
  99. cols = atoi(param.cols->answer);
  100. tile_size = atoi(param.tile_size->answer);
  101. if(param.compression->answer) {
  102. doCompress = RASTER3D_COMPRESSION;
  103. } else {
  104. doCompress = RASTER3D_NO_COMPRESSION;
  105. }
  106. /* Set the compression mode that should be used */
  107. Rast3d_set_compression_mode(doCompress, RASTER3D_MAX_PRECISION);
  108. /* Initiate the defaults for testing */
  109. Rast3d_init_defaults();
  110. /*Run the unit tests */
  111. if (param.testunit->answer || param.full->answer) {
  112. returnstat += unit_test_coordinate_transform();
  113. returnstat += unit_test_put_get_value();
  114. returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
  115. }
  116. /*Run the integration tests */
  117. if (param.testint->answer || param.full->answer) {
  118. ;
  119. }
  120. /*Run single tests */
  121. if (!param.full->answer) {
  122. /*unit tests */
  123. if (!param.testunit->answer) {
  124. i = 0;
  125. if (param.unit->answers)
  126. while (param.unit->answers[i]) {
  127. if (strcmp(param.unit->answers[i], "coord") == 0)
  128. returnstat += unit_test_coordinate_transform();
  129. if (strcmp(param.unit->answers[i], "putget") == 0)
  130. returnstat += unit_test_put_get_value();
  131. if (strcmp(param.unit->answers[i], "large") == 0)
  132. returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
  133. i++;
  134. }
  135. }
  136. /*integration tests */
  137. if (!param.testint->answer) {
  138. i = 0;
  139. if (param.integration->answers)
  140. while (param.integration->answers[i]) {
  141. ;
  142. }
  143. }
  144. }
  145. if (returnstat != 0)
  146. G_warning("Errors detected while testing the raster3d lib");
  147. else
  148. G_message("\n-- raster3d lib tests finished successfully --");
  149. return (returnstat);
  150. }