introduce TDF_compare_debug, omit OBJ_TYPE_REF casts with it
[official-gcc.git] / libgo / misc / cgo / test / align.go
bloba23b44fc38c83bf872944c71dc55cc0558ef1ae5
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package cgotest
7 /*
8 #include <stdio.h>
10 typedef unsigned char Uint8;
11 typedef unsigned short Uint16;
13 typedef enum {
14 MOD1 = 0x0000,
15 MODX = 0x8000
16 } SDLMod;
18 typedef enum {
19 A = 1,
20 B = 322,
21 SDLK_LAST
22 } SDLKey;
24 typedef struct SDL_keysym {
25 Uint8 scancode;
26 SDLKey sym;
27 SDLMod mod;
28 Uint16 unicode;
29 } SDL_keysym;
31 typedef struct SDL_KeyboardEvent {
32 Uint8 typ;
33 Uint8 which;
34 Uint8 state;
35 SDL_keysym keysym;
36 } SDL_KeyboardEvent;
38 void makeEvent(SDL_KeyboardEvent *event) {
39 unsigned char *p;
40 int i;
42 p = (unsigned char*)event;
43 for (i=0; i<sizeof *event; i++) {
44 p[i] = i;
48 int same(SDL_KeyboardEvent* e, Uint8 typ, Uint8 which, Uint8 state, Uint8 scan, SDLKey sym, SDLMod mod, Uint16 uni) {
49 return e->typ == typ && e->which == which && e->state == state && e->keysym.scancode == scan && e->keysym.sym == sym && e->keysym.mod == mod && e->keysym.unicode == uni;
52 void cTest(SDL_KeyboardEvent *event) {
53 printf("C: %#x %#x %#x %#x %#x %#x %#x\n", event->typ, event->which, event->state,
54 event->keysym.scancode, event->keysym.sym, event->keysym.mod, event->keysym.unicode);
55 fflush(stdout);
59 import "C"
61 import (
62 "testing"
65 func testAlign(t *testing.T) {
66 var evt C.SDL_KeyboardEvent
67 C.makeEvent(&evt)
68 if C.same(&evt, evt.typ, evt.which, evt.state, evt.keysym.scancode, evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode) == 0 {
69 t.Error("*** bad alignment")
70 C.cTest(&evt)
71 t.Errorf("Go: %#x %#x %#x %#x %#x %#x %#x\n",
72 evt.typ, evt.which, evt.state, evt.keysym.scancode,
73 evt.keysym.sym, evt.keysym.mod, evt.keysym.unicode)
74 t.Error(evt)