github.com/kortschak/utter@v1.5.0/dumpcgo_test.go (about) 1 // Copyright (c) 2013 Dave Collins <dave@davec.name> 2 // Copyright (c) 2015 Dan Kortschak <dan.kortschak@adelaide.edu.au> 3 // 4 // Permission to use, copy, modify, and distribute this software for any 5 // purpose with or without fee is hereby granted, provided that the above 6 // copyright notice and this permission notice appear in all copies. 7 // 8 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 16 // NOTE: Due to the following build constraints, this file will only be compiled 17 // when both cgo is supported and "-tags testcgo" is added to the go test 18 // command line. This means the cgo tests are only added (and hence run) when 19 // specifially requested. This configuration is used because utter itself 20 // does not require cgo to run even though it does handle certain cgo types 21 // specially. Rather than forcing all clients to require cgo and an external 22 // C compiler just to run the tests, this scheme makes them optional. 23 // +build cgo,testcgo 24 25 package utter_test 26 27 import "github.com/kortschak/utter/testdata" 28 29 func addCgoDumpTests() { 30 // C char pointer. 31 v := testdata.GetCgoCharPointer() 32 nv := testdata.GetCgoNullCharPointer() 33 pv := &v 34 vt := "testdata._Ctype_char" 35 vs := "116" 36 addDumpTest(v, "&"+vt+"("+vs+")\n") 37 addDumpTest(pv, "&&"+vt+"("+vs+")\n") 38 addDumpTest(&pv, "&&&"+vt+"("+vs+")\n") 39 addDumpTest(nv, "(*"+vt+")(nil)\n") 40 41 // C char array. 42 v2 := testdata.GetCgoCharArray() 43 v2t := "[6]testdata._Ctype_char" 44 v2s := "" + 45 "{\n 0x74, 0x65, 0x73, 0x74, 0x32, 0x00, // |test2.|\n}" 46 addDumpTest(v2, v2t+v2s+"\n") 47 48 // C unsigned char array. 49 v3 := testdata.GetCgoUnsignedCharArray() 50 v3tbefore1_6 := "[6]testdata._Ctype_unsignedchar" 51 v3t1_6 := "[6]testdata._Ctype_uchar" 52 v3s := "" + 53 "{\n 0x74, 0x65, 0x73, 0x74, 0x33, 0x00, // |test3.|\n}" 54 addDumpTest(v3, v3tbefore1_6+v3s+"\n", v3t1_6+v3s+"\n") 55 56 // C signed char array. 57 v4 := testdata.GetCgoSignedCharArray() 58 v4t := "[6]testdata._Ctype_schar" 59 v4t2 := "testdata._Ctype_schar" 60 v4s := "{\n " + 61 v4t2 + "(116),\n " + 62 v4t2 + "(101),\n " + 63 v4t2 + "(115),\n " + 64 v4t2 + "(116),\n " + 65 v4t2 + "(52),\n " + 66 v4t2 + "(0),\n}" 67 addDumpTest(v4, v4t+v4s+"\n") 68 69 // C uint8_t array. 70 v5 := testdata.GetCgoUint8tArray() 71 v5tbefore1_10 := "[6]testdata._Ctype_uint8_t" 72 v5t1_10 := "[6]testdata._Ctype_uchar" 73 v5tafter1_12 := "[6]uint8" 74 v5s := "" + 75 "{\n 0x74, 0x65, 0x73, 0x74, 0x35, 0x00, // |test5.|\n}" 76 addDumpTest(v5, v5tbefore1_10+v5s+"\n", v5t1_10+v5s+"\n", v5tafter1_12+v5s+"\n") 77 78 // C typedefed unsigned char array. 79 v6 := testdata.GetCgoTypdefedUnsignedCharArray() 80 v6tbefore1_10 := "[6]testdata._Ctype_custom_uchar_t" 81 v6t1_10 := "[6]testdata._Ctype_uchar" 82 v6s := "" + 83 "{\n 0x74, 0x65, 0x73, 0x74, 0x36, 0x00, // |test6.|\n}" 84 addDumpTest(v6, v6tbefore1_10+v6s+"\n", v6t1_10+v6s+"\n") 85 }