-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest-ctypes2.cpp
More file actions
161 lines (129 loc) · 2.78 KB
/
test-ctypes2.cpp
File metadata and controls
161 lines (129 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Tests on structures, classes, and hierarchy
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
extern "C" {
#include <dlfcn.h>
}
#ifdef PYTHON_BUILD
#endif
// structs
struct sA {
int a;
};
struct sB : sA {
unsigned int b;
};
struct sC : sB {
private:
unsigned int c;
};
struct sD : sB {
public:
unsigned int d;
};
// classes
class cA {
public:
int a;
//cA() : a(0x1){ };
cA(int _a=0x1) : a(_a){ };
};
class cB : cA {
public:
unsigned int b;
cB(int _b=0x22) : b(_b) { cA(0x2);};
};
class cC : cB {
public:
unsigned int c;
cC(int _c=0x333) : c(_c) {cB(0x3);};
};
class cD : cB {
public:
unsigned int d;
cD(int _d=0x4) : d(_d) {cB(0x4);};
};
class cE : cD, cC {
public:
unsigned int e;
cE() : e(0x5) {cD(0x5);};
};
int test_classes()
{
std::cout << " -- classes --" << std::endl;
cA * a = new cA();
cB * b = new cB();
cC * c = new cC();
cD * d = new cD();
cE * e = new cE();
//a->a = 0x01 ;
//b->a = 0x02;
//b->b = 0x22;
//c->a = 0x03;
//c->b = 0x33;
//c->c = 0x0333;
printf(" a is at %p size: %zu \n", a, sizeof(cA));
printf(" b is at %p size: %zu \n", b, sizeof(cB));
printf(" c is at %p size: %zu \n", c, sizeof(cC));
printf(" d is at %p size: %zu \n", d, sizeof(cD));
printf(" e is at %p size: %zu \n", e, sizeof(cE));
std::cout << " -- end classes --" << std::endl;
return 0;
}
int test_structs()
{
std::cout << " -- structs --" << std::endl;
sA * a = (sA * ) malloc(sizeof(sA));
sB * b = (sB * ) malloc(sizeof(sB));
sC * c = (sC * ) malloc(sizeof(sC));
sD * d = (sD * ) malloc(sizeof(sD));
printf(" a is at %p size: %zu \n", a, sizeof(sA));
printf(" b is at %p size: %zu \n", b, sizeof(sB));
printf(" c is at %p size: %zu \n", c, sizeof(sC));
printf(" d is at %p size: %zu \n", d, sizeof(sD));
std::cout << " -- end structs --" << std::endl;
return 0;
}
int main(){
int a;
void *handle;
printf("START\n");
fflush(stdout);
test_structs();
test_classes();
a = getchar();
handle = dlopen ("libQtCore.so", RTLD_NOW|RTLD_GLOBAL);
printf("OPEN libQtCore.so\n");
fflush(stdout);
if (handle == NULL){
fprintf (stderr, "cannot load: lib.so\n");
return -1;
}
//test_structs();
//test_classes();
a = getchar();
handle = dlopen ("libQtSvg.so", RTLD_NOW|RTLD_GLOBAL);
printf("OPEN libQtSvg.so\n");
fflush(stdout);
if (handle == NULL){
fprintf (stderr, "cannot load: lib.so\n");
return -1;
}
//test_structs();
//test_classes();
a = getchar();
handle = dlopen ("libQtGui.so", RTLD_NOW|RTLD_GLOBAL);
printf("OPEN libQtGui.so\n");
fflush(stdout);
if (handle == NULL){
fprintf (stderr, "cannot load: lib.so\n");
return -1;
}
a = getchar();
printf("END\n");
fflush(stdout);
return 0;
}