irplib_utils-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO IRPLIB package                                *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019  
00020 #ifdef HAVE_CONFIG_H
00021 #  include <config.h>
00022 #endif
00023 
00024 /*-----------------------------------------------------------------------------
00025                                 Includes
00026  -----------------------------------------------------------------------------*/
00027 
00028 #include <irplib_utils.h>
00029 #include <string.h>
00030 #include <float.h>
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Function prototypes
00034  -----------------------------------------------------------------------------*/
00035 
00036 static IRPLIB_UTIL_SET_ROW(my_table_set_row);
00037 static IRPLIB_UTIL_CHECK(my_table_check);
00038 
00039 /*----------------------------------------------------------------------------*/
00043 /*----------------------------------------------------------------------------*/
00044 
00045 /*----------------------------------------------------------------------------*/
00049 /*----------------------------------------------------------------------------*/
00050 static void
00051 test_irplib_isnaninf(void)
00052 {
00053     double infinity = DBL_MAX * DBL_MAX;
00054     double number[] = {17, 0};
00055 
00056     /* The computation  oo/oo  must result in NaN according to
00057        the IEEE 754 standard. However, some GCC 4.x versions erroneously 
00058        optimize this to 1. 
00059 
00060        Alternatively, a NaN could be produced using a IEEE 754 defined bit
00061        pattern. But that is likely to depend on the machine's word size.
00062        Therefore this test is disabled.
00063 
00064        double not_a_number = infinity / infinity;
00065     */
00066 
00067     cpl_test_zero(irplib_isnan(infinity) );
00068     /* cpl_test(  irplib_isnan(not_a_number) ); */
00069     cpl_test_zero(irplib_isnan(number[0]) );
00070     cpl_test_zero(irplib_isnan(number[1]) );
00071 
00072     cpl_test(  irplib_isinf(infinity) );
00073     /* cpl_test_zero(irplib_isinf(not_a_number) ); */
00074     cpl_test_zero(irplib_isinf(number[0]) );
00075     cpl_test_zero(irplib_isinf(number[1]) );
00076 
00077     return;
00078 }
00079 
00080 
00081 static cpl_boolean my_table_set_row(cpl_table * self,
00082                                     const char * line,
00083                                     int irow,
00084                                     const cpl_frame * rawframe,
00085                                     const cpl_parameterlist * parlist)
00086 {
00087 
00088     cpl_ensure_code(self     != NULL, CPL_ERROR_NULL_INPUT);
00089     cpl_ensure_code(line     != NULL, CPL_ERROR_NULL_INPUT);
00090     cpl_ensure_code(irow     >= 0,    CPL_ERROR_ILLEGAL_INPUT);
00091     cpl_ensure_code(rawframe != NULL, CPL_ERROR_NULL_INPUT);
00092     cpl_ensure_code(parlist  != NULL, CPL_ERROR_NULL_INPUT);
00093 
00094     return CPL_ERROR_NONE;
00095 
00096 }
00097 
00098 static cpl_error_code my_table_check(cpl_table * self,
00099                                      const cpl_frameset * useframes,
00100                                      const cpl_parameterlist * parlist)
00101 {
00102 
00103     cpl_ensure_code(self      != NULL, CPL_ERROR_NULL_INPUT);
00104     cpl_ensure_code(useframes != NULL, CPL_ERROR_NULL_INPUT);
00105     cpl_ensure_code(parlist   != NULL, CPL_ERROR_NULL_INPUT);
00106 
00107     return CPL_ERROR_NONE;
00108 
00109 }
00110 
00111 
00112 static void
00113 test_irplib_dfs_table_convert(void)
00114 {
00115 
00116     /* FIXME: Room for improvement... */
00117     cpl_error_code error
00118         = irplib_dfs_table_convert(NULL, NULL, NULL, 1024, '#',
00119                                    NULL, NULL, NULL, NULL, NULL, NULL,
00120                                    NULL, NULL, NULL, my_table_set_row,
00121                                    my_table_check);
00122 
00123     cpl_test_error(CPL_ERROR_NULL_INPUT);
00124     cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00125 
00126     error =
00127         irplib_table_read_from_frameset(NULL, NULL, 1024, '#', NULL,
00128                                         my_table_set_row);
00129 
00130     cpl_test_error(CPL_ERROR_NULL_INPUT);
00131     cpl_test_eq(error, CPL_ERROR_NULL_INPUT);
00132 }
00133 
00134 
00135 /*----------------------------------------------------------------------------*/
00139 /*----------------------------------------------------------------------------*/
00140 
00141 int main(void)
00142 {
00143     /* Initialize CPL + IRPLIB */
00144     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00145 
00146     test_irplib_isnaninf();
00147 
00148     test_irplib_dfs_table_convert();
00149 
00150     return cpl_test_end(0);
00151 }

Generated on Fri Apr 18 14:11:41 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1