Skip to content

Commit

Permalink
sdl: events: Fix tests #274
Browse files Browse the repository at this point in the history
  • Loading branch information
malashin committed Nov 8, 2017
1 parent 9059810 commit e798fe3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions sdl/audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAudioDevices(t *testing.T) {
}

func TestAudioInitQuit(t *testing.T) {
Do(func(){
Do(func() {
// figure out what driver will work
if err := InitSubSystem(INIT_AUDIO); err != nil {
t.Fatalf("InitSubSystem(INIT_AUDIO): %v", err)
Expand Down Expand Up @@ -66,28 +66,28 @@ func TestAudioInitQuit(t *testing.T) {
})
}

func TestLoadWAV_RW(t *testing.T) {
func TestLoadWAVRW(t *testing.T) {
// load WAV from *RWOps pointing to WAV data
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&squareWave))
src := RWFromMem(unsafe.Pointer(sliceHeader.Data), len(squareWave))
buf, spec := LoadWAV_RW(src, false, &AudioSpec{})
buf, spec := LoadWAVRW(src, false, &AudioSpec{})

// test returned []byte
want := []byte{0, 0, 0, 0, 255, 255, 255, 255}
if buf == nil {
t.Errorf("LoadWAV_RW() returned nil []byte")
t.Errorf("LoadWAVRW() returned nil []byte")
} else {
if bytes.Compare(buf, want) != 0 {
t.Errorf("LoadWAV_RW() returned %v; want %v", buf, want)
t.Errorf("LoadWAVRW() returned %v; want %v", buf, want)
}
FreeWAV(buf) // make sure we can free without error
}

// test returned *AudioSpec
if spec == nil {
t.Errorf("LoadWAV_RW() returned nil *AudioSpec")
t.Errorf("LoadWAVRW() returned nil *AudioSpec")
} else if spec.Freq != 8363 { // no need to test all the spec fields
t.Errorf("LoadWAV_RW() returned *AudioSpec with Freq %d; want %d",
t.Errorf("LoadWAVRW() returned *AudioSpec with Freq %d; want %d",
spec.Freq, 8363)
}
}
6 changes: 3 additions & 3 deletions sdl/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ type DropEvent struct {
File string // the file name
WindowID uint32 // the window that was dropped on, if any
}

type cDropEvent struct {
type tDropEvent struct {
Type uint32
Timestamp uint32
File unsafe.Pointer
WindowID uint32
}
type cDropEvent C.SDL_DropEvent

// RenderEvent contains render event information.
// (https://wiki.libsdl.org/SDL_EventType)
Expand Down Expand Up @@ -582,7 +582,7 @@ func goEvent(cevent *CEvent) Event {
case MULTIGESTURE:
return (*MultiGestureEvent)(unsafe.Pointer(cevent))
case DROPFILE:
e := (*cDropEvent)(unsafe.Pointer(cevent))
e := (*tDropEvent)(unsafe.Pointer(cevent))
event := DropEvent{Type: e.Type, Timestamp: e.Timestamp, File: string(C.GoString((*C.char)(e.File))), WindowID: e.WindowID}
C.SDL_free(e.File)
return &event
Expand Down
2 changes: 1 addition & 1 deletion sdl/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestStructABI(t *testing.T) {
{TouchFingerEvent{}, cTouchFingerEvent{}, nil},
{MultiGestureEvent{}, cMultiGestureEvent{}, nil},
{DollarGestureEvent{}, cDollarGestureEvent{}, nil},
{DropEvent{}, cDropEvent{}, dropEventEdgeCase},
{tDropEvent{}, cDropEvent{}, dropEventEdgeCase},
{UserEvent{}, cUserEvent{}, nil},
{SysWMEvent{}, cSysWMEvent{}, nil},
}
Expand Down

0 comments on commit e798fe3

Please sign in to comment.