1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <iostream>
30 #include <list>
31 #include "abstract.h"
32 #include "derived.h"
33 #include "kindergarten.h"
34 #include "complex.h"
35 #include "point.h"
36 #include "size.h"
37 #include "listuser.h"
38 #include "samplenamespace.h"
39 
40 using namespace std;
41 
42 int
main(int argv,char ** argc)43 main(int argv, char **argc)
44 {
45     cout << endl;
46 
47     Derived derived;
48 
49     cout << endl;
50 
51     derived.unpureVirtual();
52     derived.pureVirtual();
53     derived.callPureVirtual();
54 
55     cout << endl;
56     Abstract* abs;
57     abs = Abstract::createObject();
58     cout << "Abstract::createObject(): " << abs << endl << endl;
59     delete abs;
60 
61     abs = Derived::createObject();
62     cout << "Derived::createObject() : ";
63     abs->show();
64     cout << endl;
65     delete abs;
66     cout << endl;
67 
68     abs = Derived::createObject();
69     cout << "Derived::createObject() : ";
70     abs->show();
71     cout << endl;
72     delete abs;
73     cout << endl;
74 
75     cout << endl << "-----------------------------------------" << endl;
76 
77     KinderGarten kg;
78     Derived* d[] = { 0, 0, 0 };
79 
80     for (int i = 0; i < 3; i++) {
81         d[i] = new Derived(i);
82         d[i]->show();
83         cout << endl;
84         kg.addChild(d[i]);
85     }
86 
87     kg.show();
88     cout << endl;
89 
90     cout << endl << "* kill child ";
91     d[2]->show();
92     cout << " ----------------" << endl;
93     kg.killChild(d[2]);
94     kg.show();
95     cout << endl;
96 
97     cout << endl << "* release child ";
98     d[1]->show();
99     cout << " -------------" << endl;
100     Abstract* released = kg.releaseChild(d[1]);
101     cout << "released: ";
102     released->show();
103     cout << endl;
104     kg.show();
105     cout << endl;
106 
107     cout << endl << "* kill children ------------------------------------" << endl;
108     kg.killChildren();
109     kg.show();
110     cout << endl << endl;
111 
112     cout << "-----------------------------------------" << endl;
113     ListUser lu;
114     cout << "ListUser::createList()" << endl;
115     std::list<int> intlist = lu.createList();
116     for (std::list<int>::iterator it = intlist.begin(); it != intlist.end(); it++) {
117         cout << "* " << *it << endl;
118     }
119 
120     cout << "ListUser::createComplexList" << endl;
121     std::list<Complex> cpxlist = ListUser::createComplexList(Complex(1.1, 2.2), Complex(3.3, 4.4));
122     for (std::list<Complex>::iterator it = cpxlist.begin(); it != cpxlist.end(); it++) {
123         cout << "* ";
124         (*it).show();
125         cout << endl;
126     }
127     cout << endl;
128 
129     cout << "-----------------------------------------" << endl;
130     cout << "SampleNamespace" << endl;
131 
132     cout << "SampleNamespace::RandomNumber: ";
133     cout << SampleNamespace::getNumber(SampleNamespace::RandomNumber);
134     cout << endl;
135     cout << "SampleNamespace::UnixTime: ";
136     cout << SampleNamespace::getNumber(SampleNamespace::UnixTime);
137     cout << endl;
138     double val_d = 1.3;
139     cout << "SampleNamespace::powerOfTwo(" << val_d << "): ";
140     cout << SampleNamespace::powerOfTwo(val_d) << endl;
141     int val_i = 7;
142     cout << "SampleNamespace::powerOfTwo(" << val_i << "): ";
143     cout << SampleNamespace::powerOfTwo(val_i) << endl;
144     cout << endl;
145 
146     cout << "-----------------------------------------" << endl;
147     cout << "Point" << endl;
148 
149     Point p1(1.1, 2.2);
150     cout << "p1: ";
151     p1.show();
152     cout << endl;
153 
154     Point p2(3.4, 5.6);
155     cout << "p2: ";
156     p2.show();
157     cout << endl;
158 
159     cout << "p1 + p2 == ";
160     (p1 + p2).show();
161     cout << endl;
162 
163     cout << "p1 * 2.0 == ";
164     (p1 * 2.0).show();
165     cout << endl;
166 
167     cout << "1.5 * p2 == ";
168     (1.5 * p2).show();
169     cout << endl;
170 
171     cout << "p1: ";
172     p1.show();
173     cout << endl << "p2: ";
174     p2.show();
175     cout << endl << "p1 += p2" << endl;
176     p1 += p2;
177     cout << "p1: ";
178     p1.show();
179     cout << endl;
180 
181     cout << "p1 == p2 ? " << ((p1 == p2) ? "true" : "false") << endl;
182     cout << "p1 == p1 ? " << ((p1 == p1) ? "true" : "false") << endl;
183     cout << "p2 == p2 ? " << ((p2 == p2) ? "true" : "false") << endl;
184 
185     cout << "-----------------------------------------" << endl;
186     cout << "Size" << endl;
187 
188     Size s1(2, 2);
189     cout << "s1: ";
190     s1.show();
191     cout << ", area: " << s1.calculateArea();
192     cout << endl;
193 
194     Size s2(3, 5);
195     cout << "s2: ";
196     s2.show();
197     cout << ", area: " << s2.calculateArea();
198     cout << endl;
199 
200     cout << endl;
201 
202     cout << "s1 == s2 ? " << ((s1 == s2) ? "true" : "false") << endl;
203     cout << "s1 != s2 ? " << ((s1 != s2) ? "true" : "false") << endl;
204 
205     cout << "s1 <  s2 ? " << ((s1 <  s2) ? "true" : "false") << endl;
206     cout << "s1 <= s2 ? " << ((s1 <= s2) ? "true" : "false") << endl;
207     cout << "s1 >  s2 ? " << ((s1 >  s2) ? "true" : "false") << endl;
208     cout << "s1 >= s2 ? " << ((s1 >= s2) ? "true" : "false") << endl;
209 
210     cout << "s1 <  10 ? " << ((s1 <  10) ? "true" : "false") << endl;
211     cout << "s1 <= 10 ? " << ((s1 <= 10) ? "true" : "false") << endl;
212     cout << "s1 >  10 ? " << ((s1 >  10) ? "true" : "false") << endl;
213     cout << "s1 >= 10 ? " << ((s1 >= 10) ? "true" : "false") << endl;
214     cout << "s2 <  10 ? " << ((s2 <  10) ? "true" : "false") << endl;
215     cout << "s2 <= 10 ? " << ((s2 <= 10) ? "true" : "false") << endl;
216     cout << "s2 >  10 ? " << ((s2 >  10) ? "true" : "false") << endl;
217     cout << "s2 >= 10 ? " << ((s2 >= 10) ? "true" : "false") << endl;
218     cout << endl;
219 
220     cout << "s1: ";
221     s1.show();
222     cout << endl << "s2: ";
223     s2.show();
224     cout << endl << "s1 += s2" << endl;
225     s1 += s2;
226     cout << "s1: ";
227     s1.show();
228     cout << endl;
229 
230     cout << endl;
231 
232     cout << "s1: ";
233     s1.show();
234     cout << endl << "s1 *= 2.0" << endl;
235     s1 *= 2.0;
236     cout << "s1: ";
237     s1.show();
238     cout << endl;
239 
240     cout << endl;
241 
242     return 0;
243 }
244 
245