~ubuntu-branches/ubuntu/hardy/uim/hardy

« back to all changes in this revision

Viewing changes to sigscheme/test-c/test-alignment-coll.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2007-04-21 03:46:09 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070421034609-gpcurkutp8vaysqj
Tags: 1:1.4.1-3
* Switch to dh_gtkmodules for the gtk 2.10 transition (Closes:
  #419318)
  - debian/control: Add ${misc:Depends} and remove libgtk2.0-bin on
    uim-gtk2.0.
  - debian/uim-gtk2.0.post{inst,rm}: Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#line 1 "test-alignment.c"
 
2
/*===========================================================================
 
3
 *  Filename : test-alignment.c
 
4
 *  About    : unit test for alignment on stack
 
5
 *
 
6
 *  Copyright (C) 2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
 
7
 *  Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
 
8
 *
 
9
 *  All rights reserved.
 
10
 *
 
11
 *  Redistribution and use in source and binary forms, with or without
 
12
 *  modification, are permitted provided that the following conditions
 
13
 *  are met:
 
14
 *
 
15
 *  1. Redistributions of source code must retain the above copyright
 
16
 *     notice, this list of conditions and the following disclaimer.
 
17
 *  2. Redistributions in binary form must reproduce the above copyright
 
18
 *     notice, this list of conditions and the following disclaimer in the
 
19
 *     documentation and/or other materials provided with the distribution.
 
20
 *  3. Neither the name of authors nor the names of its contributors
 
21
 *     may be used to endorse or promote products derived from this software
 
22
 *     without specific prior written permission.
 
23
 *
 
24
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 
25
 *  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 
26
 *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
27
 *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
 
28
 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
29
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
30
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
31
 *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
32
 *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
33
 *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
34
 *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
35
===========================================================================*/
 
36
 
 
37
#include "sscm-test.h"
 
38
 
 
39
#define MSG(offs, exp) ("offset " #offs ": " #exp)
 
40
 
 
41
#define TEST_ALIGNMENT(od, offs)                                             \
 
42
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.i % ALIGNOF_INT,                 \
 
43
                MSG(offs, int));                                             \
 
44
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.l % ALIGNOF_LONG,                \
 
45
                MSG(offs, long));                                            \
 
46
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.p % ALIGNOF_VOID_P,              \
 
47
                MSG(offs, void *));                                          \
 
48
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.cp.p % ALIGNOF_VOID_P,           \
 
49
                MSG(offs, {char; void *p;}.p));                              \
 
50
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.sp.p % ALIGNOF_VOID_P,           \
 
51
                MSG(offs, {short; void *p;}.p));                             \
 
52
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c3p.p % ALIGNOF_VOID_P,          \
 
53
                MSG(offs, {char[3]; void *p;}.p));                           \
 
54
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.ip.p % ALIGNOF_VOID_P,           \
 
55
                MSG(offs, {int; void *p;}.p));                               \
 
56
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c5p.p % ALIGNOF_VOID_P,          \
 
57
                MSG(offs, {char[5]; void *p;}.p));                           \
 
58
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.lp.p % ALIGNOF_VOID_P,           \
 
59
                MSG(offs, {long; void *p;}.p));                              \
 
60
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.qp.p % ALIGNOF_VOID_P,           \
 
61
                MSG(offs, {int64_t; void *p;}.p));                           \
 
62
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.i32p.p % ALIGNOF_VOID_P,         \
 
63
                MSG(offs, {int32_t; void *p;}.p));                           \
 
64
    TST_EQ_UINT(0, (uintptr_t)&od.o##offs.d.c9p.p % ALIGNOF_VOID_P,          \
 
65
                MSG(offs, {char[9]; void *p;}.p))
 
66
 
 
67
 
 
68
union data {
 
69
    short s;
 
70
    int i;
 
71
    long l;
 
72
    int64_t q;
 
73
    void *p;
 
74
 
 
75
    struct {
 
76
        char c;
 
77
        void *p;
 
78
    } cp;
 
79
 
 
80
    struct {
 
81
        short s;
 
82
        void *p;
 
83
    } sp;
 
84
 
 
85
    struct {
 
86
        char c[3];
 
87
        void *p;
 
88
    } c3p;
 
89
 
 
90
    struct {
 
91
        int i;
 
92
        void *p;
 
93
    } ip;
 
94
 
 
95
    struct {
 
96
        char c[5];
 
97
        void *p;
 
98
    } c5p;
 
99
 
 
100
    struct {
 
101
        long l;
 
102
        void *p;
 
103
    } lp;
 
104
 
 
105
    /* for LLP64 pointer alignment check */
 
106
    struct {
 
107
        int64_t q;
 
108
        void *p;
 
109
    } qp;
 
110
 
 
111
    /* for LP64 pointer alignment check */
 
112
    struct {
 
113
        int32_t i;
 
114
        void *p;
 
115
    } i32p;
 
116
 
 
117
    struct {
 
118
        char c[9];
 
119
        void *p;
 
120
    } c9p;
 
121
};
 
122
 
 
123
union offsettable_data {
 
124
    struct {
 
125
        union data d;
 
126
    } o0;
 
127
 
 
128
    struct {
 
129
        char offset[1];
 
130
        union data d;
 
131
    } o1;
 
132
 
 
133
    struct {
 
134
        char offset[2];
 
135
        union data d;
 
136
    } o2;
 
137
 
 
138
    struct {
 
139
        char offset[3];
 
140
        union data d;
 
141
    } o3;
 
142
 
 
143
    struct {
 
144
        char offset[4];
 
145
        union data d;
 
146
    } o4;
 
147
 
 
148
    struct {
 
149
        char offset[5];
 
150
        union data d;
 
151
    } o5;
 
152
 
 
153
    struct {
 
154
        char offset[6];
 
155
        union data d;
 
156
    } o6;
 
157
 
 
158
    struct {
 
159
        char offset[7];
 
160
        union data d;
 
161
    } o7;
 
162
 
 
163
    struct {
 
164
        char offset[8];
 
165
        union data d;
 
166
    } o8;
 
167
};
 
168
 
 
169
TST_CASE(tst_1, "stack alignment all")
 
170
{
 
171
    union offsettable_data od;
 
172
 
 
173
    TEST_ALIGNMENT(od, 0);
 
174
    TEST_ALIGNMENT(od, 1);
 
175
    TEST_ALIGNMENT(od, 2);
 
176
    TEST_ALIGNMENT(od, 3);
 
177
    TEST_ALIGNMENT(od, 4);
 
178
    TEST_ALIGNMENT(od, 5);
 
179
    TEST_ALIGNMENT(od, 6);
 
180
    TEST_ALIGNMENT(od, 7);
 
181
    TEST_ALIGNMENT(od, 8);
 
182
}
 
183
TST_LIST_BEGIN()
 
184
    TST_REGISTER(tst_1)
 
185
TST_LIST_END()