tdf#132853 - UI: fix different sizes in Image tabs Type & Crop
[LibreOffice.git] / cppu / source / uno / check.cxx
blob561434aa55f357054b1dd7ffacc6e0f7ffd3cebf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include <cppu/macros.hxx>
25 #include <rtl/ustring.hxx>
26 #include <sal/types.h>
27 #include <uno/any2.h>
30 namespace {
32 #if defined( _WIN32)
33 #pragma pack(push, 8)
34 #endif
36 struct C1
38 sal_Int16 n1;
40 struct C2 : public C1
42 sal_Int32 n2 CPPU_GCC3_ALIGN( C1 );
44 struct C3 : public C2
46 double d3;
47 sal_Int32 n3;
49 struct C4 : public C3
51 sal_Int32 n4 CPPU_GCC3_ALIGN( C3 );
52 double d4;
54 struct C5 : public C4
56 sal_Int64 n5;
57 sal_Bool b5;
59 struct C6 : public C1
61 C5 c6 CPPU_GCC3_ALIGN( C1 );
62 sal_Bool b6;
65 struct D
67 sal_Int16 d;
68 sal_Int32 e;
70 struct E
72 // [-loplugin:fakebool] false positive:
73 sal_Bool a;
74 // [-loplugin:fakebool] false positive:
75 sal_Bool b;
76 // [-loplugin:fakebool] false positive:
77 sal_Bool c;
78 sal_Int16 d;
79 sal_Int32 e;
82 struct M
84 sal_Int32 n;
85 sal_Int16 o;
88 struct N : public M
90 sal_Int16 p CPPU_GCC3_ALIGN( M );
92 struct N2
94 M m;
95 sal_Int16 p;
98 struct O : public M
100 double p;
101 sal_Int16 q;
103 struct O2 : public O
105 sal_Int16 p2 CPPU_GCC3_ALIGN( O );
108 struct P : public N
110 double p2;
113 struct empty
116 struct second : public empty
118 int a;
121 struct AlignSize_Impl
123 sal_Int16 nInt16;
124 double dDouble;
127 struct Char1
129 char c1;
131 struct Char2 : public Char1
133 char c2 CPPU_GCC3_ALIGN( Char1 );
135 struct Char3 : public Char2
137 char c3 CPPU_GCC3_ALIGN( Char2 );
139 enum Enum
141 v = SAL_MAX_ENUM
144 #ifdef _WIN32
145 # pragma pack(pop)
146 #endif
148 // [-loplugin:fakebool] false positive:
149 static_assert( static_cast<sal_Bool>(true) == sal_True,
150 "must be binary compatible" );
151 // [-loplugin:fakebool] false positive:
152 static_assert( static_cast<sal_Bool>(false) == sal_False,
153 "must be binary compatible" );
154 #if SAL_TYPES_ALIGNMENT8 == 2
155 static_assert(offsetof(AlignSize_Impl, dDouble) == 2, "offsetof(AlignSize_Impl, dDouble) != 2");
156 static_assert(sizeof(AlignSize_Impl) == 10, "sizeof(AlignSize_Impl) != 10");
157 #elif SAL_TYPES_ALIGNMENT8 == 4
158 static_assert(offsetof(AlignSize_Impl, dDouble) == 4, "offsetof(AlignSize_Impl, dDouble) != 4");
159 static_assert(sizeof(AlignSize_Impl) == 12, "sizeof(AlignSize_Impl) != 12");
160 #elif SAL_TYPES_ALIGNMENT8 == 8
161 static_assert(offsetof(AlignSize_Impl, dDouble) == 8, "offsetof(AlignSize_Impl, dDouble) != 8");
162 static_assert(sizeof(AlignSize_Impl) == 16, "sizeof(AlignSize_Impl) != 16");
163 #else
164 # error unexpected alignment of 8 byte types
165 #endif
167 // sequence
168 static_assert((SAL_SEQUENCE_HEADER_SIZE % 8) == 0, "binary compatibility test failed: (SAL_SEQUENCE_HEADER_SIZE % 8) == 0!!!");
169 // enum
170 static_assert(sizeof(Enum) == sizeof(sal_Int32), "binary compatibility test failed: (sizeof(Enum) == sizeof(sal_Int32))");
171 // any
172 static_assert(sizeof(void *) >= sizeof(sal_Int32), "binary compatibility test failed: (sizeof(void *) >= sizeof(sal_Int32))");
173 static_assert(sizeof(uno_Any) == sizeof(void *) * 3, "binary compatibility test failed: (sizeof(uno_Any) == sizeof(void *) * 3");
174 static_assert(offsetof(uno_Any, pType) == 0, "offsetof(uno_Any, pType) != 0");
175 static_assert(offsetof(uno_Any, pData) == 1 * sizeof(void *), "offsetof(uno_Any, pTData) != (1 * sizeof(void *))");
176 static_assert(offsetof(uno_Any, pReserved) == 2 * sizeof(void *), "offsetof(uno_Any, pReserved) != (2 * sizeof(void *))");
177 // string
178 static_assert(sizeof(OUString) == sizeof(rtl_uString *), "binary compatibility test failed: sizeof(OUString) != sizeof(rtl_uString *)");
179 // struct
180 #if SAL_TYPES_ALIGNMENT8 == 2
181 static_assert(sizeof(M) == 6, "sizeof(M) != 6");
182 static_assert(sizeof(N) == 8, "sizeof(N) != 8");
183 static_assert(sizeof(N2) == 8, "sizeof(N2) != 8");
184 static_assert(offsetof(N2, p) == 6, "offsetof(N2, p) != 6");
185 #else
186 static_assert(sizeof(M) == 8, "sizeof(M) != 8");
187 static_assert(sizeof(N) == 12, "sizeof(N) != 12");
188 static_assert(sizeof(N2) == 12, "sizeof(N2) != 12");
189 static_assert(offsetof(N2, p) == 8, "offsetof(N2, p) != 8");
190 #endif
191 static_assert(offsetof(M, o) == 4, "offsetof(M, o) != 4");
193 #if SAL_TYPES_ALIGNMENT8 == 2
194 static_assert(sizeof(O) == 16, "sizeof(O) != 16");
195 #elif SAL_TYPES_ALIGNMENT8 == 4
196 static_assert(sizeof(O) == 20, "sizeof(O) != 20");
197 #elif SAL_TYPES_ALIGNMENT8 == 8
198 static_assert(sizeof(O) == 24, "sizeof(O) != 24");
199 #else
200 # error unexpected alignment of 8 byte types
201 #endif
203 #if SAL_TYPES_ALIGNMENT8 == 2
204 static_assert(sizeof(C2) == 6, "sizeof(C2) != 6");
205 static_assert(sizeof(D) == 6, "sizeof(D) != 6");
206 static_assert(offsetof(D, e) == 2, "offsetof(D, e) != 2");
207 static_assert(offsetof(E, e) == 6, "offsetof(E, e) != 6");
208 #else
209 static_assert(sizeof(C2) == 8, "sizeof(C2) != 8");
210 static_assert(sizeof(D) == 8, "sizeof(D) != 8");
211 static_assert(offsetof(D, e) == 4, "offsetof(D, e) != 4");
212 static_assert(offsetof(E, e) == 8, "offsetof(E, e) != 8");
213 #endif
215 static_assert(sizeof(C1) == 2, "sizeof(C1) != 2");
216 static_assert(offsetof(E, d) == 4, "offsetof(E, d) != 4");
218 #if SAL_TYPES_ALIGNMENT8 == 2
219 static_assert(sizeof(C3) == 18, "sizeof(C3) != 18");
220 static_assert(sizeof(C4) == 30, "sizeof(C4) != 30");
221 static_assert(sizeof(C5) == 40, "sizeof(C5) != 40");
222 static_assert(sizeof(C6) == 44, "sizeof(C6) != 44");
224 static_assert(sizeof(O2) == 18, "sizeof(O2) != 18");
225 #elif SAL_TYPES_ALIGNMENT8 == 4
226 static_assert(sizeof(C3) == 20, "sizeof(C3) != 20");
227 static_assert(sizeof(C4) == 32, "sizeof(C4) != 32");
228 static_assert(sizeof(C5) == 44, "sizeof(C5) != 44");
229 static_assert(sizeof(C6) == 52, "sizeof(C6) != 52");
231 static_assert(sizeof(O2) == 24, "sizeof(O2) != 24");
232 #elif SAL_TYPES_ALIGNMENT8 == 8
233 static_assert(sizeof(C3) == 24, "sizeof(C3) != 24");
234 static_assert(sizeof(C4) == 40, "sizeof(C4) != 40");
235 static_assert(sizeof(C5) == 56, "sizeof(C5) != 56");
236 static_assert(sizeof(C6) == 72, "sizeof(C6) != 72");
238 static_assert(sizeof(O2) == 32, "sizeof(O2) != 32");
239 #else
240 # error unexpected alignment of 8 byte types
241 #endif
243 static_assert(sizeof(Char3) == 3, "sizeof(Char3) != 3");
245 #if SAL_TYPES_ALIGNMENT8 == 2
246 // max alignment is 2
247 static_assert(sizeof(P) == 16, "sizeof(P) != 16");
248 #elif SAL_TYPES_ALIGNMENT8 == 4
249 // max alignment is 4
250 static_assert(sizeof(P) == 20, "sizeof(P) != 20");
251 #elif SAL_TYPES_ALIGNMENT8 == 8
252 // alignment of P is 8, because of P[] ...
253 static_assert(sizeof(P) == 24, "sizeof(P) != 24");
254 static_assert(sizeof(second) == sizeof(int), "sizeof(second) != sizeof(int)");
255 #else
256 # error unexpected alignment of 8 byte types
257 #endif
259 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
261 struct Char4
263 #if defined __GNUC__ && (__GNUC__ < 12 || (__GNUC__ == 12 && __GNUC_MINOR__ < 1)) && !defined __clang__
264 #pragma GCC diagnostic push
265 #pragma GCC diagnostic ignored "-Wattributes"
266 #endif
267 [[maybe_unused]] Char3 chars;
268 #if defined __GNUC__ && (__GNUC__ < 12 || (__GNUC__ == 12 && __GNUC_MINOR__ < 1)) && !defined __clang__
269 #pragma GCC diagnostic pop
270 #endif
271 char c;
274 template<typename T1, typename T2> std::size_t OFFSET_OF(T2 T1::* p) {
275 return reinterpret_cast< size_t >(reinterpret_cast<char *>(&(reinterpret_cast<T1 *>(16)->*p)) -16);
278 class BinaryCompatible_Impl
280 public:
281 BinaryCompatible_Impl();
283 BinaryCompatible_Impl::BinaryCompatible_Impl()
285 assert(OFFSET_OF(&N::p) == 8);
287 assert(OFFSET_OF(&C2::n2) == 4);
289 #if SAL_TYPES_ALIGNMENT8 == 2
290 assert(OFFSET_OF(&C3::d3) == 6);
291 assert(OFFSET_OF(&C3::n3) == 14);
292 assert(OFFSET_OF(&C4::n4) == 18);
293 assert(OFFSET_OF(&C4::d4) == 22);
294 assert(OFFSET_OF(&C5::n5) == 30);
295 assert(OFFSET_OF(&C5::b5) == 38);
296 assert(OFFSET_OF(&C6::c6) == 2);
297 assert(OFFSET_OF(&C6::b6) == 42);
299 assert(OFFSET_OF(&O2::p2) == 16);
300 #elif SAL_TYPES_ALIGNMENT8 == 4
301 assert(OFFSET_OF(&C3::d3) == 8);
302 assert(OFFSET_OF(&C3::n3) == 16);
303 assert(OFFSET_OF(&C4::n4) == 20);
304 assert(OFFSET_OF(&C4::d4) == 24);
305 assert(OFFSET_OF(&C5::n5) == 32);
306 assert(OFFSET_OF(&C5::b5) == 40);
307 assert(OFFSET_OF(&C6::c6) == 4);
308 assert(OFFSET_OF(&C6::b6) == 48);
310 assert(OFFSET_OF(&O2::p2) == 20);
311 #elif SAL_TYPES_ALIGNMENT8 == 8
312 assert(OFFSET_OF(&C3::d3) == 8);
313 assert(OFFSET_OF(&C3::n3) == 16);
314 assert(OFFSET_OF(&C4::n4) == 24);
315 assert(OFFSET_OF(&C4::d4) == 32);
316 assert(OFFSET_OF(&C5::n5) == 40);
317 assert(OFFSET_OF(&C5::b5) == 48);
318 assert(OFFSET_OF(&C6::c6) == 8);
319 assert(OFFSET_OF(&C6::b6) == 64);
321 assert(OFFSET_OF(&O2::p2) == 24);
322 #else
323 # error unexpected alignment of 8 byte types
324 #endif
326 assert(OFFSET_OF(&Char4::c) == 3);
329 BinaryCompatible_Impl aTest;
331 #endif
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */