]> git.buserror.net Git - polintos/scott/priv.git/blob - idlcomp/tests/cpp-vstruct.cc
Initial checkin from Perforce.
[polintos/scott/priv.git] / idlcomp / tests / cpp-vstruct.cc
1 #include <stdio.h>
2 #include <System.h>
3
4 using System::Exceptions::Exception;
5 using namespace System::Exceptions::Std;
6
7 System::VStruct *foo;
8
9 int main()
10 {
11         Exception *e, *e2;
12         SystemException *se, *se2;
13         
14         MemoryFault mf;
15         InstrFault inf;
16         ArchInstrFault aif;
17         
18         // Upcasts can be done directly.
19         se = &mf;
20         
21         // Downcast not needed, but should work anyway
22         e = Exception::downcast(&inf);
23         
24         MemoryFault *mf2 = MemoryFault::downcast(se),
25                     *mf3 = MemoryFault::downcast(e);
26         InstrFault *inf2 = InstrFault::downcast(se),
27                    *inf3 = InstrFault::downcast(e);
28         OutOfMemory *oom = OutOfMemory::downcast(e),
29                     *oom2 = OutOfMemory::downcast(&aif);
30         
31         e2 = Exception::downcast(&aif);
32         se2 = SystemException::downcast(foo);
33         
34         printf("Exception: %p %p (should be: ptr NULL)\n", e, e2);
35         printf("SystemException: %p %p (should be: ptr NULL)\n", se, se2);
36         printf("MemoryFault: %p %p (should be: ptr NULL)\n", mf2, mf3);
37         printf("InstrFault: %p %p (should be: NULL ptr)\n", inf2, inf3);
38         printf("OutOfMemory: %p %p (should be: NULL NULL)\n", oom, oom2);
39                 
40         return 0;
41 }