Add a missing #include to the test program.
[kdbg.git] / kdbg / testprogs / testfile.cpp
blob847ad3e73cbe427cd2990c0155f144eb796550d9
1 #include <iostream>
2 #include <qstring.h>
3 #include <qfile.h>
4 #include <qfileinfo.h>
5 #include <qdir.h>
6 #include <math.h>
8 enum E { red, green, blue, yellow };
9 struct S { int x, y; S* s; };
11 struct emptyBase { };
12 struct emptyDerived : S { };
13 struct emptyNested : emptyBase { };
14 struct emptyVBase { virtual ~emptyVBase(){} };
15 struct emptyVDerived : S { virtual ~emptyVDerived(){} };
16 struct emptyVNested : emptyVBase { };
18 int globalvar = 1234;
20 class Cl
22 int k;
23 double l;
24 public:
25 Cl(int r);
26 virtual ~Cl();
27 virtual int f(int x);
30 typedef void (*PtrFunc)(E*, char);
32 class Dl : public Cl
34 public:
35 Dl(int r);
36 virtual int f(int x);
37 int operator()(const QString& x, int& y) const;
38 operator const char*() { return 0; }
39 operator PtrFunc*();
42 namespace A {
43 namespace {
44 namespace B {
45 namespace {
46 namespace {
47 void g()
49 S s1, s2;
50 s1.x = 85;
51 s2.y = 17;
52 s1.s = &s2;
53 s2.s = &s1;
55 } // namespace
56 void Banong() { g(); }
57 } // namespace
58 void g() { Banong(); }
59 } // namespace B
60 void Aanong() { B::g(); }
61 } // namespace
62 void g() { Aanong(); }
63 } // namespace A
65 void f(E e[3], char c)
67 E x = e[2];
68 S y[2];
69 E* pe = e;
70 E* pea[3] = { pe, };
72 int x = 17;
75 A::g();
76 char buffer[300];
77 memset(buffer, 1, 300);
78 for (int i = 0; i < sizeof(buffer); i +=15) buffer[i] = '\02';
79 QDir dir;
80 QFile file;
81 QFileInfo fi;
82 x = red;
83 emptyBase eb;
84 emptyDerived ed;
85 emptyNested en;
86 int ea[3];
87 emptyVBase evb;
88 emptyVDerived evd;
89 emptyVNested evn;
92 void strtest(const char* t)
94 const char* s = t;
95 const char*& s2 = s;
96 if (t == 0)
97 strtest(s2);
98 std::cout << s2 << std::endl;
101 template<typename F>
102 void templated_strtest(F f, const char* t)
104 f(t);
107 void segFault()
109 *(char*)0 = 's';
112 int main(int argc, char* argv[])
114 if (argc > 1) {
115 if (*argv[1] == 's') {
116 segFault();
117 } else if (*argv[1] == 'a') {
118 // let debugger attach
119 int junk;
120 std::cin >> junk;
124 char a[6] = { 'a', 'B', '\'', '\"' };
125 char a1[1] = { '1' };
126 E e[3] = { red, green, blue };
127 E e1[1] = { yellow };
129 a[0] = '5';
130 void (*pf[2])(E*, char) = {f};
132 double d[1] = { -1.234e123 };
133 int i = 10;
134 sin(i);
136 (*pf[0])(e, '\n');
138 QString s;
140 s = "Hi, there!\r\n\t\"\'\\";
142 const QString& strref = s;
144 templated_strtest(strtest, s);
145 s = "asbcxxxxxxxxxxxxxxxxxxxxxxxxxxx";
146 strtest(s);
147 s += "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii";
148 strtest(s);
149 s += "rst";
150 strtest(s);
151 s = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
152 strtest(s);
153 s += "rst";
154 strtest(s);
155 s = "";
157 Cl c1(13);
158 Dl d1(3214);
159 d1.f(17);
160 int n = 83;
161 d1(strref, n);
162 PtrFunc* ppf = d1;
165 Cl::Cl(int r) :
166 k(r),
167 l(sin(r))
169 std::cout << l << std::endl;
172 Cl::~Cl()
176 int Cl::f(int x)
178 int y = 2*x;
179 return y;
182 Dl::Dl(int r) :
183 Cl(r)
187 int Dl::f(int x)
189 int y = Cl::f(x);
190 return y+3;
193 int Dl::operator()(const QString& x, int& y) const
195 std::cerr << "ha! I know!" << std::endl;
196 return 1;
199 Dl::operator PtrFunc*()
201 return 0;