VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTAssertCompile.cpp@ 30250

Last change on this file since 30250 was 30250, checked in by vboxsync, 14 years ago

tstRTAssertCompile.cpp: Postpone array problem on MSC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: tstRTAssertCompile.cpp 30250 2010-06-16 13:33:49Z vboxsync $ */
2/** @file
3 * IPRT Testcase - AssertCompile* - A Compile Time Testcase.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/assert.h>
32
33
34int main(int argc, char **argv)
35{
36 /* Only positive tests here. */
37
38 AssertCompile(true);
39 AssertCompile(1);
40 AssertCompile(2);
41 AssertCompile(99);
42
43 uint8_t u8; NOREF( u8);
44 uint16_t u16; NOREF(u16);
45 uint32_t u32; NOREF(u32);
46 uint64_t u64; NOREF(u64);
47 AssertCompileSize( u8, 1);
48 AssertCompileSize(u16, 2);
49 AssertCompileSize(u32, 4);
50 AssertCompileSize(u64, 8);
51
52 AssertCompileSizeAlignment( u8, 1);
53 AssertCompileSizeAlignment(u16, 1);
54 AssertCompileSizeAlignment(u16, 2);
55 AssertCompileSizeAlignment(u32, 1);
56 AssertCompileSizeAlignment(u32, 2);
57 AssertCompileSizeAlignment(u32, 4);
58 AssertCompileSizeAlignment(u64, 1);
59 AssertCompileSizeAlignment(u64, 2);
60 AssertCompileSizeAlignment(u64, 4);
61 AssertCompileSizeAlignment(u64, 8);
62
63 typedef struct STRUCT1
64 {
65 uint8_t u8;
66 uint8_t au8[8];
67 uint64_t u64;
68 uint8_t u8UnalignmentFiller1;
69 uint32_t u32;
70 uint8_t u8UnalignmentFiller2;
71 uint16_t u16;
72 const char *psz;
73 uint32_t u32A;
74 uint32_t u32B;
75 } STRUCT1, STRUCT2;
76
77 AssertCompileMemberSize(STRUCT1, u8, 1);
78 AssertCompileMemberSize(STRUCT1, u16, 2);
79 AssertCompileMemberSize(STRUCT1, u32, 4);
80 AssertCompileMemberSize(STRUCT1, u64, 8);
81
82 AssertCompileMemberSizeAlignment(STRUCT1, u8, 1);
83 AssertCompileMemberSizeAlignment(STRUCT1, u16, 1);
84 AssertCompileMemberSizeAlignment(STRUCT1, u16, 2);
85 AssertCompileMemberSizeAlignment(STRUCT1, u32, 1);
86 AssertCompileMemberSizeAlignment(STRUCT1, u32, 2);
87 AssertCompileMemberSizeAlignment(STRUCT1, u32, 4);
88 AssertCompileMemberSizeAlignment(STRUCT1, u64, 1);
89 AssertCompileMemberSizeAlignment(STRUCT1, u64, 2);
90 AssertCompileMemberSizeAlignment(STRUCT1, u64, 4);
91 AssertCompileMemberSizeAlignment(STRUCT1, u64, 8);
92 AssertCompileMemberSizeAlignment(STRUCT1, psz, sizeof(void *));
93
94 AssertCompileMemberAlignment(STRUCT1, u8, 1);
95 AssertCompileMemberAlignment(STRUCT1, u16, 1);
96 AssertCompileMemberAlignment(STRUCT1, u16, 2);
97 AssertCompileMemberAlignment(STRUCT1, u32, 1);
98 AssertCompileMemberAlignment(STRUCT1, u32, 2);
99 AssertCompileMemberAlignment(STRUCT1, u32, 4);
100 AssertCompileMemberAlignment(STRUCT1, u64, 1);
101 AssertCompileMemberAlignment(STRUCT1, u64, 2);
102 AssertCompileMemberAlignment(STRUCT1, u64, 4);
103#if defined(__GNUC__) && ARCH_BITS >= 64
104 AssertCompileMemberAlignment(STRUCT1, u64, 8);
105#endif
106 AssertCompileMemberAlignment(STRUCT1, psz, sizeof(void *));
107
108 AssertCompileMemberOffset(STRUCT1, u8, 0);
109 AssertCompileMemberOffset(STRUCT1, au8, 1);
110#ifndef _MSC_VER /** @todo figure out why MSC has trouble with these expressions */
111 AssertCompileMemberOffset(STRUCT1, au8[0], 1);
112 AssertCompileMemberOffset(STRUCT1, au8[8], 9);
113#endif
114
115 typedef union UNION1
116 {
117 STRUCT1 s1;
118 STRUCT2 s2;
119 } UNION1;
120
121 AssertCompile2MemberOffsets(UNION1, s1.u8, s2.u8);
122 AssertCompile2MemberOffsets(UNION1, s1.u16, s2.u16);
123 AssertCompile2MemberOffsets(UNION1, s1.u32, s2.u32);
124 AssertCompile2MemberOffsets(UNION1, s1.u64, s2.u64);
125 AssertCompile2MemberOffsets(UNION1, s1.psz, s2.psz);
126
127 AssertCompileAdjacentMembers(STRUCT1, u32A, u32B);
128 AssertCompileAdjacentMembers(STRUCT1, u8, au8);
129#ifndef _MSC_VER /** @todo figure out why MSC has trouble with these expressions */
130 AssertCompileAdjacentMembers(STRUCT1, u8, au8[0]);
131 AssertCompileAdjacentMembers(STRUCT1, au8[0], au8[1]);
132#endif
133
134 AssertCompileMembersAtSameOffset(STRUCT1, u8, STRUCT2, u8);
135 AssertCompileMembersAtSameOffset(STRUCT1, au8, STRUCT2, au8);
136 AssertCompileMembersAtSameOffset(STRUCT1, u16, STRUCT2, u16);
137 AssertCompileMembersAtSameOffset(STRUCT1, u32, STRUCT2, u32);
138 AssertCompileMembersAtSameOffset(STRUCT1, u64, STRUCT2, u64);
139
140 AssertCompileMembersSameSize(STRUCT1, u8, STRUCT2, u8);
141 AssertCompileMembersSameSize(STRUCT1, au8, STRUCT2, au8);
142 AssertCompileMembersSameSize(STRUCT1, u16, STRUCT2, u16);
143 AssertCompileMembersSameSize(STRUCT1, u32, STRUCT2, u32);
144 AssertCompileMembersSameSize(STRUCT1, u64, STRUCT2, u64);
145
146 AssertCompileMembersSameSizeAndOffset(STRUCT1, u8, STRUCT2, u8);
147 AssertCompileMembersSameSizeAndOffset(STRUCT1, au8, STRUCT2, au8);
148 AssertCompileMembersSameSizeAndOffset(STRUCT1, u16, STRUCT2, u16);
149 AssertCompileMembersSameSizeAndOffset(STRUCT1, u32, STRUCT2, u32);
150 AssertCompileMembersSameSizeAndOffset(STRUCT1, u64, STRUCT2, u64);
151
152 return 0;
153}
154
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette