GRASS Programmer's Manual  6.4.2(2012)
test_main.c
Go to the documentation of this file.
00001 
00002 /****************************************************************************
00003 *
00004 * MODULE:       test.gpde.lib
00005 *               
00006 * AUTHOR(S):    Original author 
00007 *               Soeren Gebbert soerengebbert <at> gmx <dot> de
00008 *               27 11 2006 Berlin
00009 *
00010 * PURPOSE:      Unit and integration tests for the gpde library
00011 *
00012 * COPYRIGHT:    (C) 2006 by the GRASS Development Team
00013 *
00014 *               This program is free software under the GNU General Public
00015 *               License (>=v2). Read the file COPYING that comes with GRASS
00016 *               for details.
00017 *
00018 *****************************************************************************/
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <grass/gis.h>
00022 #include <grass/glocale.h>
00023 #include <grass/N_pde.h>
00024 #include "test_gpde_lib.h"
00025 
00026 
00027 /*- Parameters and global variables -----------------------------------------*/
00028 typedef struct
00029 {
00030     struct Option *unit, *integration;
00031     struct Flag *full, *testunit, *testint;
00032 } paramType;
00033 
00034 paramType param;                /*Parameters */
00035 
00036 /*- prototypes --------------------------------------------------------------*/
00037 static void set_params(void);   /*Fill the paramType structure */
00038 
00039 /* ************************************************************************* */
00040 /* Set up the arguments we are expecting ********************************** */
00041 /* ************************************************************************* */
00042 void set_params(void)
00043 {
00044     param.unit = G_define_option();
00045     param.unit->key = "unit";
00046     param.unit->type = TYPE_STRING;
00047     param.unit->required = NO;
00048     param.unit->options = "array,assemble,geom,gradient,les,solver,tools";
00049     param.unit->description = _("Choose the unit tests to run");
00050 
00051     param.integration = G_define_option();
00052     param.integration->key = "integration";
00053     param.integration->type = TYPE_STRING;
00054     param.integration->required = NO;
00055     param.integration->options = "gwflow,heatflow,transport";
00056     param.integration->description = _("Choose the integration tests to run");
00057 
00058 
00059     param.testunit = G_define_flag();
00060     param.testunit->key = 'u';
00061     param.testunit->description = _("Run all unit tests");
00062 
00063     param.testint = G_define_flag();
00064     param.testint->key = 'i';
00065     param.testint->description = _("Run all integration tests");
00066 
00067     param.full = G_define_flag();
00068     param.full->key = 'a';
00069     param.full->description = _("Run all unit and integration tests");
00070 
00071 }
00072 
00073 /* ************************************************************************* */
00074 /* Main function, open the G3D map and create the raster maps ************** */
00075 /* ************************************************************************* */
00076 int main(int argc, char *argv[])
00077 {
00078     struct GModule *module;
00079     int returnstat = 0, i;
00080 
00081     /* Initialize GRASS */
00082     G_gisinit(argv[0]);
00083 
00084     module = G_define_module();
00085     module->keywords = _("test, gpde");
00086     module->description =
00087         _("Performs unit and integration tests for gpde library");
00088 
00089     /* Get parameters from user */
00090     set_params();
00091 
00092     if (G_parser(argc, argv))
00093         exit(EXIT_FAILURE);
00094 
00095 
00096     /*Run the unit tests */
00097     if (param.testunit->answer || param.full->answer) {
00098         returnstat += unit_test_arrays();
00099         returnstat += unit_test_assemble();
00100         returnstat += unit_test_gradient();
00101         returnstat += unit_test_geom_data();
00102         returnstat += unit_test_les_creation();
00103         returnstat += unit_test_solvers();
00104         returnstat += unit_test_tools();
00105 
00106     }
00107 
00108     /*Run the integration tests */
00109     if (param.testint->answer || param.full->answer) {
00110         returnstat += integration_test_gwflow();
00111         returnstat += integration_test_solute_transport();
00112     }
00113 
00114     /*Run single tests */
00115     if (!param.full->answer) {
00116         /*unit tests */
00117         if (!param.testunit->answer) {
00118             i = 0;
00119             if (param.unit->answers)
00120                 while (param.unit->answers[i]) {
00121                     if (strcmp(param.unit->answers[i], "array") == 0)
00122                         returnstat += unit_test_arrays();
00123 
00124                     if (strcmp(param.unit->answers[i], "assemble") == 0)
00125                         returnstat += unit_test_assemble();
00126 
00127                     if (strcmp(param.unit->answers[i], "gradient") == 0)
00128                         returnstat += unit_test_gradient();
00129 
00130                     if (strcmp(param.unit->answers[i], "geom") == 0)
00131                         returnstat += unit_test_geom_data();
00132 
00133                     if (strcmp(param.unit->answers[i], "les") == 0)
00134                         returnstat += unit_test_les_creation();
00135 
00136                     if (strcmp(param.unit->answers[i], "solver") == 0)
00137                         returnstat += unit_test_solvers();
00138 
00139                     if (strcmp(param.unit->answers[i], "tools") == 0)
00140                         returnstat += unit_test_tools();
00141 
00142                     i++;
00143                 }
00144         }
00145         /*integration tests */
00146         if (!param.testint->answer) {
00147             i = 0;
00148             if (param.integration->answers)
00149                 while (param.integration->answers[i]) {
00150                     if (strcmp(param.integration->answers[i], "gwflow") == 0)
00151                         returnstat += integration_test_gwflow();
00152 
00153                     if (strcmp(param.integration->answers[i], "heatflow") == 0) ;       /*nothing to do for now */
00154 
00155                     if (strcmp(param.integration->answers[i], "transport") ==
00156                         0)
00157                         returnstat += integration_test_solute_transport();
00158 
00159                     i++;
00160                 }
00161 
00162         }
00163     }
00164 
00165     if (returnstat != 0)
00166         G_warning("Errors detected while testing the gpde lib");
00167     else
00168         G_message("\n-- gpde lib tests finished successfully --");
00169 
00170     return (returnstat);
00171 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines