test_main.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.depths = G_define_option();
  38. param.depths->key = "depths";
  39. param.depths->type = TYPE_INTEGER;
  40. param.depths->required = NO;
  41. param.depths->answer = "20";
  42. param.depths->description = "The number of depths to be used for the large file put/get value test";
  43. param.rows = G_define_option();
  44. param.rows->key = "rows";
  45. param.rows->type = TYPE_INTEGER;
  46. param.rows->required = NO;
  47. param.rows->answer = "5400";
  48. param.rows->description = "The number of rows to be used for the large file put/get value test";
  49. param.cols = G_define_option();
  50. param.cols->key = "cols";
  51. param.cols->type = TYPE_INTEGER;
  52. param.cols->required = NO;
  53. param.cols->answer = "10800";
  54. param.cols->description = "The number of columns to be used for the large file put/get value test";
  55. param.tile_size = G_define_option();
  56. param.tile_size->key = "tile_size";
  57. param.tile_size->type = TYPE_INTEGER;
  58. param.tile_size->required = NO;
  59. param.tile_size->answer = "32";
  60. 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.";
  61. param.testunit = G_define_flag();
  62. param.testunit->key = 'u';
  63. param.testunit->description = "Run all unit tests";
  64. param.compression = G_define_flag();
  65. param.compression->key = 'l';
  66. param.compression->description = "Switch zip compression on";
  67. }
  68. /* ************************************************************************* */
  69. /* ************************************************************************* */
  70. /* ************************************************************************* */
  71. int main(int argc, char *argv[]) {
  72. struct GModule *module;
  73. int returnstat = 0, i;
  74. int depths, rows, cols, tile_size;
  75. int doCompress = RASTER3D_COMPRESSION;
  76. /* Initialize GRASS */
  77. G_gisinit(argv[0]);
  78. module = G_define_module();
  79. G_add_keyword(_("raster3d"));
  80. G_add_keyword(_("unit test"));
  81. module->description
  82. = "Performs unit and integration tests for the raster3d library";
  83. /* Get parameters from user */
  84. set_params();
  85. if (G_parser(argc, argv))
  86. exit(EXIT_FAILURE);
  87. depths = atoi(param.depths->answer);
  88. rows = atoi(param.rows->answer);
  89. cols = atoi(param.cols->answer);
  90. tile_size = atoi(param.tile_size->answer);
  91. if(param.compression->answer) {
  92. doCompress = RASTER3D_COMPRESSION;
  93. } else {
  94. doCompress = RASTER3D_NO_COMPRESSION;
  95. }
  96. /* Set the compression mode that should be used */
  97. Rast3d_set_compression_mode(doCompress, RASTER3D_MAX_PRECISION);
  98. /* Initiate the defaults for testing */
  99. Rast3d_init_defaults();
  100. /*Run the unit tests */
  101. if (param.testunit->answer) {
  102. returnstat += unit_test_coordinate_transform();
  103. returnstat += unit_test_put_get_value();
  104. returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
  105. }
  106. /*Run single tests */
  107. if (!param.testunit->answer) {
  108. i = 0;
  109. if (param.unit->answers)
  110. while (param.unit->answers[i]) {
  111. if (strcmp(param.unit->answers[i], "coord") == 0)
  112. returnstat += unit_test_coordinate_transform();
  113. if (strcmp(param.unit->answers[i], "putget") == 0)
  114. returnstat += unit_test_put_get_value();
  115. if (strcmp(param.unit->answers[i], "large") == 0)
  116. returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
  117. i++;
  118. }
  119. }
  120. if (returnstat != 0)
  121. G_warning("Errors detected while testing the raster3d lib");
  122. else
  123. G_message("\n-- raster3d lib tests finished successfully --");
  124. return (returnstat);
  125. }