ReactOS 0.4.15-dev-7953-g1f49173
ihateeh.cxx
Go to the documentation of this file.
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for
3// full license information.
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#define FALSE 0
9#define TRUE 1
10#define NO_CTOR_THROW 1
11#define NO_DTOR_THROW 2
12
13#define TEST_DTOR
14
15#define MAX_OBJECTS 500
16
17#define NOEXCEPT(_x)
18
21int Fail;
22
23void FAIL(int i) {
24 printf("FAILED on %d\n", i);
25 Fail++;
26}
27
28void dealloc(int i, int no_throw) {
29 /* Make sure i is valid, and object exists */
30 if (i < 0 || i >= MaxObjectCount || !Object[i])
31 FAIL(i);
32
33 Object[i] = 0;
34
35/* Try throw in this dtor.. */
36#ifdef TEST_DTOR
37 if (i + MaxObjectCount == ThrowCount && !no_throw) {
38 printf("Throwing\n");
39 throw(1);
40 }
41#endif
42}
43
44void alloc(int i, int no_throw) {
47
48 /* Object already exists? */
49 if (Object[i])
50 FAIL(i);
51
52 /* Try throw in this ctor.. */
53 if (i == ThrowCount && !no_throw) {
54 printf("Throwing\n");
55 throw(1);
56 }
57
58 if (i >= MAX_OBJECTS) {
59 printf("\n*** Number of objects exceeded. Increase MAX_OBJECTS ***\n\n");
60 FAIL(i);
61 i = 0;
62 }
63
64 Object[i] = 1;
65}
66
67class B {
68public:
69 int i;
70 int flag;
71 B();
72 B(int);
74};
75
76B::B() {
78 printf("B ctor. i = %d\n", i);
79 alloc(i, FALSE);
80}
81
82B::B(int f) {
84 flag = f;
85 printf("B ctor. i = %d\n", i);
87}
88
90 printf("B dtor. i = %d\n", i);
92}
93
94class A {
95public:
96 int i;
97 A();
98 A(int) {
100 printf("A(int) ctor. i = %d\n", i);
101 alloc(i, FALSE);
102 }
104 A(const A &a) {
105 /* Try objects in ctor */
107
109 printf("A copy ctor. i = %d\n", i);
110 alloc(i, FALSE);
111 }
112
114 /* Try objects in dtor */
116
117 printf("A dtor. i = %d\n", i);
118 dealloc(i, FALSE);
119 };
120};
121
122A::A() {
124 printf("A ctor. i = %d\n", i);
125 alloc(i, FALSE);
126}
127
128A A::operator+(A a) {
129 printf("A%d + A%d\n", i, a.i);
130 return A();
131}
132
133A foo(A a1, A a2) { return a1 + a2; };
134
135int bar() {
136 A a;
137
138 return 666;
139}
140
141void foo2(int i, A a1, A a2, A a3) {
142 if (i != 666)
143 FAIL(666);
144 foo(a1, a3);
145}
146
148 puts("Try simple ctor");
149 A a1;
150
151 puts("Try question op ctor");
152 A a2 = (ThrowCount & 1) ? A() : ThrowCount;
153
154 puts("Try a more complex question op ctor");
155 A a3 = (ThrowCount & 1) ? A() + a1 + A() + a2 : a2 + A() + A() + ThrowCount;
156
157 puts("Try mbarg copy ctors, and return UDT");
158 A a4 = foo(a1, a2);
159
160 puts("Try a more complex mbarg copy ctors, and a function call");
161 foo2(bar(), a1 + a2, a2 + A() + a3 + a4, a3);
162
163 puts("Try temporary expressions, and return UDT");
164 return a1 + A() + a2 + A() + a3 + a4;
165}
166
167int main() {
168 int i;
169
170 /* Call test(), with a different ctor/dtor throwing each time */
171 for (ThrowCount = 0; ThrowCount < MaxObjectCount * 2; ThrowCount++) {
172 printf("ThrowCount = %d MaxObjectCount = %d\n", ThrowCount,
174
176
177 try {
178 test();
179 } catch (int) {
180 printf("In catch\n");
181 }
182
183 /* Any objects which didn't get dtor'd? */
184 for (i = 0; i < MaxObjectCount; i++) {
185 if (Object[i]) {
186 FAIL(i);
187 Object[i] = 0;
188 }
189 }
190
191 printf("\n");
192 }
193
194 printf("\n");
195 if (Fail)
196 printf("FAILED %d tests\n", Fail);
197 else
198 printf("Passed\n");
199}
Definition: ehthrow.cxx:93
~A() NOEXCEPT(false)
Definition: ihateeh.cxx:113
A(int)
Definition: ihateeh.cxx:98
A operator+(A a)
A()
A(const A &a)
Definition: ihateeh.cxx:104
Definition: ehthrow.cxx:54
B(int)
~B() NOEXCEPT(false)
B()
~B()
Definition: ehthrow.cxx:86
int puts(const char *string)
Definition: crtsupp.c:23
#define FALSE
Definition: types.h:117
#define A(row, col)
int main()
Definition: test.c:6
int Fail
Definition: ehthrow.cxx:24
void FAIL(int i)
Definition: ehthrow.cxx:27
void bar()
Definition: ehthrow.cxx:142
#define NO_DTOR_THROW
Definition: ehthrow.cxx:17
int MaxObjectCount
Definition: ehthrow.cxx:23
int CurrentObjectNumber
Definition: ehthrow.cxx:21
void dealloc(int i, int no_throw)
Definition: ehthrow.cxx:33
#define NO_CTOR_THROW
Definition: ehthrow.cxx:16
#define printf
Definition: freeldr.h:97
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int Fail
Definition: ihateeh.cxx:21
void FAIL(int i)
Definition: ihateeh.cxx:23
void foo2(int i, A a1, A a2, A a3)
Definition: ihateeh.cxx:141
int MaxObjectCount
Definition: ihateeh.cxx:20
int CurrentObjectNumber
Definition: ihateeh.cxx:20
#define NOEXCEPT(_x)
Definition: ihateeh.cxx:17
#define MAX_OBJECTS
Definition: ihateeh.cxx:15
void dealloc(int i, int no_throw)
Definition: ihateeh.cxx:28
int ThrowCount
Definition: ihateeh.cxx:20
#define f
Definition: ke_i.h:83
#define a
Definition: ke_i.h:78
static const struct update_accum a1
Definition: msg.c:578
static const struct update_accum a2
Definition: msg.c:586
static CRYPT_DATA_BLOB b2[]
Definition: msg.c:582
static CRYPT_DATA_BLOB b1[]
Definition: msg.c:573
static const struct update_accum a3
Definition: msg.c:600
static const struct update_accum a4
Definition: msg.c:2285
#define alloc
Definition: rosglue.h:13
#define test
Definition: rosglue.h:37
#define false
Definition: stdbool.h:37
Definition: ttei1.cpp:16
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object