Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * VARIANT test program |
| 3 | * |
| 4 | * Copyright 1998 Jean-Claude Cote |
| 5 | * |
| 6 | * The purpose of this program is validate the implementation |
| 7 | * of the APIs related to VARIANTs. The validation is done |
| 8 | * by comparing the results given by the Windows implementation |
| 9 | * versus the Wine implementation. |
| 10 | * |
| 11 | * This program tests the creation/coercion/destruction of VARIANTs. |
| 12 | * |
| 13 | * The program does not currently test any API that takes |
| 14 | * arguments of type: IDispatch, IUnknown, DECIMAL, CURRENCY. |
| 15 | * |
| 16 | * Since the purpose of this program is to compare the results |
| 17 | * from Windows and Wine it is written so that with a simple |
| 18 | * define it can be compiled either in Windows or Linux. |
| 19 | * |
| 20 | * |
| 21 | * NOTES |
| 22 | * - The Variant structure in Windows has a non-named union. This means |
| 23 | * the member of the union are accessible simply by doing pVariant->pfltVal. |
| 24 | * With gcc it is not possible to have non-named union so it has been named |
| 25 | * 'u'. So it's members are accessible using this name like so |
| 26 | * pVariant->u.pfltVal. So if this program is compiled in Windows |
| 27 | * the references to 'u' will need to be take out of this file. |
| 28 | * |
| 29 | * - Also the printf is a little different so the format specifiers may |
| 30 | * need to be tweaked if this file is compile in Windows. |
| 31 | * Printf is also different in that it continues printing numbers |
| 32 | * even after there is no more significative digits left to print. These |
| 33 | * number are garbage and in windows they are set to zero but not |
| 34 | * on Linux. |
| 35 | * |
| 36 | * - The VarDateFromStr is not implemented yet. |
| 37 | * |
| 38 | * - The date and floating point format may not be the exact same format has the one in |
| 39 | * windows depending on what the Internatinal setting are in windows. |
| 40 | * |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | |
| 45 | #include <stdio.h> |
| 46 | #include <malloc.h> |
| 47 | #include <windows.h> |
| 48 | #include <winerror.h> |
| 49 | #include <winnt.h> |
| 50 | |
| 51 | #include <oleauto.h> |
| 52 | |
| 53 | #include <math.h> |
| 54 | #include <float.h> |
| 55 | #include <time.h> |
| 56 | |
Jim Aston | 2e1cafa | 1999-03-14 16:35:05 +0000 | [diff] [blame] | 57 | #include <windef.h> |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 58 | |
Pavel Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 59 | #ifdef __unix__ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 60 | #include <debugstr.h> |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 61 | extern LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str ); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | |
| 65 | static const int MAX_BUFFER = 1024; |
| 66 | |
| 67 | |
Pavel Roskin | 734247b | 1999-04-03 13:52:04 +0000 | [diff] [blame] | 68 | #ifndef __unix__ |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 69 | char* WtoA( OLECHAR* p ) |
| 70 | { |
| 71 | int i = 0; |
| 72 | char* pc = (char *)malloc( MAX_BUFFER*sizeof(char) ); |
| 73 | pc[0] = '\"'; |
| 74 | pc++; |
| 75 | i = wcstombs( pc, p, MAX_BUFFER ); |
| 76 | if( i < MAX_BUFFER-1 ) |
| 77 | { |
| 78 | pc[i] = '\"'; |
| 79 | pc[i+1] = '\0'; |
| 80 | } |
| 81 | pc--; |
| 82 | return pc; |
| 83 | } |
| 84 | |
| 85 | OLECHAR* AtoW( char* p ) |
| 86 | { |
| 87 | int i = 0; |
| 88 | OLECHAR* pwc = (OLECHAR *)malloc( MAX_BUFFER*sizeof(OLECHAR) ); |
| 89 | i = mbstowcs( pwc, p, MAX_BUFFER ); |
| 90 | return pwc; |
| 91 | } |
| 92 | #else |
| 93 | char* WtoA( OLECHAR* p ) |
| 94 | { |
| 95 | return debugstr_wn( p, MAX_BUFFER ); |
| 96 | } |
| 97 | OLECHAR* AtoW( char* p ) |
| 98 | { |
| 99 | return HEAP_strdupAtoW( GetProcessHeap(), 0, p ); |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | |
| 104 | int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show) |
| 105 | { |
| 106 | VARIANTARG va; |
| 107 | VARIANTARG vb; |
| 108 | VARIANTARG vc; |
| 109 | VARIANTARG vd; |
| 110 | VARIANTARG ve; |
| 111 | |
| 112 | int theInt = 0; |
| 113 | int* pInt = &theInt; |
| 114 | VARIANT_BOOL b = 0; |
| 115 | VARIANT_BOOL* pBool = &b; |
| 116 | unsigned short uShort = 0; |
| 117 | unsigned short* pUShort = &uShort; |
| 118 | unsigned long uLong = 0; |
| 119 | unsigned long* pULong = &uLong; |
| 120 | CHAR theChar; |
| 121 | CHAR* pChar = &theChar; |
| 122 | BYTE byte; |
| 123 | BYTE* pByte = &byte; |
| 124 | short s = 0; |
| 125 | short* pShort = &s; |
| 126 | long Long = 0; |
| 127 | long* pLong = &Long; |
| 128 | float f = 0; |
| 129 | float* pFloat = &f; |
| 130 | double d = 0; |
| 131 | double* pDouble = &d; |
| 132 | |
| 133 | unsigned short i = 0; |
| 134 | HRESULT res = 0; |
| 135 | BSTR bstr = NULL; |
| 136 | int olePtrIndex = 0; |
| 137 | int nOlePtrs = 120; |
| 138 | OLECHAR* pOleChar[120]; |
| 139 | |
| 140 | pOleChar[0] = AtoW( "-2" ); |
| 141 | pOleChar[1] = AtoW( "-1" ); |
| 142 | pOleChar[2] = AtoW( "-0.51" ); |
| 143 | pOleChar[3] = AtoW( "-0.5" ); |
| 144 | pOleChar[4] = AtoW( "-0.49" ); |
| 145 | pOleChar[5] = AtoW( "-0.0" ); |
| 146 | pOleChar[6] = AtoW( "0.0" ); |
| 147 | pOleChar[7] = AtoW( "0.49" ); |
| 148 | pOleChar[8] = AtoW( "0.5" ); |
| 149 | pOleChar[9] = AtoW( "0.51" ); |
| 150 | pOleChar[10] = AtoW( "1" ); |
| 151 | pOleChar[11] = AtoW( "127" ); |
| 152 | pOleChar[12] = AtoW( "128" ); |
| 153 | pOleChar[13] = AtoW( "129" ); |
| 154 | pOleChar[14] = AtoW( "255" ); |
| 155 | pOleChar[15] = AtoW( "256" ); |
| 156 | pOleChar[16] = AtoW( "257" ); |
| 157 | pOleChar[17] = AtoW( "32767" ); |
| 158 | pOleChar[18] = AtoW( "32768" ); |
| 159 | pOleChar[19] = AtoW( "-32768" ); |
| 160 | pOleChar[20] = AtoW( "-32769" ); |
| 161 | pOleChar[21] = AtoW( "16777216" ); |
| 162 | pOleChar[22] = AtoW( "16777217" ); |
| 163 | pOleChar[23] = AtoW( "-16777216" ); |
| 164 | pOleChar[24] = AtoW( "16777217" ); |
| 165 | pOleChar[25] = AtoW( "2147483647" ); |
| 166 | pOleChar[26] = AtoW( "2147483648" ); |
| 167 | pOleChar[27] = AtoW( "-2147483647" ); |
| 168 | pOleChar[28] = AtoW( "-2147483648" ); |
| 169 | |
| 170 | pOleChar[29] = AtoW( "" ); |
| 171 | pOleChar[30] = AtoW( " " ); |
| 172 | pOleChar[31] = AtoW( "1F" ); |
| 173 | pOleChar[32] = AtoW( "1G" ); |
| 174 | pOleChar[33] = AtoW( " 1 " ); |
| 175 | pOleChar[34] = AtoW( " 1 2 " ); |
| 176 | pOleChar[35] = AtoW( "1,2,3" ); |
| 177 | pOleChar[36] = AtoW( "1 2 3" ); |
| 178 | pOleChar[37] = AtoW( "1,2, 3" ); |
| 179 | pOleChar[38] = AtoW( "1;2;3" ); |
| 180 | pOleChar[39] = AtoW( "1.2.3" ); |
| 181 | |
| 182 | pOleChar[40] = AtoW( "0." ); |
| 183 | pOleChar[41] = AtoW( ".0" ); |
| 184 | pOleChar[42] = AtoW( "0.1E12" ); |
| 185 | pOleChar[43] = AtoW( "2.4,E1" ); |
| 186 | pOleChar[44] = AtoW( " +3.2,E1" ); |
| 187 | pOleChar[45] = AtoW( "4E2.5" ); |
| 188 | pOleChar[46] = AtoW( " 2E+2" ); |
| 189 | pOleChar[47] = AtoW( "1 E+2" ); |
| 190 | pOleChar[48] = AtoW( "." ); |
| 191 | pOleChar[49] = AtoW( ".E2" ); |
| 192 | pOleChar[50] = AtoW( "1000000000000000000000000000000000000000000000000000000000000000" ); |
| 193 | pOleChar[51] = AtoW( "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ); |
| 194 | pOleChar[52] = AtoW( "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ); |
| 195 | pOleChar[53] = AtoW( "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ); |
| 196 | pOleChar[54] = AtoW( "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ); |
| 197 | pOleChar[55] = AtoW( "65535" ); |
| 198 | pOleChar[56] = AtoW( "65535.5" ); |
| 199 | pOleChar[57] = AtoW( "65536" ); |
| 200 | pOleChar[58] = AtoW( "4294967295" ); |
| 201 | pOleChar[59] = AtoW( "4294967296" ); |
| 202 | |
| 203 | pOleChar[60] = AtoW( "1 January 99" ); |
| 204 | pOleChar[61] = AtoW( "December 31, 2078" ); |
| 205 | pOleChar[62] = AtoW( "January 1, 1900" ); |
| 206 | pOleChar[63] = AtoW( "January 2 1900" ); |
| 207 | pOleChar[64] = AtoW( "11.11.1999" ); |
| 208 | pOleChar[65] = AtoW( "11/11/1999" ); |
| 209 | pOleChar[66] = AtoW( " 11 / 11 / 1999" ); |
| 210 | pOleChar[67] = AtoW( "11/11/1999:11:11:1134" ); |
| 211 | pOleChar[68] = AtoW( "11/11/1999 11:11:11:1" ); |
| 212 | pOleChar[69] = AtoW( "\t1999/\t11/21 11 :11:11am" ); |
| 213 | |
| 214 | pOleChar[70] = AtoW( "11/11/1999 11:11:11Am" ); |
| 215 | pOleChar[71] = AtoW( "11/11/1999 11:11:11PM" ); |
| 216 | pOleChar[72] = AtoW( "11/11/199911:11:11PM" ); |
| 217 | pOleChar[73] = AtoW( "11/11/1999 0:0:11am" ); |
| 218 | pOleChar[74] = AtoW( "11/11/1999 11,11:11am" ); |
| 219 | pOleChar[75] = AtoW( "11/11/1999 11:11:11am" ); |
| 220 | pOleChar[76] = AtoW( "11/11/1999 11/11:11am" ); |
| 221 | pOleChar[77] = AtoW( "11/11/1999 11:11AM" ); |
| 222 | pOleChar[78] = AtoW( "11/11/1999 1AM" ); |
| 223 | pOleChar[79] = AtoW( "11/11/1999 0AM" ); |
| 224 | |
| 225 | pOleChar[80] = AtoW( "11/11/1999 11:11:11" ); |
| 226 | pOleChar[81] = AtoW( "11/13/1999 0AM" ); |
| 227 | pOleChar[82] = AtoW( "13/13/1999 0AM" ); |
| 228 | pOleChar[83] = AtoW( "13/11/1999 0AM" ); |
| 229 | pOleChar[84] = AtoW( "11/33/1999 0AM" ); |
| 230 | pOleChar[85] = AtoW( "11/11/1999 AM" ); |
| 231 | pOleChar[86] = AtoW( "1/1/0 0AM" ); |
| 232 | pOleChar[87] = AtoW( "1/1/-1 0AM" ); |
| 233 | pOleChar[88] = AtoW( "1999 January 3 9AM" ); |
| 234 | pOleChar[89] = AtoW( "1 January 1999 11AM" ); |
| 235 | |
| 236 | pOleChar[90] = AtoW( "4AM 11/11/1999" ); |
| 237 | pOleChar[91] = AtoW( "4:22 11/11/1999 AM" ); |
| 238 | pOleChar[92] = AtoW( " 1 1 /11/1999" ); |
| 239 | pOleChar[93] = AtoW( "11-11/1999 11:11:11.12AM" ); |
| 240 | pOleChar[94] = AtoW( "1999 January 3, 9AM" ); |
| 241 | pOleChar[95] = AtoW( "December, 31, 2078" ); |
| 242 | pOleChar[96] = AtoW( "December, 31, 2078," ); |
| 243 | pOleChar[97] = AtoW( "December, 31 2078" ); |
| 244 | pOleChar[98] = AtoW( "11/99" ); |
| 245 | pOleChar[99] = AtoW( "11-1999" ); |
| 246 | |
| 247 | pOleChar[100] = AtoW( "true" ); |
| 248 | pOleChar[101] = AtoW( "True" ); |
| 249 | pOleChar[102] = AtoW( "TRue" ); |
| 250 | pOleChar[103] = AtoW( "TRUE" ); |
| 251 | pOleChar[104] = AtoW( " TRUE" ); |
| 252 | pOleChar[105] = AtoW( "FALSE " ); |
| 253 | pOleChar[106] = AtoW( "False" ); |
| 254 | pOleChar[107] = AtoW( "JustSomeText" ); |
| 255 | pOleChar[108] = AtoW( "Just Some Text" ); |
| 256 | pOleChar[109] = AtoW( "" ); |
| 257 | |
| 258 | pOleChar[110] = AtoW( "1.5" ); |
| 259 | pOleChar[111] = AtoW( "2.5" ); |
| 260 | pOleChar[112] = AtoW( "3.5" ); |
| 261 | pOleChar[113] = AtoW( "4.5" ); |
| 262 | pOleChar[114] = AtoW( "" ); |
| 263 | pOleChar[115] = AtoW( "" ); |
| 264 | pOleChar[116] = AtoW( "" ); |
| 265 | pOleChar[117] = AtoW( "" ); |
| 266 | pOleChar[118] = AtoW( "" ); |
| 267 | pOleChar[119] = AtoW( "" ); |
| 268 | |
| 269 | |
| 270 | /* Start testing the Low-Level API ( the coercions ) |
| 271 | */ |
| 272 | |
| 273 | |
| 274 | /* unsigned char from... |
| 275 | */ |
| 276 | printf( "\n\n======== Testing VarUI1FromXXX ========\n"); |
| 277 | |
| 278 | /* res = VarUI1FromI2( 0, NULL ); |
| 279 | */ |
| 280 | printf( "VarUI1FromI2: passing in NULL as return val makes it crash, %X\n", (unsigned int) res ); |
| 281 | |
| 282 | res = VarUI1FromStr( NULL, 0, 0, pByte ); |
| 283 | printf( "VarUI1FromStr: passing in NULL as param: %X\n", (unsigned int) res ); |
| 284 | |
| 285 | res = VarUI1FromI2( 0, pByte ); |
| 286 | printf( "VarUI1FromI2: 0, %X, %X\n", *pByte, (unsigned int) res ); |
| 287 | res = VarUI1FromI2( 69, pByte ); |
| 288 | printf( "VarUI1FromI2: 69, %X, %X\n", *pByte, (unsigned int) res ); |
| 289 | res = VarUI1FromI2( 70, pByte ); |
| 290 | printf( "VarUI1FromI2: 70, %X, %X\n", *pByte, (unsigned int) res ); |
| 291 | res = VarUI1FromI2( 128, pByte ); |
| 292 | printf( "VarUI1FromI2: 128, %X, %X\n", *pByte, (unsigned int) res ); |
| 293 | res = VarUI1FromI2( 255, pByte ); |
| 294 | printf( "VarUI1FromI2: 255, %X, %X\n", *pByte, (unsigned int) res ); |
| 295 | res = VarUI1FromI2( 256, pByte ); |
| 296 | printf( "VarUI1FromI2: 256, %X, %X\n", *pByte, (unsigned int) res ); |
| 297 | res = VarUI1FromI2( 257, pByte ); |
| 298 | printf( "VarUI1FromI2: 257, %X, %X\n", *pByte, (unsigned int) res ); |
| 299 | |
| 300 | res = VarUI1FromR8( 0.0, pByte ); |
| 301 | printf( "VarUI1FromR8: 0.0, %X, %X\n", *pByte, (unsigned int) res ); |
| 302 | res = VarUI1FromR8( 69.33, pByte ); |
| 303 | printf( "VarUI1FromR8: 69.33, %X, %X\n", *pByte, (unsigned int) res ); |
| 304 | res = VarUI1FromR8( 69.66, pByte ); |
| 305 | printf( "VarUI1FromR8: 69.66, %X, %X\n", *pByte, (unsigned int) res ); |
| 306 | res = VarUI1FromR8( -69.33, pByte ); |
| 307 | printf( "VarUI1FromR8: -69.33, %X, %X\n", *pByte, (unsigned int) res ); |
| 308 | res = VarUI1FromR8( -69.66, pByte ); |
| 309 | printf( "VarUI1FromR8: -69.66, %X, %X\n", *pByte, (unsigned int) res ); |
| 310 | |
| 311 | res = VarUI1FromR8( -0.5, pByte ); |
| 312 | printf( "VarUI1FromR8: -0.5, %X, %X\n", *pByte, (unsigned int) res ); |
| 313 | res = VarUI1FromR8( -0.51, pByte ); |
| 314 | printf( "VarUI1FromR8: -0.51, %X, %X\n", *pByte, (unsigned int) res ); |
| 315 | res = VarUI1FromR8( -0.49, pByte ); |
| 316 | printf( "VarUI1FromR8: -0.49, %X, %X\n", *pByte, (unsigned int) res ); |
| 317 | |
| 318 | res = VarUI1FromR8( 0.5, pByte ); |
| 319 | printf( "VarUI1FromR8: 0.5, %X, %X\n", *pByte, (unsigned int) res ); |
| 320 | res = VarUI1FromR8( 0.51, pByte ); |
| 321 | printf( "VarUI1FromR8: 0.51, %X, %X\n", *pByte, (unsigned int) res ); |
| 322 | res = VarUI1FromR8( 0.49, pByte ); |
| 323 | printf( "VarUI1FromR8: 0.49, %X, %X\n", *pByte, (unsigned int) res ); |
| 324 | |
| 325 | res = VarUI1FromDate( 0.0, pByte ); |
| 326 | printf( "VarUI1FromDate: 0.0, %X, %X\n", *pByte, (unsigned int) res ); |
| 327 | res = VarUI1FromDate( 69.33, pByte ); |
| 328 | printf( "VarUI1FromDate: 69.33, %X, %X\n", *pByte, (unsigned int) res ); |
| 329 | res = VarUI1FromDate( 69.66, pByte ); |
| 330 | printf( "VarUI1FromDate: 69.66, %X, %X\n", *pByte, (unsigned int) res ); |
| 331 | res = VarUI1FromDate( -69.33, pByte ); |
| 332 | printf( "VarUI1FromDate: -69.33, %X, %X\n", *pByte, (unsigned int) res ); |
| 333 | res = VarUI1FromDate( -69.66, pByte ); |
| 334 | printf( "VarUI1FromDate: -69.66, %X, %X\n", *pByte, (unsigned int) res ); |
| 335 | |
| 336 | res = VarUI1FromBool( VARIANT_TRUE, pByte ); |
| 337 | printf( "VarUI1FromBool: VARIANT_TRUE, %X, %X\n", *pByte, (unsigned int) res ); |
| 338 | res = VarUI1FromBool( VARIANT_FALSE, pByte ); |
| 339 | printf( "VarUI1FromBool: VARIANT_FALSE, %X, %X\n", *pByte, (unsigned int) res ); |
| 340 | |
| 341 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 342 | { |
| 343 | res = VarUI1FromStr( pOleChar[olePtrIndex], 0, 0, pByte ); |
| 344 | printf( "VarUI1FromStr: %s, %X, %X\n", WtoA(pOleChar[olePtrIndex]), *pByte, (unsigned int) res ); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | /* unsigned short from ... |
| 349 | */ |
| 350 | printf( "\n\n======== Testing VarUI2FromXXX ========\n"); |
| 351 | |
| 352 | res = VarUI2FromI2( -1, &i ); |
| 353 | printf( "VarUI2FromI2: -1, %d, %X\n", i, (unsigned int) res ); |
| 354 | |
| 355 | /* res = VarUI2FromI2( 0, NULL ); |
| 356 | */ |
| 357 | printf( "VarUI2FromI2: passing in NULL as return val makes it crash, %X\n", (unsigned int) res ); |
| 358 | |
| 359 | res = VarUI2FromStr( NULL, 0, 0, pUShort ); |
| 360 | printf( "VarUI2FromStr: passing in NULL as param: %X\n", (unsigned int) res ); |
| 361 | |
| 362 | res = VarUI2FromI2( 0, pUShort ); |
| 363 | printf( "VarUI2FromI2: 0, %u, %X\n", *pUShort, (unsigned int) res ); |
| 364 | res = VarUI2FromI2( 69, pUShort ); |
| 365 | printf( "VarUI2FromI2: 69, %u, %X\n", *pUShort, (unsigned int) res ); |
| 366 | res = VarUI2FromI2( 70, pUShort ); |
| 367 | printf( "VarUI2FromI2: 70, %u, %X\n", *pUShort, (unsigned int) res ); |
| 368 | res = VarUI2FromI2( 128, pUShort ); |
| 369 | printf( "VarUI2FromI2: 128, %u, %X\n", *pUShort, (unsigned int) res ); |
| 370 | res = VarUI2FromI4( 65535, pUShort ); |
| 371 | printf( "VarUI2FromI4: 65535, %u, %X\n", *pUShort, (unsigned int) res ); |
| 372 | res = VarUI2FromI4( 65536, pUShort ); |
| 373 | printf( "VarUI2FromI4: 65536, %u, %X\n", *pUShort, (unsigned int) res ); |
| 374 | res = VarUI2FromI4( 65537, pUShort ); |
| 375 | printf( "VarUI2FromI4: 65537, %u, %X\n", *pUShort, (unsigned int) res ); |
| 376 | |
| 377 | res = VarUI2FromR8( 0.0, pUShort ); |
| 378 | printf( "VarUI2FromR8: 0.0, %u, %X\n", *pUShort, (unsigned int) res ); |
| 379 | res = VarUI2FromR8( 69.33, pUShort ); |
| 380 | printf( "VarUI2FromR8: 69.33, %u, %X\n", *pUShort, (unsigned int) res ); |
| 381 | res = VarUI2FromR8( 69.66, pUShort ); |
| 382 | printf( "VarUI2FromR8: 69.66, %u, %X\n", *pUShort, (unsigned int) res ); |
| 383 | res = VarUI2FromR8( -69.33, pUShort ); |
| 384 | printf( "VarUI2FromR8: -69.33, %u, %X\n", *pUShort, (unsigned int) res ); |
| 385 | res = VarUI2FromR8( -69.66, pUShort ); |
| 386 | printf( "VarUI2FromR8: -69.66, %u, %X\n", *pUShort, (unsigned int) res ); |
| 387 | |
| 388 | res = VarUI2FromR8( -0.5, pUShort ); |
| 389 | printf( "VarUI2FromR8: -0.5, %u, %X\n", *pUShort, (unsigned int) res ); |
| 390 | res = VarUI2FromR8( -0.51, pUShort ); |
| 391 | printf( "VarUI2FromR8: -0.51, %u, %X\n", *pUShort, (unsigned int) res ); |
| 392 | res = VarUI2FromR8( -0.49, pUShort ); |
| 393 | printf( "VarUI2FromR8: -0.49, %u, %X\n", *pUShort, (unsigned int) res ); |
| 394 | |
| 395 | res = VarUI2FromR8( 0.5, pUShort ); |
| 396 | printf( "VarUI2FromR8: 0.5, %u, %X\n", *pUShort, (unsigned int) res ); |
| 397 | res = VarUI2FromR8( 0.51, pUShort ); |
| 398 | printf( "VarUI2FromR8: 0.51, %u, %X\n", *pUShort, (unsigned int) res ); |
| 399 | res = VarUI2FromR8( 0.49, pUShort ); |
| 400 | printf( "VarUI2FromR8: 0.49, %u, %X\n", *pUShort, (unsigned int) res ); |
| 401 | |
| 402 | res = VarUI2FromDate( 0.0, pUShort ); |
| 403 | printf( "VarUI2FromDate: 0.0, %u, %X\n", *pUShort, (unsigned int) res ); |
| 404 | res = VarUI2FromDate( 69.33, pUShort ); |
| 405 | printf( "VarUI2FromDate: 69.33, %u, %X\n", *pUShort, (unsigned int) res ); |
| 406 | res = VarUI2FromDate( 69.66, pUShort ); |
| 407 | printf( "VarUI2FromDate: 69.66, %u, %X\n", *pUShort, (unsigned int) res ); |
| 408 | res = VarUI2FromDate( -69.33, pUShort ); |
| 409 | printf( "VarUI2FromDate: -69.33, %u, %X\n", *pUShort, (unsigned int) res ); |
| 410 | res = VarUI2FromDate( -69.66, pUShort ); |
| 411 | printf( "VarUI2FromDate: -69.66, %u, %X\n", *pUShort, (unsigned int) res ); |
| 412 | |
| 413 | res = VarUI2FromBool( VARIANT_TRUE, pUShort ); |
| 414 | printf( "VarUI2FromBool: VARIANT_TRUE, %u, %X\n", *pUShort, (unsigned int) res ); |
| 415 | res = VarUI2FromBool( VARIANT_FALSE, pUShort ); |
| 416 | printf( "VarUI2FromBool: VARIANT_FALSE, %u, %X\n", *pUShort, (unsigned int) res ); |
| 417 | |
| 418 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 419 | { |
| 420 | res = VarUI2FromStr( pOleChar[olePtrIndex], 0, 0, pUShort ); |
| 421 | printf( "VarUI2FromStr: %s, %u, %X\n", WtoA(pOleChar[olePtrIndex]), (int)*pUShort, (unsigned int) res ); |
| 422 | } |
| 423 | |
| 424 | /* unsigned long from ... |
| 425 | */ |
| 426 | printf( "\n\n======== Testing VarUI4FromXXX ========\n"); |
| 427 | |
| 428 | /*res = VarUI4FromI2( 0, NULL ); |
| 429 | */ |
| 430 | printf( "VarUI4FromI2: passing in NULL as return val makes it crash, %X\n", (unsigned int) res ); |
| 431 | |
| 432 | res = VarUI4FromStr( NULL, 0, 0, pULong ); |
| 433 | printf( "VarUI4FromStr: passing in NULL as param: %X\n", (unsigned int) res ); |
| 434 | |
| 435 | res = VarUI4FromI2( 0, pULong ); |
| 436 | printf( "VarUI4FromI2: 0, %lu, %X\n", *pULong, (unsigned int) res ); |
| 437 | res = VarUI4FromI2( 69, pULong ); |
| 438 | printf( "VarUI4FromI2: 69, %lu, %X\n", *pULong, (unsigned int) res ); |
| 439 | res = VarUI4FromI2( 70, pULong ); |
| 440 | printf( "VarUI4FromI2: 70, %lu, %X\n", *pULong, (unsigned int) res ); |
| 441 | res = VarUI4FromI2( 128, pULong ); |
| 442 | printf( "VarUI4FromI2: 128, %lu, %X\n", *pULong, (unsigned int) res ); |
| 443 | res = VarUI4FromI2( 255, pULong ); |
| 444 | printf( "VarUI4FromI2: 255, %lu, %X\n", *pULong, (unsigned int) res ); |
| 445 | res = VarUI4FromR8( 4294967295.0, pULong ); |
| 446 | printf( "VarUI4FromR8: 4294967295, %lu, %X\n", *pULong, (unsigned int) res ); |
| 447 | res = VarUI4FromR8( 4294967296.0, pULong ); |
| 448 | printf( "VarUI4FromR8: 4294967296, %lu, %X\n", *pULong, (unsigned int) res ); |
| 449 | |
| 450 | res = VarUI4FromR8( 0.0, pULong ); |
| 451 | printf( "VarUI4FromR8: 0.0, %lu, %X\n", *pULong, (unsigned int) res ); |
| 452 | res = VarUI4FromR8( 69.33, pULong ); |
| 453 | printf( "VarUI4FromR8: 69.33, %lu, %X\n", *pULong, (unsigned int) res ); |
| 454 | res = VarUI4FromR8( 69.66, pULong ); |
| 455 | printf( "VarUI4FromR8: 69.66, %lu, %X\n", *pULong, (unsigned int) res ); |
| 456 | res = VarUI4FromR8( -69.33, pULong ); |
| 457 | printf( "VarUI4FromR8: -69.33, %lu, %X\n", *pULong, (unsigned int) res ); |
| 458 | res = VarUI4FromR8( -69.66, pULong ); |
| 459 | printf( "VarUI4FromR8: -69.66, %lu, %X\n", *pULong, (unsigned int) res ); |
| 460 | |
| 461 | res = VarUI4FromR8( -0.5, pULong ); |
| 462 | printf( "VarUI4FromR8: -0.5, %lu, %X\n", *pULong, (unsigned int) res ); |
| 463 | res = VarUI4FromR8( -0.51, pULong ); |
| 464 | printf( "VarUI4FromR8: -0.51, %lu, %X\n", *pULong, (unsigned int) res ); |
| 465 | res = VarUI4FromR8( -0.49, pULong ); |
| 466 | printf( "VarUI4FromR8: -0.49, %lu, %X\n", *pULong, (unsigned int) res ); |
| 467 | |
| 468 | res = VarUI4FromR8( 0.5, pULong ); |
| 469 | printf( "VarUI4FromR8: 0.5, %lu, %X\n", *pULong, (unsigned int) res ); |
| 470 | res = VarUI4FromR8( 0.51, pULong ); |
| 471 | printf( "VarUI4FromR8: 0.51, %lu, %X\n", *pULong, (unsigned int) res ); |
| 472 | res = VarUI4FromR8( 0.49, pULong ); |
| 473 | printf( "VarUI4FromR8: 0.49, %lu, %X\n", *pULong, (unsigned int) res ); |
| 474 | |
| 475 | res = VarUI4FromDate( 0.0, pULong ); |
| 476 | printf( "VarUI4FromDate: 0.0, %lu, %X\n", *pULong, (unsigned int) res ); |
| 477 | res = VarUI4FromDate( 69.33, pULong ); |
| 478 | printf( "VarUI4FromDate: 69.33, %lu, %X\n", *pULong, (unsigned int) res ); |
| 479 | res = VarUI4FromDate( 69.66, pULong ); |
| 480 | printf( "VarUI4FromDate: 69.66, %lu, %X\n", *pULong, (unsigned int) res ); |
| 481 | res = VarUI4FromDate( -69.33, pULong ); |
| 482 | printf( "VarUI4FromDate: -69.33, %lu, %X\n", *pULong, (unsigned int) res ); |
| 483 | res = VarUI4FromDate( -69.66, pULong ); |
| 484 | printf( "VarUI4FromDate: -69.66, %lu, %X\n", *pULong, (unsigned int) res ); |
| 485 | |
| 486 | res = VarUI4FromBool( VARIANT_TRUE, pULong ); |
| 487 | printf( "VarUI4FromBool: VARIANT_TRUE, %lu, %X\n", *pULong, (unsigned int) res ); |
| 488 | res = VarUI4FromBool( VARIANT_FALSE, pULong ); |
| 489 | printf( "VarUI4FromBool: VARIANT_FALSE, %lu, %X\n", *pULong, (unsigned int) res ); |
| 490 | |
| 491 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 492 | { |
| 493 | res = VarUI4FromStr( pOleChar[olePtrIndex], 0, 0, pULong ); |
| 494 | printf( "VarUI4FromStr: %s, %lu, %X\n", WtoA(pOleChar[olePtrIndex]), *pULong, (unsigned int) res ); |
| 495 | } |
| 496 | |
| 497 | /* CHAR from ... |
| 498 | */ |
| 499 | printf( "\n\n======== Testing VarI1FromXXX ========\n"); |
| 500 | |
| 501 | res = VarI1FromBool( VARIANT_TRUE, pByte ); |
| 502 | printf( "VarI1FromBool: VARIANT_TRUE, %d, %X\n", *pByte, (unsigned int) res ); |
| 503 | |
| 504 | res = VarI1FromBool( VARIANT_TRUE, pChar ); |
| 505 | printf( "VarI1FromBool: VARIANT_TRUE, %d, %X\n", *pChar, (unsigned int) res ); |
| 506 | |
| 507 | res = VarI1FromBool( VARIANT_FALSE, pChar ); |
| 508 | printf( "VarI1FromBool: VARIANT_FALSE, %d, %X\n", *pChar, (unsigned int) res ); |
| 509 | |
| 510 | res = VarI1FromUI1( (unsigned char)32767, pChar ); |
| 511 | printf( "VarI1FromUI1: 32767, %d, %X\n", *pChar, (unsigned int) res ); |
| 512 | res = VarI1FromUI1( (unsigned char)65535, pChar ); |
| 513 | printf( "VarI1FromUI1: 65535, %d, %X\n", *pChar, (unsigned int) res ); |
| 514 | |
| 515 | res = VarI1FromI4( 32767, pChar ); |
| 516 | printf( "VarI1FromI4: 32767, %d, %X\n", *pChar, (unsigned int) res ); |
| 517 | res = VarI1FromI4( 32768, pChar ); |
| 518 | printf( "VarI1FromI4: 32768, %d, %X\n", *pChar, (unsigned int) res ); |
| 519 | res = VarI1FromI4( -32768, pChar ); |
| 520 | printf( "VarI1FromI4: -32768, %d, %X\n", *pChar, (unsigned int) res ); |
| 521 | res = VarI1FromI4( -32769, pChar ); |
| 522 | printf( "VarI1FromI4: -32769, %d, %X\n", *pChar, (unsigned int) res ); |
| 523 | |
| 524 | res = VarI1FromR8( 69.33, pChar ); |
| 525 | printf( "VarI1FromR8: 69.33, %d, %X\n", *pChar, (unsigned int) res ); |
| 526 | res = VarI1FromR8( 69.66, pChar ); |
| 527 | printf( "VarI1FromR8: 69.66, %d, %X\n", *pChar, (unsigned int) res ); |
| 528 | res = VarI1FromR8( -69.33, pChar ); |
| 529 | printf( "VarI1FromR8: -69.33, %d, %X\n", *pChar, (unsigned int) res ); |
| 530 | res = VarI1FromR8( -69.66, pChar ); |
| 531 | printf( "VarI1FromR8: -69.66, %d, %X\n", *pChar, (unsigned int) res ); |
| 532 | |
| 533 | res = VarI1FromDate( -69.66, pChar ); |
| 534 | printf( "VarI1FromDate: -69.66, %d, %X\n", *pChar, (unsigned int) res ); |
| 535 | |
| 536 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 537 | { |
| 538 | res = VarI1FromStr( pOleChar[olePtrIndex], 0, 0, pChar ); |
| 539 | printf( "VarI1FromStr: %s, %d, %X\n", WtoA(pOleChar[olePtrIndex]), *pChar, (unsigned int) res ); |
| 540 | } |
| 541 | |
| 542 | /* short from ... |
| 543 | */ |
| 544 | printf( "\n\n======== Testing VarI2FromXXX ========\n"); |
| 545 | |
| 546 | res = VarI2FromUI2( 32767, pShort ); |
| 547 | printf( "VarI2FromUI2: 32767, %d, %X\n", *pShort, (unsigned int) res ); |
| 548 | res = VarI2FromUI2( 65535, pShort ); |
| 549 | printf( "VarI2FromUI2: 65535, %d, %X\n", *pShort, (unsigned int) res ); |
| 550 | |
| 551 | res = VarI2FromI4( 32767, pShort ); |
| 552 | printf( "VarI2FromI4: 32767, %d, %X\n", *pShort, (unsigned int) res ); |
| 553 | res = VarI2FromI4( 32768, pShort ); |
| 554 | printf( "VarI2FromI4: 32768, %d, %X\n", *pShort, (unsigned int) res ); |
| 555 | res = VarI2FromI4( -32768, pShort ); |
| 556 | printf( "VarI2FromI4: -32768, %d, %X\n", *pShort, (unsigned int) res ); |
| 557 | res = VarI2FromI4( -32769, pShort ); |
| 558 | printf( "VarI2FromI4: -32769, %d, %X\n", *pShort, (unsigned int) res ); |
| 559 | |
| 560 | res = VarI2FromR8( 69.33, pShort ); |
| 561 | printf( "VarI2FromR8: 69.33, %d, %X\n", *pShort, (unsigned int) res ); |
| 562 | res = VarI2FromR8( 69.66, pShort ); |
| 563 | printf( "VarI2FromR8: 69.66, %d, %X\n", *pShort, (unsigned int) res ); |
| 564 | res = VarI2FromR8( -69.33, pShort ); |
| 565 | printf( "VarI2FromR8: -69.33, %d, %X\n", *pShort, (unsigned int) res ); |
| 566 | res = VarI2FromR8( -69.66, pShort ); |
| 567 | printf( "VarI2FromR8: -69.66, %d, %X\n", *pShort, (unsigned int) res ); |
| 568 | |
| 569 | res = VarI2FromDate( -69.66, pShort ); |
| 570 | printf( "VarI2FromDate: -69.66, %d, %X\n", *pShort, (unsigned int) res ); |
| 571 | |
| 572 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 573 | { |
| 574 | res = VarI2FromStr( pOleChar[olePtrIndex], 0, 0, pShort ); |
| 575 | printf( "VarI2FromStr: %s, %d, %X\n", WtoA(pOleChar[olePtrIndex]), *pShort, (unsigned int) res ); |
| 576 | } |
| 577 | |
| 578 | /* long from ... |
| 579 | */ |
| 580 | printf( "\n\n======== Testing VarI4FromXXX ========\n"); |
| 581 | |
| 582 | res = VarI4FromI2( 3, (long*)pInt ); |
| 583 | printf( "VarIntFromI2: 3, %d, %X\n", *pInt, (unsigned int) res ); |
| 584 | |
| 585 | res = VarI4FromR8( 69.33, pLong ); |
| 586 | printf( "VarI4FromR8: 69.33, %ld, %X\n", *pLong, (unsigned int) res ); |
| 587 | res = VarI4FromR8( 69.66, pLong ); |
| 588 | printf( "VarI4FromR8: 69.66, %ld, %X\n", *pLong, (unsigned int) res ); |
| 589 | res = VarI4FromR8( -69.33, pLong ); |
| 590 | printf( "VarI4FromR8: -69.33, %ld, %X\n", *pLong, (unsigned int) res ); |
| 591 | res = VarI4FromR8( -69.66, pLong ); |
| 592 | printf( "VarI4FromR8: -69.66, %ld, %X\n", *pLong, (unsigned int) res ); |
| 593 | |
| 594 | res = VarI4FromR8( 2147483647.0, pLong ); |
| 595 | printf( "VarI4FromR8: 2147483647.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 596 | res = VarI4FromR8( 2147483648.0, pLong ); |
| 597 | printf( "VarI4FromR8: 2147483648.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 598 | res = VarI4FromR8( -2147483647.0, pLong ); |
| 599 | printf( "VarI4FromR8: -2147483647.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 600 | res = VarI4FromR8( -2147483648.0, pLong ); |
| 601 | printf( "VarI4FromR8: -2147483648.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 602 | res = VarI4FromR8( -2147483649.0, pLong ); |
| 603 | printf( "VarI4FromR8: -2147483649.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 604 | |
| 605 | res = VarI4FromDate( -2147483649.0, pLong ); |
| 606 | printf( "VarI4FromDate: -2147483649.0, %ld, %X\n", *pLong, (unsigned int) res ); |
| 607 | |
| 608 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 609 | { |
| 610 | res = VarI4FromStr( pOleChar[olePtrIndex], 0, 0, pLong ); |
| 611 | printf( "VarI4FromStr: %s, %ld, %X\n", WtoA(pOleChar[olePtrIndex]), *pLong, (unsigned int) res ); |
| 612 | } |
| 613 | |
| 614 | /* float from ... |
| 615 | */ |
| 616 | printf( "\n\n======== Testing VarR4FromXXX ========\n"); |
| 617 | |
| 618 | res = VarR4FromI4( 16777216, pFloat ); |
| 619 | printf( "VarR4FromI4: 16777216, %f, %X\n", *pFloat, (unsigned int) res ); |
| 620 | res = VarR4FromI4( 16777217, pFloat ); |
| 621 | printf( "VarR4FromI4: 16777217, %f, %X\n", *pFloat, (unsigned int) res ); |
| 622 | res = VarR4FromI4( -16777216, pFloat ); |
| 623 | printf( "VarR4FromI4: -16777216, %f, %X\n", *pFloat, (unsigned int) res ); |
| 624 | res = VarR4FromI4( -16777217, pFloat ); |
| 625 | printf( "VarR4FromI4: -16777217, %f, %X\n", *pFloat, (unsigned int) res ); |
| 626 | |
| 627 | res = VarR4FromR8( 16777216.0, pFloat ); |
| 628 | printf( "VarR4FromR8: 16777216.0, %f, %X\n", *pFloat, (unsigned int) res ); |
| 629 | res = VarR4FromR8( 16777217.0, pFloat ); |
| 630 | printf( "VarR4FromR8: 16777217.0, %f, %X\n", *pFloat, (unsigned int) res ); |
| 631 | res = VarR4FromR8( -16777216.0, pFloat ); |
| 632 | printf( "VarR4FromR8: -16777216.0, %f, %X\n", *pFloat, (unsigned int) res ); |
| 633 | res = VarR4FromR8( -16777217.0, pFloat ); |
| 634 | printf( "VarR4FromR8: -16777217.0, %f, %X\n", *pFloat, (unsigned int) res ); |
| 635 | |
| 636 | res = VarR4FromR8( 16777218e31, pFloat ); |
| 637 | printf( "VarR4FromR8: 16777218e31, %f, %X\n", *pFloat, (unsigned int) res ); |
| 638 | res = VarR4FromR8( 16777218e32, pFloat ); |
| 639 | printf( "VarR4FromR8: 16777218e32, %f, %X\n", *pFloat, (unsigned int) res ); |
| 640 | |
| 641 | res = VarR4FromDate( 16777218e31, pFloat ); |
| 642 | printf( "VarR4FromDate: 16777218e31, %f, %X\n", *pFloat, (unsigned int) res ); |
| 643 | |
| 644 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 645 | { |
| 646 | res = VarR4FromStr( pOleChar[olePtrIndex], 0, 0, pFloat ); |
| 647 | printf( "VarR4FromStr: %s, %f, %X\n", WtoA(pOleChar[olePtrIndex]), *pFloat, (unsigned int) res ); |
| 648 | } |
| 649 | |
| 650 | /* double from ... |
| 651 | */ |
| 652 | printf( "\n\n======== Testing VarR8FromXXX ========\n"); |
| 653 | |
| 654 | res = VarR8FromDate( 900719925474099.0, pDouble ); |
| 655 | printf( "VarR8FromDate: 900719925474099.0, %f, %X\n", *pDouble, (unsigned int) res ); |
| 656 | |
| 657 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 658 | { |
| 659 | res = VarR8FromStr( pOleChar[olePtrIndex], 0, 0, pDouble ); |
| 660 | printf( "VarR8FromStr: %s, %f, %X\n", WtoA(pOleChar[olePtrIndex]), *pDouble, (unsigned int) res ); |
| 661 | } |
| 662 | |
| 663 | /* date from ... |
| 664 | */ |
| 665 | printf( "\n\n======== Testing VarDateFromXXX ========\n"); |
| 666 | |
| 667 | res = VarDateFromI4( 2958465, pDouble ); |
| 668 | printf( "VarDateFromI4: 2958465, %f, %X\n", *pDouble, (unsigned int) res ); |
| 669 | res = VarDateFromI4( 2958466, pDouble ); |
| 670 | printf( "VarDateFromI4: 2958466, %f, %X\n", *pDouble, (unsigned int) res ); |
| 671 | res = VarDateFromI4( -657434, pDouble ); |
| 672 | printf( "VarDateFromI4: -657434, %f, %X\n", *pDouble, (unsigned int) res ); |
| 673 | res = VarDateFromI4( -657435, pDouble ); |
| 674 | printf( "VarDateFromI4: -657435, %f, %X\n", *pDouble, (unsigned int) res ); |
| 675 | |
| 676 | res = VarDateFromR8( 2958465.9999, pDouble ); |
| 677 | printf( "VarDateFromR8: 2958465.9999, %f, %X\n", *pDouble, (unsigned int) res ); |
| 678 | res = VarDateFromR8( 2958466, pDouble ); |
| 679 | printf( "VarDateFromR8: 2958466, %f, %X\n", *pDouble, (unsigned int) res ); |
| 680 | res = VarDateFromR8( -657434.9999, pDouble ); |
| 681 | printf( "VarDateFromR8: -657434.9999, %f, %X\n", *pDouble, (unsigned int) res ); |
| 682 | res = VarDateFromR8( -657435, pDouble ); |
| 683 | printf( "VarDateFromR8: -657435, %f, %X\n", *pDouble, (unsigned int) res ); |
| 684 | |
| 685 | |
| 686 | res = VarDateFromR8( 0.0, pDouble ); |
| 687 | printf( "VarDateFromR8: 0.0, %f, %X\n", *pDouble, (unsigned int) res ); |
| 688 | res = VarDateFromR8( 1.0, pDouble ); |
| 689 | printf( "VarDateFromR8: 1.0, %f, %X\n", *pDouble, (unsigned int) res ); |
| 690 | res = VarDateFromR8( 2.25, pDouble ); |
| 691 | printf( "VarDateFromR8: 2.25, %f, %X\n", *pDouble, (unsigned int) res ); |
| 692 | res = VarDateFromR8( -2.0, pDouble ); |
| 693 | printf( "VarDateFromR8: -2.0, %f, %X\n", *pDouble, (unsigned int) res ); |
| 694 | |
| 695 | /* Need some parsing function in Linux to emulate this... |
| 696 | * Still in progess. |
| 697 | */ |
| 698 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 699 | { |
| 700 | res = VarDateFromStr( pOleChar[olePtrIndex], 0, 0, pDouble ); |
| 701 | printf( "VarDateFromStr: %s, %f, %X\n", WtoA(pOleChar[olePtrIndex]), *pDouble, (unsigned int) res ); |
| 702 | } |
| 703 | |
| 704 | /* bool from ... |
| 705 | */ |
| 706 | printf( "\n\n======== Testing VarBoolFromXXX ========\n"); |
| 707 | |
| 708 | res = VarBoolFromI4( 0, pBool ); |
| 709 | printf( "VarBoolFromI4: 0, %d, %X\n", *pBool, (unsigned int) res ); |
| 710 | res = VarBoolFromI4( 1, pBool ); |
| 711 | printf( "VarBoolFromI4: 1, %d, %X\n", *pBool, (unsigned int) res ); |
| 712 | res = VarBoolFromI4( -1, pBool ); |
| 713 | printf( "VarBoolFromI4: -1, %d, %X\n", *pBool, (unsigned int) res ); |
| 714 | res = VarBoolFromI4( 2, pBool ); |
| 715 | printf( "VarBoolFromI4: 2, %d, %X\n", *pBool, (unsigned int) res ); |
| 716 | |
| 717 | res = VarBoolFromUI1( ' ', pBool ); |
| 718 | printf( "VarBoolFromUI1: ' ', %d, %X\n", *pBool, (unsigned int) res ); |
| 719 | res = VarBoolFromUI1( '\0', pBool ); |
| 720 | printf( "VarBoolFromUI1: '\\0', %d, %X\n", *pBool, (unsigned int) res ); |
| 721 | res = VarBoolFromUI1( 0x0000, pBool ); |
| 722 | printf( "VarBoolFromUI1: 0x0000, %d, %X\n", *pBool, (unsigned int) res ); |
| 723 | res = VarBoolFromUI1( (unsigned char)0xFFF, pBool ); |
| 724 | printf( "VarBoolFromUI1: 0xFFF, %d, %X\n", *pBool, (unsigned int) res ); |
| 725 | res = VarBoolFromUI1( (unsigned char)0xFFFF, pBool ); |
| 726 | printf( "VarBoolFromUI1: 0xFFFF, %d, %X\n", *pBool, (unsigned int) res ); |
| 727 | |
| 728 | res = VarBoolFromR8( 0.0, pBool ); |
| 729 | printf( "VarBoolFromR8: 0.0, %d, %X\n", *pBool, (unsigned int) res ); |
| 730 | res = VarBoolFromR8( 1.1, pBool ); |
| 731 | printf( "VarBoolFromR8: 1.1, %d, %X\n", *pBool, (unsigned int) res ); |
| 732 | res = VarBoolFromR8( 0.5, pBool ); |
| 733 | printf( "VarBoolFromR8: 0.5, %d, %X\n", *pBool, (unsigned int) res ); |
| 734 | res = VarBoolFromR8( 0.49, pBool ); |
| 735 | printf( "VarBoolFromR8: 0.49, %d, %X\n", *pBool, (unsigned int) res ); |
| 736 | res = VarBoolFromR8( 0.51, pBool ); |
| 737 | printf( "VarBoolFromR8: 0.51, %d, %X\n", *pBool, (unsigned int) res ); |
| 738 | res = VarBoolFromR8( -0.5, pBool ); |
| 739 | printf( "VarBoolFromR8: -0.5, %d, %X\n", *pBool, (unsigned int) res ); |
| 740 | res = VarBoolFromR8( -0.49, pBool ); |
| 741 | printf( "VarBoolFromR8: -0.49, %d, %X\n", *pBool, (unsigned int) res ); |
| 742 | res = VarBoolFromR8( -0.51, pBool ); |
| 743 | printf( "VarBoolFromR8: -0.51, %d, %X\n", *pBool, (unsigned int) res ); |
| 744 | |
| 745 | |
| 746 | for( olePtrIndex = 0; olePtrIndex < nOlePtrs; olePtrIndex ++ ) |
| 747 | { |
| 748 | res = VarBoolFromStr( pOleChar[olePtrIndex], 0, 0, pBool ); |
| 749 | printf( "VarBoolFromStr: %s, %d, %X\n", WtoA(pOleChar[olePtrIndex]), *pBool, (unsigned int) res ); |
| 750 | } |
| 751 | |
| 752 | res = VarI1FromBool( VARIANT_TRUE, pByte ); |
| 753 | printf( "VarI1FromBool: VARIANT_TRUE, %d, %X\n", *pByte, (unsigned int) res ); |
| 754 | |
| 755 | res = VarUI2FromI2( -1, &i ); |
| 756 | printf( "VarUI2FromI2: -1, %d, %X\n", i, (unsigned int) res ); |
| 757 | |
| 758 | |
| 759 | /* BSTR from ... |
| 760 | */ |
| 761 | printf( "\n\n======== Testing VarBSTRFromXXX ========\n"); |
| 762 | |
| 763 | /* integers... |
| 764 | */ |
| 765 | res = VarBstrFromI1( -100, 0, 0, &bstr ); |
| 766 | printf( "VarBstrFromI1: -100, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 767 | |
| 768 | res = VarBstrFromUI1( 0x5A, 0, 0, &bstr ); |
| 769 | printf( "VarBstrFromUI1: 0x5A, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 770 | |
| 771 | res = VarBstrFromI4( 2958465, 0, 0, &bstr ); |
| 772 | printf( "VarBstrFromI4: 2958465, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 773 | |
| 774 | /* reals... |
| 775 | */ |
| 776 | d=0; |
| 777 | for( i=0; i<20; i++ ) |
| 778 | { |
| 779 | /* add an integer to the real number |
| 780 | */ |
| 781 | d += ((i%9)+1) * pow( 10, i ); |
| 782 | res = VarBstrFromR8( d, 0, 0, &bstr ); |
| 783 | printf( "VarBstrFromR8: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int) res ); |
| 784 | res = VarBstrFromR8( -d, 0, 0, &bstr ); |
| 785 | printf( "VarBstrFromR8: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 786 | } |
| 787 | d=0; |
| 788 | for( i=0; i<20; i++ ) |
| 789 | { |
| 790 | /* add a decimal to the real number |
| 791 | */ |
| 792 | d += ((i%9)+1) * pow( 10, (i*-1) ); |
| 793 | res = VarBstrFromR8( d, 0, 0, &bstr ); |
| 794 | printf( "VarBstrFromR8: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int) res ); |
| 795 | res = VarBstrFromR8( d-1, 0, 0, &bstr ); |
| 796 | printf( "VarBstrFromR8: %f, %s, %X\n", d-1, WtoA( bstr ), (unsigned int) res ); |
| 797 | res = VarBstrFromR8( -d, 0, 0, &bstr ); |
| 798 | printf( "VarBstrFromR8: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 799 | } |
| 800 | |
| 801 | d=0; |
| 802 | for( i=0; i<20; i++ ) |
| 803 | { |
| 804 | /* add an integer to the real number |
| 805 | */ |
| 806 | d += ((i%9)+1) * pow( 10, i ); |
| 807 | /* add a decimal to the real number |
| 808 | */ |
| 809 | d += ((i%9)+1) * pow( 10, (i*-1) ); |
| 810 | res = VarBstrFromR8( d, 0, 0, &bstr ); |
| 811 | printf( "VarBstrFromR8: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int)res ); |
| 812 | res = VarBstrFromR8( -d, 0, 0, &bstr ); |
| 813 | printf( "VarBstrFromR8: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | |
| 818 | d=0; |
| 819 | for( i=0; i<10; i++ ) |
| 820 | { |
| 821 | /* add an integer to the real number |
| 822 | */ |
| 823 | d += ((i%9)+1) * pow( 10, i ); |
| 824 | res = VarBstrFromR4( (float)d, 0, 0, &bstr ); |
| 825 | printf( "VarBstrFromR4: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int) res ); |
| 826 | res = VarBstrFromR4( (float)-d, 0, 0, &bstr ); |
| 827 | printf( "VarBstrFromR4: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 828 | } |
| 829 | d=0; |
| 830 | for( i=0; i<10; i++ ) |
| 831 | { |
| 832 | /* add a decimal to the real number |
| 833 | */ |
| 834 | d += ((i%9)+1) * pow( 10, (i*-1) ); |
| 835 | res = VarBstrFromR4( (float)d, 0, 0, &bstr ); |
| 836 | printf( "VarBstrFromR4: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int) res ); |
| 837 | res = VarBstrFromR4( (float)d-1, 0, 0, &bstr ); |
| 838 | printf( "VarBstrFromR4: %f, %s, %X\n", d-1, WtoA( bstr ), (unsigned int) res ); |
| 839 | res = VarBstrFromR4( (float)-d, 0, 0, &bstr ); |
| 840 | printf( "VarBstrFromR4: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 841 | } |
| 842 | |
| 843 | d=0; |
| 844 | for( i=0; i<10; i++ ) |
| 845 | { |
| 846 | /* add an integer to the real number |
| 847 | */ |
| 848 | d += ((i%9)+1) * pow( 10, i ); |
| 849 | /* add a decimal to the real number |
| 850 | */ |
| 851 | d += ((i%9)+1) * pow( 10, (i*-1) ); |
| 852 | res = VarBstrFromR4( (float)d, 0, 0, &bstr ); |
| 853 | printf( "VarBstrFromR4: %f, %s, %X\n", d, WtoA( bstr ), (unsigned int) res ); |
| 854 | res = VarBstrFromR4( (float)-d, 0, 0, &bstr ); |
| 855 | printf( "VarBstrFromR4: %f, %s, %X\n", -d, WtoA( bstr ), (unsigned int) res ); |
| 856 | } |
| 857 | |
| 858 | res = VarBstrFromBool( 0x00, 0, 0, &bstr ); |
| 859 | printf( "VarBstrFromBool: 0x00, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 860 | res = VarBstrFromBool( 0xFF, 0, 0, &bstr ); |
| 861 | printf( "VarBstrFromBool: 0xFF, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 862 | |
| 863 | res = VarBstrFromDate( 0.0, 0, 0, &bstr ); |
| 864 | printf( "VarBstrFromDate: 0.0, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 865 | res = VarBstrFromDate( 3.34, 0, 0, &bstr ); |
| 866 | printf( "VarBstrFromDate: 3.34, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 867 | res = VarBstrFromDate( 3339.34, 0, 0, &bstr ); |
| 868 | printf( "VarBstrFromDate: 3339.34, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 869 | res = VarBstrFromDate( 365.00, 0, 0, &bstr ); |
| 870 | printf( "VarBstrFromDate: 365.00, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 871 | res = VarBstrFromDate( 365.25, 0, 0, &bstr ); |
| 872 | printf( "VarBstrFromDate: 365.25, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 873 | res = VarBstrFromDate( 1461.0, 0, 0, &bstr ); |
| 874 | printf( "VarBstrFromDate: 1461.00, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 875 | res = VarBstrFromDate( 1461.5, 0, 0, &bstr ); |
| 876 | printf( "VarBstrFromDate: 1461.5, %s, %X\n", WtoA( bstr ), (unsigned int) res ); |
| 877 | |
| 878 | |
| 879 | res = VarBstrFromBool( 0x00, 0, 0, &bstr ); |
| 880 | printf( "VarBstrFromBool: 0x00, %s, %X\n", WtoA(bstr), (unsigned int) res ); |
| 881 | res = VarBstrFromBool( 0xFF, 0, 0, &bstr ); |
| 882 | printf( "VarBstrFromBool: 0xFF, %s, %X\n", WtoA(bstr), (unsigned int) res ); |
| 883 | |
| 884 | res = VarBstrFromDate( 0.0, 0, 0, &bstr ); |
| 885 | printf( "VarBstrFromDate: 0.0, %s, %X\n", WtoA(bstr), (unsigned int) res ); |
| 886 | res = VarBstrFromDate( 3.34, 0, 0, &bstr ); |
| 887 | printf( "VarBstrFromDate: 3.34, %s, %X\n", WtoA(bstr), (unsigned int) res ); |
| 888 | |
| 889 | /* Test variant API... |
| 890 | */ |
| 891 | printf( "\n\n======== Testing Hi-Level Variant API ========\n"); |
| 892 | |
| 893 | bstr = SysAllocString( pOleChar[4] ); |
| 894 | |
| 895 | res = VariantClear( &va ); |
| 896 | printf( "Result is: %x\n", (unsigned int)res ); |
| 897 | |
| 898 | VariantInit( &va ); |
| 899 | VariantInit( &vb ); |
| 900 | VariantInit( &vc ); |
| 901 | VariantInit( &vd ); |
| 902 | VariantInit( &ve ); |
| 903 | |
| 904 | va.vt = VT_BSTR; |
| 905 | va.u.bstrVal = bstr; |
| 906 | res = VariantClear( &va ); |
| 907 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 908 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 909 | SysFreeString( bstr ); |
| 910 | SysFreeString( bstr ); |
| 911 | |
| 912 | res = VariantCopy( &vb, &va ); |
| 913 | printf( "VariantCopy: %x\n", (unsigned int)res ); |
| 914 | res = VariantClear( &vb ); |
| 915 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 916 | res = VariantClear( &va ); |
| 917 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 918 | |
| 919 | |
| 920 | va.vt = VT_R8; |
| 921 | d = 4.123; |
| 922 | va.u.dblVal = d; |
| 923 | res = VariantCopy( &va, &va ); |
| 924 | printf( "VariantCopy %f -> %f: %x\n", V_R8(&va), V_R8(&va), (unsigned int)res ); |
| 925 | |
| 926 | va.vt = VT_R8 | VT_BYREF; |
| 927 | d = 31.123; |
| 928 | va.u.pdblVal = &d; |
| 929 | res = VariantCopyInd( &va, &va ); |
| 930 | printf( "VariantCopyInd %f: %x\n", V_R8(&va), (unsigned int)res ); |
| 931 | |
| 932 | va.vt = VT_R8; |
| 933 | d = 1.123; |
| 934 | va.u.dblVal = d; |
| 935 | res = VariantCopy( &vb, &va ); |
| 936 | printf( "VariantCopy %f -> %f: %x\n", V_R8(&va), V_R8(&vb), (unsigned int)res ); |
| 937 | |
| 938 | va.vt = VT_R8 | VT_BYREF; |
| 939 | d = 123.123; |
| 940 | va.u.pdblVal = &d; |
| 941 | res = VariantCopy( &vb, &va ); |
| 942 | printf( "VariantCopy %f -> %f: %x\n", *(V_R8REF(&va)), *(V_R8REF(&vb)), (unsigned int)res ); |
| 943 | |
| 944 | va.vt = VT_R8 | VT_BYREF; |
| 945 | d = 111.2; |
| 946 | va.u.pdblVal = &d; |
| 947 | res = VariantCopyInd( &vb, &va ); |
| 948 | printf( "VariantCopyInd %f -> %f: %x\n", *(V_R8REF(&va)), V_R8(&vb), (unsigned int)res ); |
| 949 | |
| 950 | va.vt = VT_R8 | VT_BYREF; |
| 951 | d = 1211.123453; |
| 952 | va.u.pdblVal = &d; |
| 953 | res = VariantChangeTypeEx( &va, &va, 0, 0, VT_I2 ); |
| 954 | printf( "VariantChangeTypeEx %d: %x\n", V_I2(&va), (unsigned int) res ); |
| 955 | |
| 956 | va.vt = VT_INT; |
| 957 | va.u.intVal = 4; |
| 958 | res = VariantChangeTypeEx(&vb, &va, 0, 0, VT_BSTR ); |
| 959 | printf( "VariantChangeTypeEx %d -> %s: %x\n", V_INT(&va), WtoA(V_BSTR(&vb)), (unsigned int)res ); |
| 960 | |
| 961 | va.vt = VT_DATE; |
| 962 | va.u.date = 34465.332431; |
| 963 | res = VariantChangeTypeEx(&vb, &va, 0, 0, VT_BSTR ); |
| 964 | printf( "VariantChangeTypeEx %f -> %s: %x\n", V_DATE(&va), WtoA(V_BSTR(&vb)), (unsigned int)res ); |
| 965 | |
| 966 | bstr = pOleChar[4]; |
| 967 | va.vt = VT_BSTR; |
| 968 | va.u.bstrVal = bstr; |
| 969 | res = VariantChangeTypeEx(&vb, &va, 0, 0, VT_R8 ); |
| 970 | printf( "VariantChangeTypeEx %s -> %f: %x\n", WtoA(V_BSTR(&va)), V_R8(&vb), (unsigned int)res ); |
| 971 | |
| 972 | |
| 973 | vc.vt = VT_BSTR | VT_BYREF; |
| 974 | vc.u.pbstrVal = &bstr; |
| 975 | vb.vt = VT_VARIANT | VT_BYREF; |
| 976 | vb.u.pvarVal = &vc; |
| 977 | va.vt = VT_VARIANT | VT_BYREF; |
| 978 | va.u.pvarVal = &vb; |
| 979 | res = VariantCopyInd( &vd, &va ); |
| 980 | printf( "VariantCopyInd: %x\n", (unsigned int)res ); |
| 981 | |
| 982 | /* test what happens when bad vartypes are passed in |
| 983 | */ |
| 984 | printf( "-------------- Testing different VARTYPES ----------------\n" ); |
| 985 | |
| 986 | for( i=0; i<100; i++ ) |
| 987 | { |
| 988 | /* Trying to use variants that are set to be BSTR but |
| 989 | * do not contain a valid pointer makes the program crash |
| 990 | * in Windows so we will skip those. We do not need them |
| 991 | * anyways to illustrate the behavior. |
| 992 | */ |
| 993 | if( i == VT_BSTR ) |
| 994 | i = 77; |
| 995 | |
| 996 | va.vt = i; |
| 997 | d = 4.123; |
| 998 | va.u.dblVal = d; |
| 999 | res = VariantCopyInd( &vb, &va ); |
| 1000 | printf( "VariantCopyInd: %d -> %x\n", i, (unsigned int)res ); |
| 1001 | |
| 1002 | va.vt = i | VT_BYREF; |
| 1003 | d = 4.123; |
| 1004 | va.u.pdblVal = &d; |
| 1005 | res = VariantCopyInd( &vb, &va ); |
| 1006 | printf( "VariantCopyInd: %d -> %x\n", i, (unsigned int)res ); |
| 1007 | |
| 1008 | va.vt = VT_R8; |
| 1009 | d = 4.123; |
| 1010 | va.u.dblVal = d; |
| 1011 | res = VariantChangeTypeEx( &vb, &va, 0, 0, i ); |
| 1012 | printf( "VariantChangeTypeEx: %d -> %x\n", i, (unsigned int)res ); |
| 1013 | |
| 1014 | va.vt = VT_R8; |
| 1015 | d = 4.123; |
| 1016 | va.u.dblVal = d; |
| 1017 | res = VariantChangeTypeEx( &vb, &va, 0, 0, i | VT_BYREF ); |
| 1018 | printf( "VariantChangeTypeEx: VT_BYREF %d -> %x\n", i, (unsigned int)res ); |
| 1019 | |
| 1020 | va.vt = 99; |
| 1021 | d = 4.123; |
| 1022 | va.u.dblVal = d; |
| 1023 | res = VariantClear( &va ); |
| 1024 | printf( "VariantClear: %d -> %x\n", i, (unsigned int)res ); |
| 1025 | |
| 1026 | } |
| 1027 | |
| 1028 | res = VariantClear( &va ); |
| 1029 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 1030 | res = VariantClear( &vb ); |
| 1031 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 1032 | res = VariantClear( &vc ); |
| 1033 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 1034 | res = VariantClear( &vd ); |
| 1035 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 1036 | res = VariantClear( &ve ); |
| 1037 | printf( "VariantClear: %x\n", (unsigned int)res ); |
| 1038 | |
| 1039 | |
| 1040 | /* There is alot of memory leaks but this is simply a test program. |
| 1041 | */ |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |