unit_testing_main.c

Go to the documentation of this file.
00001 /**
00002 \file    unit_testing_main.c
00003 \brief   GNSS core 'c' function library: unit testing main().
00004 \author  Glenn D. MacGougan (GDM)
00005 \date    2007-11-29
00006 \since   2007-11-29
00007 
00008 \b "LICENSE INFORMATION" \n
00009 Copyright (c) 2007, refer to 'author' doxygen tags \n
00010 All rights reserved. \n
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided the following conditions are met: \n
00014 
00015 - Redistributions of source code must retain the above copyright
00016   notice, this list of conditions and the following disclaimer. \n
00017 - Redistributions in binary form must reproduce the above copyright
00018   notice, this list of conditions and the following disclaimer in the
00019   documentation and/or other materials provided with the distribution. \n
00020 - The name(s) of the contributor(s) may not be used to endorse or promote 
00021   products derived from this software without specific prior written 
00022   permission. \n
00023 
00024 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00025 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00028 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00030 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00032 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00033 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00034 SUCH DAMAGE.
00035 */
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include "Basic.h"  // CUnit/Basic.h
00041 #include "time_conversion.h"
00042 #include "test_geodesy.h"
00043 #include "test_time_conversion.h"
00044 #include "test_novatel.h"
00045 #include "test_yuma.h"
00046 #include "test_ionosphere.h"
00047 #include "test_rinex.h"
00048 
00049 
00050 /** \brief The function where all suites and tests are added. */
00051 int AddTests();
00052 
00053 /** \brief Print the time the test occurred to stdout. */
00054 static void print_system_time(void);
00055 
00056 int main(int argc, char* argv[])
00057 {
00058   CU_BasicRunMode mode = CU_BRM_VERBOSE;
00059   CU_ErrorAction error_action = CUEA_IGNORE;
00060   int i;
00061 
00062   setvbuf(stdout, NULL, _IONBF, 0);
00063 
00064   for (i=1 ; i<argc ; i++) 
00065   {
00066     if (!strcmp("-i", argv[i])) 
00067     {
00068       error_action = CUEA_IGNORE;
00069     }
00070     else if (!strcmp("-f", argv[i])) 
00071     {
00072       error_action = CUEA_FAIL;
00073     }
00074     else if (!strcmp("-A", argv[i])) 
00075     {
00076       error_action = CUEA_ABORT;
00077     }
00078     else if (!strcmp("-s", argv[i])) 
00079     {
00080       mode = CU_BRM_SILENT;
00081     }
00082     else if (!strcmp("-n", argv[i])) 
00083     {
00084       mode = CU_BRM_NORMAL;
00085     }
00086     else if (!strcmp("-v", argv[i])) 
00087     {
00088       mode = CU_BRM_VERBOSE;
00089     }
00090     /*
00091     else if (!strcmp("-e", argv[i])) 
00092     {
00093       print_example_results();
00094       return 0;
00095     }
00096     */
00097     else 
00098     {
00099       printf("\nUsage:  eGNSS_Test [options]\n\n"
00100                "Options:   -i   ignore framework errors [default].\n"
00101                "           -f   fail on framework error.\n"
00102                "           -A   abort on framework error.\n\n"
00103                "           -s   silent mode - no output to screen.\n"
00104                "           -n   normal mode - standard output to screen.\n"
00105                "           -v   verbose mode - max output to screen [default].\n\n"
00106              /*"           -e   print expected test results and exit.\n"*/
00107                "           -h   print this message and exit.\n\n");
00108       return 0;
00109     }
00110   }
00111 
00112   // Output system time and date.
00113   print_system_time();
00114 
00115   if (CU_initialize_registry()) 
00116   {
00117     printf("\nInitialization of Test Registry failed.");
00118   }
00119   else 
00120   {
00121     if( AddTests() == CUE_SUCCESS )
00122     {
00123       CU_basic_set_mode(mode);
00124       CU_set_error_action(error_action);
00125       printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
00126     }
00127     CU_cleanup_registry();
00128   }
00129 
00130   return 0;
00131 }
00132 
00133 
00134 
00135 /** 
00136 The AddTests() function for setting up the tests. 
00137 */
00138 int AddTests()
00139 {
00140   CU_pSuite pSuite = NULL;
00141 
00142 
00143 
00144   /* add a suite to the registry */
00145   pSuite = CU_add_suite("GEODESY", init_suite_GEODESY, clean_suite_GEODESY);
00146   if (NULL == pSuite)   
00147     return CU_get_error();
00148   
00149   /* add the tests to the suite */
00150   if( CU_add_test(pSuite, "GEODESY_GetReferenceEllipseParameters()", test_GEODESY_GetReferenceEllipseParameters) == NULL )
00151     return CU_get_error();
00152   if( CU_add_test(pSuite, "test_GEODESY_ConvertCoordinates()", test_GEODESY_ConvertCoordinates) == NULL )
00153     return CU_get_error();
00154   if( CU_add_test(pSuite, "GEODESY_ComputeNorthingEastingVertical()", test_GEODESY_ComputeNorthingEastingVertical) == NULL )
00155     return CU_get_error();
00156   if( CU_add_test(pSuite, "GEODESY_ComputePositionDifference()", test_GEODESY_ComputePositionDifference) == NULL )
00157     return CU_get_error();
00158   if( CU_add_test(pSuite, "GEODESY_ComputeMeridianRadiusOfCurvature()", test_GEODESY_ComputeMeridianRadiusOfCurvature) == NULL )
00159     return CU_get_error();
00160   if( CU_add_test(pSuite, "GEODESY_ComputePrimeVerticalRadiusOfCurvature()", test_GEODESY_ComputePrimeVerticalRadiusOfCurvature) == NULL )
00161     return CU_get_error();
00162   if( CU_add_test(pSuite, "GEODESY_ComputeMeridianArcBetweenTwoLatitudes()", test_GEODESY_ComputeMeridianArcBetweenTwoLatitudes) == NULL )
00163     return CU_get_error();
00164   if( CU_add_test(pSuite, "GEODESY_ComputeParallelArcBetweenTwoLongitudes()", test_GEODESY_ComputeParallelArcBetweenTwoLongitudes) == NULL )
00165     return CU_get_error();
00166   if( CU_add_test(pSuite, "GEODESY_RotateVectorFromLocalGeodeticFrameToEarthFixedFrame()", test_GEODESY_RotateVectorFromLocalGeodeticFrameToEarthFixedFrame) == NULL )
00167     return CU_get_error();
00168   if( CU_add_test(pSuite, "GEODESY_RotateVectorFromEarthFixedFrameToLocalGeodeticFrame()", test_GEODESY_RotateVectorFromEarthFixedFrameToLocalGeodeticFrame) == NULL )
00169     return CU_get_error();
00170   if( CU_add_test(pSuite, "GEODESY_ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame()", test_GEODESY_ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame) == NULL )
00171     return CU_get_error();
00172 
00173 
00174 
00175 
00176   /* add a suite to the registry */
00177   pSuite = CU_add_suite("TIMECONV", init_suite_GEODESY, clean_suite_GEODESY);
00178   if (NULL == pSuite)   
00179     return CU_get_error();
00180   
00181   /* add the tests to the suite */
00182   if( CU_add_test(pSuite, "TIMECONV_GetJulianDateFromGPSTime()", test_TIMECONV_GetJulianDateFromGPSTime) == NULL )
00183     return CU_get_error();
00184   if( CU_add_test(pSuite, "TIMECONV_GetJulianDateFromUTCTime()", test_TIMECONV_GetJulianDateFromUTCTime) == NULL )
00185     return CU_get_error();
00186   if( CU_add_test(pSuite, "TIMECONV_GetGPSTimeFromJulianDate()", test_TIMECONV_GetGPSTimeFromJulianDate) == NULL )
00187     return CU_get_error();
00188   if( CU_add_test(pSuite, "TIMECONV_GetUTCTimeFromJulianDate()", test_TIMECONV_GetUTCTimeFromJulianDate) == NULL )
00189     return CU_get_error();
00190   if( CU_add_test(pSuite, "TIMECONV_GetGPSTimeFromUTCTime()", test_TIMECONV_GetGPSTimeFromUTCTime) == NULL )
00191     return CU_get_error();
00192   if( CU_add_test(pSuite, "TIMECONV_GetUTCTimeFromGPSTime()", test_TIMECONV_GetUTCTimeFromGPSTime) == NULL )
00193     return CU_get_error();
00194   if( CU_add_test(pSuite, "TIMECONV_DetermineUTCOffset()", test_TIMECONV_DetermineUTCOffset) == NULL )
00195     return CU_get_error();
00196   if( CU_add_test(pSuite, "TIMECONV_GetNumberOfDaysInMonth()", test_TIMECONV_GetNumberOfDaysInMonth) == NULL )
00197     return CU_get_error();
00198   if( CU_add_test(pSuite, "TIMECONV_IsALeapYear()", test_TIMECONV_IsALeapYear) == NULL )
00199     return CU_get_error();
00200   if( CU_add_test(pSuite, "TIMECONV_GetDayOfYear()", test_TIMECONV_GetDayOfYear) == NULL )
00201     return CU_get_error();
00202   if( CU_add_test(pSuite, "TIMECONV_GetGPSTimeFromYearAndDayOfYear()", test_TIMECONV_GetGPSTimeFromYearAndDayOfYear) == NULL )
00203     return CU_get_error();
00204   
00205   /* add a suite to the registry */
00206   pSuite = CU_add_suite("NOVATELOEM4", init_suite_GEODESY, clean_suite_GEODESY);
00207   if (NULL == pSuite)   
00208     return CU_get_error();
00209 
00210   /* add the tests to the suite */
00211   if( CU_add_test(pSuite, "NOVATELOEM4_FindNextMessageInFile()", test_NOVATELOEM4_FindNextMessageInFile) == NULL )
00212     return CU_get_error();
00213   if( CU_add_test(pSuite, "NOVATELOEM4_DecodeRANGEB()", test_NOVATELOEM4_DecodeRANGEB) == NULL )
00214     return CU_get_error();
00215   if( CU_add_test(pSuite, "NOVATELOEM4_DecodeRANGECMPB()", test_NOVATELOEM4_DecodeRANGECMPB) == NULL )
00216     return CU_get_error();
00217   if( CU_add_test(pSuite, "NOVATELOEM4_DecodeRAWEPHEMB()", test_NOVATELOEM4_DecodeRAWEPHEMB) == NULL )
00218     return CU_get_error();
00219 
00220 
00221 
00222   /* add a suite to the registry */
00223   pSuite = CU_add_suite("YUMA", init_suite_YUMA, clean_suite_YUMA);
00224   if (NULL == pSuite)   
00225     return CU_get_error();
00226 
00227   /* add the tests to the suite */
00228   if( CU_add_test(pSuite, "YUMA_ReadAlmanacDataFromFile()", test_YUMA_ReadAlmanacDataFromFile) == NULL )
00229     return CU_get_error();
00230   if( CU_add_test(pSuite, "YUMA_WriteAlmanacDataToFile()", test_YUMA_WriteAlmanacDataToFile) == NULL )
00231     return CU_get_error();
00232   if( CU_add_test(pSuite, "YUMA_WriteSingleAlmanacElementToBuffer()", test_YUMA_WriteSingleAlmanacElementToBuffer) == NULL )
00233     return CU_get_error();
00234 
00235   /* add a suite to the registry */
00236   pSuite = CU_add_suite("IONOSPHERE", init_suite_YUMA, clean_suite_YUMA);
00237   if (NULL == pSuite)   
00238     return CU_get_error();
00239 
00240   /* add the tests to the suite */
00241   if( CU_add_test(pSuite, "IONOSPHERE_GetL1KlobucharCorrection()", test_IONOSPHERE_GetL1KlobucharCorrection) == NULL )
00242     return CU_get_error();
00243 
00244   /* add a suite to the registry */
00245   pSuite = CU_add_suite("RINEX", init_suite_RINEX, clean_suite_RINEX);
00246   if (NULL == pSuite)   
00247     return CU_get_error();
00248 
00249   /* add the tests to the suite */
00250   if( CU_add_test(pSuite, "RINEX_GetHeader()", test_RINEX_GetHeader) == NULL )
00251     return CU_get_error();
00252   if( CU_add_test(pSuite, "RINEX_DecodeHeader_ObservationFile()", test_RINEX_DecodeHeader_ObservationFile) == NULL )
00253     return CU_get_error();
00254   if( CU_add_test(pSuite, "RINEX_GetNextObservationSet()", test_RINEX_GetNextObservationSet) == NULL )
00255     return CU_get_error();
00256   if( CU_add_test(pSuite, "RINEX_DecodeGPSNavigationFile()", test_RINEX_DecodeGPSNavigationFile) == NULL )
00257     return CU_get_error();
00258   if( CU_add_test(pSuite, "RINEX_GetKlobucharIonoParametersFromNavFile()", test_RINEX_GetKlobucharIonoParametersFromNavFile) == NULL )
00259     return CU_get_error();
00260   
00261   return CUE_SUCCESS;
00262 }
00263 
00264 
00265 
00266 void print_system_time(void)
00267 {
00268   BOOL result;
00269   unsigned short     utc_year;     // Universal Time Coordinated    [year]
00270   unsigned char      utc_month;    // Universal Time Coordinated    [1-12 months] 
00271   unsigned char      utc_day;      // Universal Time Coordinated    [1-31 days]
00272   unsigned char      utc_hour;     // Universal Time Coordinated    [hours]
00273   unsigned char      utc_minute;   // Universal Time Coordinated    [minutes]
00274   float              utc_seconds;  // Universal Time Coordinated    [s]
00275   unsigned char      utc_offset;   // Integer seconds that GPS is ahead of UTC time, always positive             [s], obtained from a look up table
00276   double             julian_date;  // Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
00277   unsigned short     gps_week;     // GPS week (0-1024+)            [week]
00278   double             gps_tow;      // GPS time of week (0-604800.0) [s]
00279   
00280   result = TIMECONV_GetSystemTime(
00281     &utc_year,   
00282     &utc_month,  
00283     &utc_day,    
00284     &utc_hour,   
00285     &utc_minute,  
00286     &utc_seconds, 
00287     &utc_offset,  
00288     &julian_date, 
00289     &gps_week,    
00290     &gps_tow          
00291     );
00292 
00293   if( result == 0 )
00294     return;
00295 
00296   printf( "\nDate YYYY-MM-DD, Time HH:MM:SS, of test (UTC).\n");
00297   printf( "     %4d-%02d-%02d,      %02d:%02d:%02.0f\n", 
00298     utc_year,
00299     utc_month,
00300     utc_day,
00301     utc_hour,
00302     utc_minute,
00303     utc_seconds );
00304   return;
00305 }