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 <irplib_test.h> 00030 #include <string.h> 00031 #include <float.h> 00032 00033 /*----------------------------------------------------------------------------- 00034 Defines 00035 -----------------------------------------------------------------------------*/ 00036 00037 /*----------------------------------------------------------------------------*/ 00041 /*----------------------------------------------------------------------------*/ 00042 00043 /*----------------------------------------------------------------------------*/ 00047 /*----------------------------------------------------------------------------*/ 00048 00049 static void 00050 test_irplib_bpp_find(void) 00051 { 00052 irplib_test( irplib_bpp_find(0, (1<<8)-1) == CPL_BPP_8_UNSIGNED); 00053 00054 irplib_test( irplib_bpp_find(0, (1<<15)-1) == CPL_BPP_16_SIGNED); 00055 00056 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE > CPL_VERSION(3, 0, 90) 00057 irplib_test( irplib_bpp_find(0, (1<<16)-1) == CPL_BPP_16_UNSIGNED); 00058 #endif 00059 00060 irplib_test( irplib_bpp_find(-1, 1) == CPL_BPP_16_SIGNED); 00061 00062 irplib_test( irplib_bpp_find(-1, (1<<15)) == CPL_BPP_32_SIGNED); 00063 00064 return; 00065 } 00066 00067 /*----------------------------------------------------------------------------*/ 00071 /*----------------------------------------------------------------------------*/ 00072 static void 00073 test_irplib_sprintf(void) 00074 { 00075 const char * string = __FILE__; /* Some non-empty string */ 00076 const char * null; /* This string is supposed to always be NULL */ 00077 const char * null2; /* This string is supposed to always be NULL */ 00078 char * nonnull; /* String is supposed to never be NULL */ 00079 00080 /* Successfully create an illegal format string */ 00081 nonnull = irplib_sprintf("%s %s", string, "%"); 00082 00083 irplib_test(nonnull != NULL); 00084 irplib_test(strlen(nonnull) == strlen(string) + 2); 00085 irplib_test(!cpl_error_get_code()); 00086 00087 /* Verify that an error is produced using that illegal format */ 00088 null = irplib_sprintf(nonnull, "."); 00089 00090 irplib_test(cpl_error_get_code() == CPL_ERROR_ILLEGAL_INPUT); 00091 cpl_error_reset(); 00092 00093 irplib_test(null == NULL); 00094 00095 cpl_free(nonnull); 00096 00097 null2 = irplib_sprintf(null); 00098 00099 irplib_test(cpl_error_get_code() == CPL_ERROR_NULL_INPUT); 00100 cpl_error_reset(); 00101 00102 irplib_test(null2 == NULL); 00103 00104 return; 00105 } 00106 00107 /*----------------------------------------------------------------------------*/ 00111 /*----------------------------------------------------------------------------*/ 00112 static void 00113 test_irplib_isnaninf(void) 00114 { 00115 double infinity = DBL_MAX * DBL_MAX; 00116 double number[] = {17, 0}; 00117 00118 /* The computation oo/oo must result in NaN according to 00119 the IEEE 754 standard. However, some GCC 4.x versions erroneously 00120 optimize this to 1. 00121 00122 Alternatively, a NaN could be produced using a IEEE 754 defined bit 00123 pattern. But that is likely to depend on the machine's word size. 00124 Therefore this test is disabled. 00125 00126 double not_a_number = infinity / infinity; 00127 */ 00128 00129 irplib_test( !irplib_isnan(infinity) ); 00130 /* irplib_test( irplib_isnan(not_a_number) ); */ 00131 irplib_test( !irplib_isnan(number[0]) ); 00132 irplib_test( !irplib_isnan(number[1]) ); 00133 00134 irplib_test( irplib_isinf(infinity) ); 00135 /* irplib_test( !irplib_isinf(not_a_number) ); */ 00136 irplib_test( !irplib_isinf(number[0]) ); 00137 irplib_test( !irplib_isinf(number[1]) ); 00138 00139 return; 00140 } 00141 00142 /*----------------------------------------------------------------------------*/ 00146 /*----------------------------------------------------------------------------*/ 00147 00148 int main(void) 00149 { 00150 /* Initialize CPL + IRPLIB */ 00151 IRPLIB_TEST_INIT; 00152 00153 test_irplib_bpp_find(); 00154 00155 test_irplib_sprintf(); 00156 00157 test_irplib_isnaninf(); 00158 00159 IRPLIB_TEST_END; 00160 }
1.4.6