-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
test_main.c
153 lines (125 loc) · 5.4 KB
/
test_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*****************************************************************************
*
* MODULE: Grass raster3d Library
* AUTHOR(S): Soeren Gebbert, Braunschweig (GER) Jun 2011
* soerengebbert <at> googlemail <dot> com
*
* PURPOSE: Unit and Integration tests
*
* COPYRIGHT: (C) 2000 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "test_raster3d_lib.h"
/*- Parameters and global variables -----------------------------------------*/
typedef struct {
struct Option *unit, *integration, *depths, *rows, *cols, *tile_size;
struct Flag *full, *testunit, *testint, *rle, *compression;
} paramType;
paramType param; /*Parameters */
/*- prototypes --------------------------------------------------------------*/
static void set_params(void); /*Fill the paramType structure */
/* ************************************************************************* */
/* Set up the arguments we are expecting ********************************** */
/* ************************************************************************* */
void set_params(void) {
param.unit = G_define_option();
param.unit->key = "unit";
param.unit->type = TYPE_STRING;
param.unit->required = NO;
param.unit->options = "coord,putget,large";
param.unit->description = "Choose the unit tests to run";
param.depths = G_define_option();
param.depths->key = "depths";
param.depths->type = TYPE_INTEGER;
param.depths->required = NO;
param.depths->answer = "20";
param.depths->description = "The number of depths to be used for the large file put/get value test";
param.rows = G_define_option();
param.rows->key = "rows";
param.rows->type = TYPE_INTEGER;
param.rows->required = NO;
param.rows->answer = "5400";
param.rows->description = "The number of rows to be used for the large file put/get value test";
param.cols = G_define_option();
param.cols->key = "cols";
param.cols->type = TYPE_INTEGER;
param.cols->required = NO;
param.cols->answer = "10800";
param.cols->description = "The number of columns to be used for the large file put/get value test";
param.tile_size = G_define_option();
param.tile_size->key = "tile_size";
param.tile_size->type = TYPE_INTEGER;
param.tile_size->required = NO;
param.tile_size->answer = "32";
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.";
param.testunit = G_define_flag();
param.testunit->key = 'u';
param.testunit->description = "Run all unit tests";
param.compression = G_define_flag();
param.compression->key = 'l';
param.compression->description = "Switch zip compression on";
}
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int main(int argc, char *argv[]) {
struct GModule *module;
int returnstat = 0, i;
int depths, rows, cols, tile_size;
int doCompress = RASTER3D_COMPRESSION;
/* Initialize GRASS */
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("raster3d"));
G_add_keyword(_("unit test"));
module->description
= "Performs unit and integration tests for the raster3d library";
/* Get parameters from user */
set_params();
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
depths = atoi(param.depths->answer);
rows = atoi(param.rows->answer);
cols = atoi(param.cols->answer);
tile_size = atoi(param.tile_size->answer);
if(param.compression->answer) {
doCompress = RASTER3D_COMPRESSION;
} else {
doCompress = RASTER3D_NO_COMPRESSION;
}
/* Set the compression mode that should be used */
Rast3d_set_compression_mode(doCompress, RASTER3D_MAX_PRECISION);
/* Initiate the defaults for testing */
Rast3d_init_defaults();
/*Run the unit tests */
if (param.testunit->answer) {
returnstat += unit_test_coordinate_transform();
returnstat += unit_test_put_get_value();
returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
}
/*Run single tests */
if (!param.testunit->answer) {
i = 0;
if (param.unit->answers)
while (param.unit->answers[i]) {
if (strcmp(param.unit->answers[i], "coord") == 0)
returnstat += unit_test_coordinate_transform();
if (strcmp(param.unit->answers[i], "putget") == 0)
returnstat += unit_test_put_get_value();
if (strcmp(param.unit->answers[i], "large") == 0)
returnstat += unit_test_put_get_value_large_file(depths, rows, cols, tile_size);
i++;
}
}
if (returnstat != 0)
G_warning("Errors detected while testing the raster3d lib");
else
G_message("\n-- raster3d lib tests finished successfully --");
return (returnstat);
}