From 50b87aed771f98033e8f285b71c0410d82a84e66 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 5 May 2014 22:32:34 -0500 Subject: [PATCH] Pass cgo tests. --- spew/dumpcgo_test.go | 35 +++++++++++++++++++++++++---------- spew/testdata/dumpcgo.go | 37 +++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/spew/dumpcgo_test.go b/spew/dumpcgo_test.go index 30e7f7c..9b8a358 100644 --- a/spew/dumpcgo_test.go +++ b/spew/dumpcgo_test.go @@ -44,39 +44,54 @@ func addCgoDumpTests() { addDumpTest(nv, "("+vt+")()\n") // C char array. - v2 := testdata.GetCgoCharArray() + v2, v2l, v2c := testdata.GetCgoCharArray() + v2Len := fmt.Sprintf("%d", v2l) + v2Cap := fmt.Sprintf("%d", v2c) v2t := "[6]testdata._Ctype_char" - v2s := "{\n 00000000 74 65 73 74 32 00 " + + v2s := "(len=" + v2Len + " cap=" + v2Cap + ") " + + "{\n 00000000 74 65 73 74 32 00 " + " |test2.|\n}" addDumpTest(v2, "("+v2t+") "+v2s+"\n") // C unsigned char array. - v3 := testdata.GetCgoUnsignedCharArray() + v3, v3l, v3c := testdata.GetCgoUnsignedCharArray() + v3Len := fmt.Sprintf("%d", v3l) + v3Cap := fmt.Sprintf("%d", v3c) v3t := "[6]testdata._Ctype_unsignedchar" - v3s := "{\n 00000000 74 65 73 74 33 00 " + + v3s := "(len=" + v3Len + " cap=" + v3Cap + ") " + + "{\n 00000000 74 65 73 74 33 00 " + " |test3.|\n}" addDumpTest(v3, "("+v3t+") "+v3s+"\n") // C signed char array. - v4 := testdata.GetCgoSignedCharArray() + v4, v4l, v4c := testdata.GetCgoSignedCharArray() + v4Len := fmt.Sprintf("%d", v4l) + v4Cap := fmt.Sprintf("%d", v4c) v4t := "[6]testdata._Ctype_schar" v4t2 := "testdata._Ctype_schar" - v4s := "{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 + + v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " + + "{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 + ") 115,\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 52,\n (" + v4t2 + ") 0\n}" addDumpTest(v4, "("+v4t+") "+v4s+"\n") // C uint8_t array. - v5 := testdata.GetCgoUint8tArray() + v5, v5l, v5c := testdata.GetCgoUint8tArray() + v5Len := fmt.Sprintf("%d", v5l) + v5Cap := fmt.Sprintf("%d", v5c) v5t := "[6]testdata._Ctype_uint8_t" - v5s := "{\n 00000000 74 65 73 74 35 00 " + + v5s := "(len=" + v5Len + " cap=" + v5Cap + ") " + + "{\n 00000000 74 65 73 74 35 00 " + " |test5.|\n}" addDumpTest(v5, "("+v5t+") "+v5s+"\n") // C typedefed unsigned char array. - v6 := testdata.GetCgoTypdefedUnsignedCharArray() + v6, v6l, v6c := testdata.GetCgoTypdefedUnsignedCharArray() + v6Len := fmt.Sprintf("%d", v6l) + v6Cap := fmt.Sprintf("%d", v6c) v6t := "[6]testdata._Ctype_custom_uchar_t" - v6s := "{\n 00000000 74 65 73 74 36 00 " + + v6s := "(len=" + v6Len + " cap=" + v6Cap + ") " + + "{\n 00000000 74 65 73 74 36 00 " + " |test6.|\n}" addDumpTest(v6, "("+v6t+") "+v6s+"\n") } diff --git a/spew/testdata/dumpcgo.go b/spew/testdata/dumpcgo.go index 2e98452..5c87dd4 100644 --- a/spew/testdata/dumpcgo.go +++ b/spew/testdata/dumpcgo.go @@ -51,31 +51,32 @@ func GetCgoCharPointer() interface{} { return C.cp } -// GetCgoCharArray returns a char array via cgo. This is only used for tests. -func GetCgoCharArray() interface{} { - return C.ca +// GetCgoCharArray returns a char array via cgo and the array's len and cap. +// This is only used for tests. +func GetCgoCharArray() (interface{}, int, int) { + return C.ca, len(C.ca), cap(C.ca) } -// GetCgoUnsignedCharArray returns an unsigned char array via cgo. This is only -// used for tests. -func GetCgoUnsignedCharArray() interface{} { - return C.uca +// GetCgoUnsignedCharArray returns an unsigned char array via cgo and the +// array's len and cap. This is only used for tests. +func GetCgoUnsignedCharArray() (interface{}, int, int) { + return C.uca, len(C.uca), cap(C.uca) } -// GetCgoSignedCharArray returns a signed char array via cgo. This is only used -// for tests. -func GetCgoSignedCharArray() interface{} { - return C.sca +// GetCgoSignedCharArray returns a signed char array via cgo and the array's len +// and cap. This is only used for tests. +func GetCgoSignedCharArray() (interface{}, int, int) { + return C.sca, len(C.sca), cap(C.sca) } -// GetCgoUint8tArray returns a uint8_t array via cgo. This is only used for -// tests. -func GetCgoUint8tArray() interface{} { - return C.ui8ta +// GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and +// cap. This is only used for tests. +func GetCgoUint8tArray() (interface{}, int, int) { + return C.ui8ta, len(C.ui8ta), cap(C.ui8ta) } // GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via -// cgo. This is only used for tests. -func GetCgoTypdefedUnsignedCharArray() interface{} { - return C.tuca +// cgo and the array's len and cap. This is only used for tests. +func GetCgoTypdefedUnsignedCharArray() (interface{}, int, int) { + return C.tuca, len(C.tuca), cap(C.tuca) }