A better fix for anonymous name spaces, because they can be nested in other
[kdbg.git] / kdbg / testprogs / testfile.cpp
blob13bb53baf7a1c1def34c1fe2cf8026ba260fde8d
1 #include <iostream>
2 #include <qstring.h>
3 #include <qfile.h>
4 #include <qfileinfo.h>
5 #include <qdir.h>
7 enum E { red, green, blue, yellow };
8 struct S { int x, y; S* s; };
10 struct emptyBase { };
11 struct emptyDerived : S { };
12 struct emptyNested : emptyBase { };
13 struct emptyVBase { virtual ~emptyVBase(){} };
14 struct emptyVDerived : S { virtual ~emptyVDerived(){} };
15 struct emptyVNested : emptyVBase { };
17 int globalvar = 1234;
19 class Cl
21 int k;
22 double l;
23 public:
24 Cl(int r);
25 virtual ~Cl();
26 virtual int f(int x);
29 typedef void (*PtrFunc)(E*, char);
31 class Dl : public Cl
33 public:
34 Dl(int r);
35 virtual int f(int x);
36 int operator()(const QString& x, int& y) const;
37 operator const char*() { return 0; }
38 operator PtrFunc*();
41 namespace A {
42 namespace {
43 namespace B {
44 namespace {
45 namespace {
46 void g()
48 S s1, s2;
49 s1.x = 85;
50 s2.y = 17;
51 s1.s = &s2;
52 s2.s = &s1;
54 } // namespace
55 void Banong() { g(); }
56 } // namespace
57 void g() { Banong(); }
58 } // namespace B
59 void Aanong() { B::g(); }
60 } // namespace
61 void g() { Aanong(); }
62 } // namespace A
64 void f(E e[3], char c)
66 E x = e[2];
67 S y[2];
68 E* pe = e;
69 E* pea[3] = { pe, };
71 int x = 17;
74 A::g();
75 char buffer[300];
76 memset(buffer, 1, 300);
77 for (int i = 0; i < sizeof(buffer); i +=15) buffer[i] = '\02';
78 QDir dir;
79 QFile file;
80 QFileInfo fi;
81 x = red;
82 emptyBase eb;
83 emptyDerived ed;
84 emptyNested en;
85 int ea[3];
86 emptyVBase evb;
87 emptyVDerived evd;
88 emptyVNested evn;
91 void strtest(const char* t)
93 const char* s = t;
94 const char*& s2 = s;
95 if (t == 0)
96 strtest(s2);
97 std::cout << s2 << std::endl;
101 void segFault()
103 *(char*)0 = 's';
106 int main(int argc, char* argv[])
108 if (argc > 1) {
109 if (*argv[1] == 's') {
110 segFault();
111 } else if (*argv[1] == 'a') {
112 // let debugger attach
113 int junk;
114 std::cin >> junk;
118 char a[6] = { 'a', 'B', '\'', '\"' };
119 char a1[1] = { '1' };
120 E e[3] = { red, green, blue };
121 E e1[1] = { yellow };
123 a[0] = '5';
124 void (*pf[2])(E*, char) = {f};
126 double d[1] = { -1.234e123 };
127 int i = 10;
128 sin(i);
130 (*pf[0])(e, '\n');
132 QString s;
134 s = "Hi, there!\r\n\t\"\'\\";
136 const QString& strref = s;
138 strtest(s);
139 s = "asbcxxxxxxxxxxxxxxxxxxxxxxxxxxx";
140 strtest(s);
141 s += "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii";
142 strtest(s);
143 s += "rst";
144 strtest(s);
145 s = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
146 strtest(s);
147 s += "rst";
148 strtest(s);
149 s = "";
151 Cl c1(13);
152 Dl d1(3214);
153 d1.f(17);
154 int n = 83;
155 d1(strref, n);
156 PtrFunc* ppf = d1;
159 Cl::Cl(int r) :
160 k(r),
161 l(sin(r))
163 std::cout << l << std::endl;
166 Cl::~Cl()
170 int Cl::f(int x)
172 int y = 2*x;
173 return y;
176 Dl::Dl(int r) :
177 Cl(r)
181 int Dl::f(int x)
183 int y = Cl::f(x);
184 return y+3;
187 int Dl::operator()(const QString& x, int& y) const
189 std::cerr << "ha! I know!" << std::endl;
190 return 1;
193 Dl::operator PtrFunc*()
195 return 0;