00001 #include "config.h" 00002 00003 #include <cassert> 00004 #include <string> 00005 00006 #include "asserts.h" 00007 #include "types.h" 00008 00009 void test_u8(void) 00010 { 00011 uint8 u8 = 0; 00012 uint8 u8_old = 0; 00013 unsigned int c = 0; 00014 00015 u8 = 1; 00016 for (c = 0; u8 != u8_old; c++) { 00017 u8_old = u8; 00018 u8 <<= 1; 00019 u8 |= 1; 00020 } 00021 00022 assert(c == 8); 00023 } 00024 00025 void test_u16(void) 00026 { 00027 uint16 u16 = 0; 00028 uint16 u16_old = 0; 00029 unsigned int c = 0; 00030 00031 u16 = 1; 00032 for (c = 0; u16 != u16_old; c++) { 00033 u16_old = u16; 00034 u16 <<= 1; 00035 u16 |= 1; 00036 } 00037 00038 assert(c == 16); 00039 } 00040 00041 void test_u32(void) 00042 { 00043 uint32 u32 = 0; 00044 uint32 u32_old = 0; 00045 unsigned int c = 0; 00046 00047 u32 = 1; 00048 for (c = 0; u32 != u32_old; c++) { 00049 u32_old = u32; 00050 u32 <<= 1; 00051 u32 |= 1; 00052 } 00053 00054 assert(c == 32); 00055 } 00056 00057 void test_u64(void) 00058 { 00059 uint64 u64 = 0; 00060 uint64 u64_old = 0; 00061 unsigned int c = 0; 00062 00063 u64 = 1; 00064 for (c = 0; u64 != u64_old; c++) { 00065 u64_old = u64; 00066 u64 <<= 1; 00067 u64 |= 1; 00068 } 00069 00070 assert(c == 64); 00071 } 00072 00073 void test_type(void) 00074 { 00075 char sc; 00076 unsigned char uc; 00077 short ss; 00078 unsigned short us; 00079 int si; 00080 unsigned int ui; 00081 long sl; 00082 unsigned long ul; 00083 long long sll; 00084 unsigned long long ull; 00085 float f; 00086 double d; 00087 bool b; 00088 00089 assert( is_signed_char(sc)); 00090 assert(!is_signed_char(uc)); 00091 assert(!is_signed_char(ss)); 00092 assert(!is_signed_char(us)); 00093 assert(!is_signed_char(si)); 00094 assert(!is_signed_char(ui)); 00095 assert(!is_signed_char(sl)); 00096 assert(!is_signed_char(ul)); 00097 assert(!is_signed_char(sll)); 00098 assert(!is_signed_char(ull)); 00099 assert(!is_signed_char(f)); 00100 assert(!is_signed_char(d)); 00101 assert(!is_signed_char(b)); 00102 00103 assert(!is_unsigned_char(sc)); 00104 assert( is_unsigned_char(uc)); 00105 assert(!is_unsigned_char(ss)); 00106 assert(!is_unsigned_char(us)); 00107 assert(!is_unsigned_char(si)); 00108 assert(!is_unsigned_char(ui)); 00109 assert(!is_unsigned_char(sl)); 00110 assert(!is_unsigned_char(ul)); 00111 assert(!is_unsigned_char(sll)); 00112 assert(!is_unsigned_char(ull)); 00113 assert(!is_unsigned_char(f)); 00114 assert(!is_unsigned_char(d)); 00115 assert(!is_unsigned_char(b)); 00116 00117 assert(!is_signed_short(sc)); 00118 assert(!is_signed_short(uc)); 00119 assert( is_signed_short(ss)); 00120 assert(!is_signed_short(us)); 00121 assert(!is_signed_short(si)); 00122 assert(!is_signed_short(ui)); 00123 assert(!is_signed_short(sl)); 00124 assert(!is_signed_short(ul)); 00125 assert(!is_signed_short(sll)); 00126 assert(!is_signed_short(ull)); 00127 assert(!is_signed_short(f)); 00128 assert(!is_signed_short(d)); 00129 assert(!is_signed_short(b)); 00130 00131 assert(!is_unsigned_short(sc)); 00132 assert(!is_unsigned_short(uc)); 00133 assert(!is_unsigned_short(ss)); 00134 assert( is_unsigned_short(us)); 00135 assert(!is_unsigned_short(si)); 00136 assert(!is_unsigned_short(ui)); 00137 assert(!is_unsigned_short(sl)); 00138 assert(!is_unsigned_short(ul)); 00139 assert(!is_unsigned_short(sll)); 00140 assert(!is_unsigned_short(ull)); 00141 assert(!is_unsigned_short(f)); 00142 assert(!is_unsigned_short(d)); 00143 assert(!is_unsigned_short(b)); 00144 00145 assert(!is_signed_int(sc)); 00146 assert(!is_signed_int(uc)); 00147 assert(!is_signed_int(ss)); 00148 assert(!is_signed_int(us)); 00149 assert( is_signed_int(si)); 00150 assert(!is_signed_int(ui)); 00151 assert(!is_signed_int(sl)); 00152 assert(!is_signed_int(ul)); 00153 assert(!is_signed_int(sll)); 00154 assert(!is_signed_int(ull)); 00155 assert(!is_signed_int(f)); 00156 assert(!is_signed_int(d)); 00157 assert(!is_signed_int(b)); 00158 00159 assert(!is_unsigned_int(sc)); 00160 assert(!is_unsigned_int(uc)); 00161 assert(!is_unsigned_int(ss)); 00162 assert(!is_unsigned_int(us)); 00163 assert(!is_unsigned_int(si)); 00164 assert( is_unsigned_int(ui)); 00165 assert(!is_unsigned_int(sl)); 00166 assert(!is_unsigned_int(ul)); 00167 assert(!is_unsigned_int(sll)); 00168 assert(!is_unsigned_int(ull)); 00169 assert(!is_unsigned_int(f)); 00170 assert(!is_unsigned_int(d)); 00171 assert(!is_unsigned_int(b)); 00172 00173 assert(!is_signed_long(sc)); 00174 assert(!is_signed_long(uc)); 00175 assert(!is_signed_long(ss)); 00176 assert(!is_signed_long(us)); 00177 assert(!is_signed_long(si)); 00178 assert(!is_signed_long(ui)); 00179 assert( is_signed_long(sl)); 00180 assert(!is_signed_long(ul)); 00181 assert(!is_signed_long(sll)); 00182 assert(!is_signed_long(ull)); 00183 assert(!is_signed_long(f)); 00184 assert(!is_signed_long(d)); 00185 assert(!is_signed_long(b)); 00186 00187 assert(!is_unsigned_long(sc)); 00188 assert(!is_unsigned_long(uc)); 00189 assert(!is_unsigned_long(ss)); 00190 assert(!is_unsigned_long(us)); 00191 assert(!is_unsigned_long(si)); 00192 assert(!is_unsigned_long(ui)); 00193 assert(!is_unsigned_long(sl)); 00194 assert( is_unsigned_long(ul)); 00195 assert(!is_unsigned_long(sll)); 00196 assert(!is_unsigned_long(ull)); 00197 assert(!is_unsigned_long(f)); 00198 assert(!is_unsigned_long(d)); 00199 assert(!is_unsigned_long(b)); 00200 00201 assert(!is_signed_long_long(sc)); 00202 assert(!is_signed_long_long(uc)); 00203 assert(!is_signed_long_long(ss)); 00204 assert(!is_signed_long_long(us)); 00205 assert(!is_signed_long_long(si)); 00206 assert(!is_signed_long_long(ui)); 00207 assert(!is_signed_long_long(sl)); 00208 assert(!is_signed_long_long(ul)); 00209 assert( is_signed_long_long(sll)); 00210 assert(!is_signed_long_long(ull)); 00211 assert(!is_signed_long_long(f)); 00212 assert(!is_signed_long_long(d)); 00213 assert(!is_signed_long_long(b)); 00214 00215 assert(!is_unsigned_long_long(sc)); 00216 assert(!is_unsigned_long_long(uc)); 00217 assert(!is_unsigned_long_long(ss)); 00218 assert(!is_unsigned_long_long(us)); 00219 assert(!is_unsigned_long_long(si)); 00220 assert(!is_unsigned_long_long(ui)); 00221 assert(!is_unsigned_long_long(sl)); 00222 assert(!is_unsigned_long_long(ul)); 00223 assert(!is_unsigned_long_long(sll)); 00224 assert( is_unsigned_long_long(ull)); 00225 assert(!is_unsigned_long_long(f)); 00226 assert(!is_unsigned_long_long(d)); 00227 assert(!is_unsigned_long_long(b)); 00228 00229 assert(!is_float(sc)); 00230 assert(!is_float(uc)); 00231 assert(!is_float(ss)); 00232 assert(!is_float(us)); 00233 assert(!is_float(si)); 00234 assert(!is_float(ui)); 00235 assert(!is_float(sl)); 00236 assert(!is_float(ul)); 00237 assert(!is_float(sll)); 00238 assert(!is_float(ull)); 00239 assert( is_float(f)); 00240 assert(!is_float(d)); 00241 assert(!is_float(b)); 00242 00243 assert(!is_double(sc)); 00244 assert(!is_double(uc)); 00245 assert(!is_double(ss)); 00246 assert(!is_double(us)); 00247 assert(!is_double(si)); 00248 assert(!is_double(ui)); 00249 assert(!is_double(sl)); 00250 assert(!is_double(ul)); 00251 assert(!is_double(sll)); 00252 assert(!is_double(ull)); 00253 assert(!is_double(f)); 00254 assert( is_double(d)); 00255 assert(!is_double(b)); 00256 00257 assert(!is_bool(sc)); 00258 assert(!is_bool(uc)); 00259 assert(!is_bool(ss)); 00260 assert(!is_bool(us)); 00261 assert(!is_bool(si)); 00262 assert(!is_bool(ui)); 00263 assert(!is_bool(sl)); 00264 assert(!is_bool(ul)); 00265 assert(!is_bool(sll)); 00266 assert(!is_bool(ull)); 00267 assert(!is_bool(f)); 00268 assert(!is_bool(d)); 00269 assert( is_bool(b)); 00270 00271 assert(static_cast<std::string>(type_name(sc)) == "char"); 00272 assert(static_cast<std::string>(type_name(uc)) == "unsigned char"); 00273 assert(static_cast<std::string>(type_name(ss)) == "short"); 00274 assert(static_cast<std::string>(type_name(us)) == "unsigned short"); 00275 assert(static_cast<std::string>(type_name(si)) == "int"); 00276 assert(static_cast<std::string>(type_name(ui)) == "unsigned int"); 00277 assert(static_cast<std::string>(type_name(sl)) == "long"); 00278 assert(static_cast<std::string>(type_name(ul)) == "unsigned long"); 00279 assert(static_cast<std::string>(type_name(sll)) == "long long"); 00280 assert(static_cast<std::string>(type_name(ull)) == "unsigned long long"); 00281 assert(static_cast<std::string>(type_name(f)) == "float"); 00282 assert(static_cast<std::string>(type_name(d)) == "double"); 00283 assert(static_cast<std::string>(type_name(b)) == "bool"); 00284 } 00285 00286 int main(int argc, char const * argv[]) 00287 { 00288 test_u8(); 00289 test_u16(); 00290 test_u32(); 00291 test_u64(); 00292 test_type(); 00293 return(0); 00294 }