1--TEST--
2COM: General variant tests
3--EXTENSIONS--
4com_dotnet
5--SKIPIF--
6<?php
7if (8 != PHP_INT_SIZE) print "skip x64 only";
8if ((string) variant_cat(new VARIANT(false), new VARIANT(0.5)) != 'False0.5')
9    print "skip English locale only";
10?>
11--FILE--
12<?php
13error_reporting(E_ALL);
14
15$v = new VARIANT();
16if (VT_EMPTY != variant_get_type($v)) {
17    echo "VT_EMPTY: bork\n";
18}
19
20$values = array(VT_I8 => 42, VT_R8 => 3.5, VT_BSTR => "hello", VT_BOOL => false);
21$binary_ops = array('add', 'cat', 'sub', 'mul', 'and', 'div',
22    'eqv', 'idiv', 'imp', 'mod', 'or', 'pow', 'xor');
23
24foreach ($values as $t => $val) {
25    $v = new VARIANT($val);
26    if ($t != variant_get_type($v)) {
27        printf("Bork: [%d] %d: %s\n", $t, variant_get_type($v), $val);
28        print $v . "\n";
29    }
30    $results = array();
31
32    foreach ($values as $op2) {
33        echo "--\n";
34        foreach ($binary_ops as $op) {
35            try {
36                echo "$op: " . call_user_func('variant_' . $op, $v, $op2) . "\n";
37            } catch (com_exception $e) {
38                echo "$op:\n";
39                echo "\tvariant_$op($v, $op2)\n";
40                echo "\texception " . $e->getMessage();
41                printf("\n\tcode %08x\n\n", $e->getCode());
42            }
43        }
44    }
45}
46
47echo "OK!";
48?>
49--EXPECT--
50--
51add: 84
52cat: 4242
53sub: 0
54mul: 1764
55and: 42
56div: 1
57eqv: -1
58idiv: 1
59imp: -1
60mod: 0
61or: 42
62pow: 1.50130937545297E+68
63xor: 0
64--
65add: 45.5
66cat: 423.5
67sub: 38.5
68mul: 147
69and: 0
70div: 12
71eqv: -47
72idiv: 10
73imp: -43
74mod: 2
75or: 46
76pow: 480145.116863642
77xor: 46
78--
79add:
80	variant_add(42, hello)
81	exception Type mismatch
82	code 80020005
83
84cat: 42hello
85sub:
86	variant_sub(42, hello)
87	exception Type mismatch
88	code 80020005
89
90mul:
91	variant_mul(42, hello)
92	exception Type mismatch
93	code 80020005
94
95and:
96	variant_and(42, hello)
97	exception Type mismatch
98	code 80020005
99
100div:
101	variant_div(42, hello)
102	exception Type mismatch
103	code 80020005
104
105eqv:
106	variant_eqv(42, hello)
107	exception Type mismatch
108	code 80020005
109
110idiv:
111	variant_idiv(42, hello)
112	exception Type mismatch
113	code 80020005
114
115imp:
116	variant_imp(42, hello)
117	exception Type mismatch
118	code 80020005
119
120mod:
121	variant_mod(42, hello)
122	exception Type mismatch
123	code 80020005
124
125or:
126	variant_or(42, hello)
127	exception Type mismatch
128	code 80020005
129
130pow:
131	variant_pow(42, hello)
132	exception Type mismatch
133	code 80020005
134
135xor:
136	variant_xor(42, hello)
137	exception Type mismatch
138	code 80020005
139
140--
141add: 42
142cat: 42False
143sub: 42
144mul: 0
145and: 0
146div:
147	variant_div(42, )
148	exception Division by zero
149	code 80020012
150
151eqv: -43
152idiv:
153	variant_idiv(42, )
154	exception Division by zero
155	code 80020012
156
157imp: -43
158mod:
159	variant_mod(42, )
160	exception Division by zero
161	code 80020012
162
163or: 42
164pow: 1
165xor: 42
166--
167add: 45.5
168cat: 3.542
169sub: -38.5
170mul: 147
171and: 0
172div: 8.33333333333333E-02
173eqv: -47
174idiv: 0
175imp: -5
176mod: 4
177or: 46
178pow: 7.09345573078604E+22
179xor: 46
180--
181add: 7
182cat: 3.53.5
183sub: 0
184mul: 12.25
185and: 4
186div: 1
187eqv: -1
188idiv: 1
189imp: -1
190mod: 0
191or: 4
192pow: 80.2117802289664
193xor: 0
194--
195add:
196	variant_add(3.5, hello)
197	exception Type mismatch
198	code 80020005
199
200cat: 3.5hello
201sub:
202	variant_sub(3.5, hello)
203	exception Type mismatch
204	code 80020005
205
206mul:
207	variant_mul(3.5, hello)
208	exception Type mismatch
209	code 80020005
210
211and:
212	variant_and(3.5, hello)
213	exception Type mismatch
214	code 80020005
215
216div:
217	variant_div(3.5, hello)
218	exception Type mismatch
219	code 80020005
220
221eqv:
222	variant_eqv(3.5, hello)
223	exception Type mismatch
224	code 80020005
225
226idiv:
227	variant_idiv(3.5, hello)
228	exception Type mismatch
229	code 80020005
230
231imp:
232	variant_imp(3.5, hello)
233	exception Type mismatch
234	code 80020005
235
236mod:
237	variant_mod(3.5, hello)
238	exception Type mismatch
239	code 80020005
240
241or:
242	variant_or(3.5, hello)
243	exception Type mismatch
244	code 80020005
245
246pow:
247	variant_pow(3.5, hello)
248	exception Type mismatch
249	code 80020005
250
251xor:
252	variant_xor(3.5, hello)
253	exception Type mismatch
254	code 80020005
255
256--
257add: 3.5
258cat: 3.5False
259sub: 3.5
260mul: 0
261and: 0
262div:
263	variant_div(3.5, )
264	exception Division by zero
265	code 80020012
266
267eqv: -5
268idiv:
269	variant_idiv(3.5, )
270	exception Division by zero
271	code 80020012
272
273imp: -5
274mod:
275	variant_mod(3.5, )
276	exception Division by zero
277	code 80020012
278
279or: 4
280pow: 1
281xor: 4
282--
283add:
284	variant_add(hello, 42)
285	exception Type mismatch
286	code 80020005
287
288cat: hello42
289sub:
290	variant_sub(hello, 42)
291	exception Type mismatch
292	code 80020005
293
294mul:
295	variant_mul(hello, 42)
296	exception Type mismatch
297	code 80020005
298
299and:
300	variant_and(hello, 42)
301	exception Type mismatch
302	code 80020005
303
304div:
305	variant_div(hello, 42)
306	exception Type mismatch
307	code 80020005
308
309eqv:
310	variant_eqv(hello, 42)
311	exception Type mismatch
312	code 80020005
313
314idiv:
315	variant_idiv(hello, 42)
316	exception Type mismatch
317	code 80020005
318
319imp:
320	variant_imp(hello, 42)
321	exception Type mismatch
322	code 80020005
323
324mod:
325	variant_mod(hello, 42)
326	exception Type mismatch
327	code 80020005
328
329or:
330	variant_or(hello, 42)
331	exception Type mismatch
332	code 80020005
333
334pow:
335	variant_pow(hello, 42)
336	exception Type mismatch
337	code 80020005
338
339xor:
340	variant_xor(hello, 42)
341	exception Type mismatch
342	code 80020005
343
344--
345add:
346	variant_add(hello, 3.5)
347	exception Type mismatch
348	code 80020005
349
350cat: hello3.5
351sub:
352	variant_sub(hello, 3.5)
353	exception Type mismatch
354	code 80020005
355
356mul:
357	variant_mul(hello, 3.5)
358	exception Type mismatch
359	code 80020005
360
361and:
362	variant_and(hello, 3.5)
363	exception Type mismatch
364	code 80020005
365
366div:
367	variant_div(hello, 3.5)
368	exception Type mismatch
369	code 80020005
370
371eqv:
372	variant_eqv(hello, 3.5)
373	exception Type mismatch
374	code 80020005
375
376idiv:
377	variant_idiv(hello, 3.5)
378	exception Type mismatch
379	code 80020005
380
381imp:
382	variant_imp(hello, 3.5)
383	exception Type mismatch
384	code 80020005
385
386mod:
387	variant_mod(hello, 3.5)
388	exception Type mismatch
389	code 80020005
390
391or:
392	variant_or(hello, 3.5)
393	exception Type mismatch
394	code 80020005
395
396pow:
397	variant_pow(hello, 3.5)
398	exception Type mismatch
399	code 80020005
400
401xor:
402	variant_xor(hello, 3.5)
403	exception Type mismatch
404	code 80020005
405
406--
407add: hellohello
408cat: hellohello
409sub:
410	variant_sub(hello, hello)
411	exception Type mismatch
412	code 80020005
413
414mul:
415	variant_mul(hello, hello)
416	exception Type mismatch
417	code 80020005
418
419and:
420	variant_and(hello, hello)
421	exception Type mismatch
422	code 80020005
423
424div:
425	variant_div(hello, hello)
426	exception Type mismatch
427	code 80020005
428
429eqv:
430	variant_eqv(hello, hello)
431	exception Type mismatch
432	code 80020005
433
434idiv:
435	variant_idiv(hello, hello)
436	exception Type mismatch
437	code 80020005
438
439imp:
440	variant_imp(hello, hello)
441	exception Type mismatch
442	code 80020005
443
444mod:
445	variant_mod(hello, hello)
446	exception Type mismatch
447	code 80020005
448
449or:
450	variant_or(hello, hello)
451	exception Type mismatch
452	code 80020005
453
454pow:
455	variant_pow(hello, hello)
456	exception Type mismatch
457	code 80020005
458
459xor:
460	variant_xor(hello, hello)
461	exception Type mismatch
462	code 80020005
463
464--
465add:
466	variant_add(hello, )
467	exception Type mismatch
468	code 80020005
469
470cat: helloFalse
471sub:
472	variant_sub(hello, )
473	exception Type mismatch
474	code 80020005
475
476mul:
477	variant_mul(hello, )
478	exception Type mismatch
479	code 80020005
480
481and:
482	variant_and(hello, )
483	exception Type mismatch
484	code 80020005
485
486div:
487	variant_div(hello, )
488	exception Type mismatch
489	code 80020005
490
491eqv:
492	variant_eqv(hello, )
493	exception Type mismatch
494	code 80020005
495
496idiv:
497	variant_idiv(hello, )
498	exception Type mismatch
499	code 80020005
500
501imp:
502	variant_imp(hello, )
503	exception Type mismatch
504	code 80020005
505
506mod:
507	variant_mod(hello, )
508	exception Type mismatch
509	code 80020005
510
511or:
512	variant_or(hello, )
513	exception Type mismatch
514	code 80020005
515
516pow:
517	variant_pow(hello, )
518	exception Type mismatch
519	code 80020005
520
521xor:
522	variant_xor(hello, )
523	exception Type mismatch
524	code 80020005
525
526--
527add: 42
528cat: False42
529sub: -42
530mul: 0
531and: 0
532div: 0
533eqv: -43
534idiv: 0
535imp: -1
536mod: 0
537or: 42
538pow: 0
539xor: 42
540--
541add: 3.5
542cat: False3.5
543sub: -3.5
544mul: 0
545and: 0
546div: 0
547eqv: -5
548idiv: 0
549imp: -1
550mod: 0
551or: 4
552pow: 0
553xor: 4
554--
555add:
556	variant_add(0, hello)
557	exception Type mismatch
558	code 80020005
559
560cat: Falsehello
561sub:
562	variant_sub(0, hello)
563	exception Type mismatch
564	code 80020005
565
566mul:
567	variant_mul(0, hello)
568	exception Type mismatch
569	code 80020005
570
571and:
572	variant_and(0, hello)
573	exception Type mismatch
574	code 80020005
575
576div:
577	variant_div(0, hello)
578	exception Type mismatch
579	code 80020005
580
581eqv:
582	variant_eqv(0, hello)
583	exception Type mismatch
584	code 80020005
585
586idiv:
587	variant_idiv(0, hello)
588	exception Type mismatch
589	code 80020005
590
591imp:
592	variant_imp(0, hello)
593	exception Type mismatch
594	code 80020005
595
596mod:
597	variant_mod(0, hello)
598	exception Type mismatch
599	code 80020005
600
601or:
602	variant_or(0, hello)
603	exception Type mismatch
604	code 80020005
605
606pow:
607	variant_pow(0, hello)
608	exception Type mismatch
609	code 80020005
610
611xor:
612	variant_xor(0, hello)
613	exception Type mismatch
614	code 80020005
615
616--
617add: 0
618cat: FalseFalse
619sub: 0
620mul: 0
621and: 0
622div:
623	variant_div(0, )
624	exception Out of present range
625	code 8002000a
626
627eqv: -1
628idiv:
629	variant_idiv(0, )
630	exception Division by zero
631	code 80020012
632
633imp: -1
634mod:
635	variant_mod(0, )
636	exception Division by zero
637	code 80020012
638
639or: 0
640pow: 1
641xor: 0
642OK!
643