If you're hacky enough, you can now call into auto-generated interfaces from
[wvapps.git] / xplcidl / ptrtest.cc
blob115337d4c90f934cc3b6f6ff590acf62108f880d
1 #include "xplc/ptr.h"
2 #include "xplc/utils.h"
3 #include <stdio.h>
4 #include <assert.h>
6 static int nobjs;
8 class MyObject : public IObject
10 IMPLEMENT_IOBJECT(MyObject);
11 public:
12 MyObject() { nobjs++; }
13 virtual ~MyObject() { nobjs--; }
17 UUID_MAP_BEGIN(MyObject)
18 UUID_MAP_ENTRY(IObject)
19 UUID_MAP_END;
22 int main()
25 IObject *a = new MyObject;
26 assert(nobjs == 1);
27 a->release();
28 assert(!nobjs);
32 xplc_ptr<IObject> a(new MyObject);
33 assert(nobjs == 1);
35 assert(!nobjs);
38 xplc_ptr<IObject> a(new MyObject);
39 assert(nobjs == 1);
40 a = 0;
41 assert(nobjs == 0);
45 xplc_ptr<IObject> a(new MyObject);
46 IObject *stupid = a->getInterface(IObject_IID);
47 a = 0;
48 assert(nobjs == 1);
49 stupid->release();
50 assert(!nobjs);
53 #if 1
55 xplc_ptr<IObject> a(new MyObject);
56 IObject *stupid = a->getInterface(IObject_IID);
57 a = 0;
58 assert(nobjs == 1);
59 a = stupid;
60 assert(nobjs == 1);
62 assert(!nobjs); // assertion fails
63 #endif
65 #if 1
67 xplc_ptr<IObject> a(new MyObject);
68 xplc_ptr<IObject> b;
69 b = a; // doesn't compile: "operator= is private"
70 assert(nobjs == 1);
72 assert(!nobjs);
73 #endif
75 #if 1
77 xplc_ptr<IObject> a(new MyObject);
78 xplc_ptr<IObject> b(a);
79 assert(nobjs == 1);
80 } // crashes
81 assert(!nobjs);
82 #endif
84 printf("all tests passed.\n");
85 return 0;