1 
2 /****************************************************************************
3 *
4 * MODULE:       test.gpde.lib
5 *
6 * AUTHOR(S):    Original author
7 *               Soeren Gebbert soerengebbert <at> gmx <dot> de
8 * 		27 11 2006 Berlin
9 *
10 * PURPOSE:      Unit and integration tests for the gpde library
11 *
12 * COPYRIGHT:    (C) 2006 by the GRASS Development Team
13 *
14 *               This program is free software under the GNU General Public
15 *   	    	License (>=v2). Read the file COPYING that comes with GRASS
16 *   	    	for details.
17 *
18 *****************************************************************************/
19 #include <stdlib.h>
20 #include <string.h>
21 #include <grass/gis.h>
22 #include <grass/N_pde.h>
23 #include <grass/gmath.h>
24 #include "test_gpde_lib.h"
25 
26 
27 /*- Parameters and global variables -----------------------------------------*/
28 typedef struct
29 {
30     struct Option *unit, *integration;
31     struct Flag *full, *testunit, *testint;
32 } paramType;
33 
34 paramType param;		/*Parameters */
35 
36 /*- prototypes --------------------------------------------------------------*/
37 static void set_params(void);		/*Fill the paramType structure */
38 
39 /* ************************************************************************* */
40 /* Set up the arguments we are expecting ********************************** */
41 /* ************************************************************************* */
set_params(void)42 void set_params(void)
43 {
44     param.unit = G_define_option();
45     param.unit->key = "unit";
46     param.unit->type = TYPE_STRING;
47     param.unit->required = NO;
48     param.unit->options = "array,assemble,geom,gradient,les,tools";
49     param.unit->description = "Choose the unit tests to run";
50 
51     param.integration = G_define_option();
52     param.integration->key = "integration";
53     param.integration->type = TYPE_STRING;
54     param.integration->required = NO;
55     param.integration->options = "gwflow,heatflow,transport";
56     param.integration->description = "Choose the integration tests to run";
57 
58 
59     param.testunit = G_define_flag();
60     param.testunit->key = 'u';
61     param.testunit->description = "Run all unit tests";
62 
63     param.testint = G_define_flag();
64     param.testint->key = 'i';
65     param.testint->description = "Run all integration tests";
66 
67     param.full = G_define_flag();
68     param.full->key = 'a';
69     param.full->description = "Run all unit and integration tests";
70 
71 }
72 
73 /* ************************************************************************* */
74 /* Main function, open the RASTER3D map and create the raster maps ************** */
75 /* ************************************************************************* */
main(int argc,char * argv[])76 int main(int argc, char *argv[])
77 {
78     struct GModule *module;
79     int returnstat = 0, i;
80 
81     /* Initialize GRASS */
82     G_gisinit(argv[0]);
83 
84     module = G_define_module();
85     G_add_keyword("test");
86     G_add_keyword("gpde");
87     module->description =
88 	_("Performs unit and integration tests for gpde library");
89 
90     /* Get parameters from user */
91     set_params();
92 
93     if (G_parser(argc, argv))
94 	exit(EXIT_FAILURE);
95 
96 
97     /*Run the unit tests */
98     if (param.testunit->answer || param.full->answer) {
99 	returnstat += unit_test_arrays();
100 	returnstat += unit_test_assemble();
101 	returnstat += unit_test_gradient();
102 	returnstat += unit_test_geom_data();
103 	returnstat += unit_test_les_creation();
104 	returnstat += unit_test_tools();
105 
106     }
107 
108     /*Run the integration tests */
109     if (param.testint->answer || param.full->answer) {
110 	returnstat += integration_test_gwflow();
111 	returnstat += integration_test_solute_transport();
112     }
113 
114     /*Run single tests */
115     if (!param.full->answer) {
116 	/*unit tests */
117 	if (!param.testunit->answer) {
118 	    i = 0;
119 	    if (param.unit->answers)
120 		while (param.unit->answers[i]) {
121 		    if (strcmp(param.unit->answers[i], "array") == 0)
122 			returnstat += unit_test_arrays();
123 
124 		    if (strcmp(param.unit->answers[i], "assemble") == 0)
125 			returnstat += unit_test_assemble();
126 
127 		    if (strcmp(param.unit->answers[i], "gradient") == 0)
128 			returnstat += unit_test_gradient();
129 
130 		    if (strcmp(param.unit->answers[i], "geom") == 0)
131 			returnstat += unit_test_geom_data();
132 
133 		    if (strcmp(param.unit->answers[i], "les") == 0)
134 			returnstat += unit_test_les_creation();
135 
136 		    if (strcmp(param.unit->answers[i], "tools") == 0)
137 			returnstat += unit_test_tools();
138 
139 		    i++;
140 		}
141 	}
142 	/*integration tests */
143 	if (!param.testint->answer) {
144 	    i = 0;
145 	    if (param.integration->answers)
146 		while (param.integration->answers[i]) {
147 		    if (strcmp(param.integration->answers[i], "gwflow") == 0)
148 			returnstat += integration_test_gwflow();
149 
150 		    if (strcmp(param.integration->answers[i], "heatflow") == 0);	/*nothing to do for now */
151 
152 		    if (strcmp(param.integration->answers[i], "transport") == 0)
153 		        returnstat += integration_test_solute_transport();
154 
155 		    i++;
156 		}
157 
158 	}
159     }
160 
161     if(returnstat != 0)
162     	G_warning("Errors detected while testing the gpde lib");
163     else
164     	G_message("\n-- gpde lib tests finished successfully --");
165 
166     return (returnstat);
167 }
168