Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(434)

Side by Side Diff: misc/cgo/test/fpvar.go

Issue 9835047: code review 9835047: cmd/cgo: Add support for C function pointers (Closed)
Patch Set: diff -r d881cb1ffc14 https://code.google.com/p/go Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « misc/cgo/test/cgo_test.go ('k') | src/cmd/cgo/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 // This file contains test cases for cgo with function pointer variables.
6
7 package cgotest
8
9 /*
10 typedef int (*intFunc) ();
11
12 int
13 bridge_int_func(intFunc f)
14 {
15 return f();
16 }
17
18 int fortytwo()
19 {
20 return 42;
21 }
22
23 */
24 import "C"
25 import "testing"
26
27 func callBridge(f C.intFunc) int {
28 return int(C.bridge_int_func(f))
29 }
30
31 func callCBridge(f C.intFunc) C.int {
32 return C.bridge_int_func(f)
33 }
34
35 func testFpVar(t *testing.T) {
36 const expected = 42
37 f := C.intFunc(C.fortytwo)
38 res1 := C.bridge_int_func(f)
39 if r1 := int(res1); r1 != expected {
40 t.Errorf("got %d, want %d", r1, expected)
41 }
42 res2 := callCBridge(f)
43 if r2 := int(res2); r2 != expected {
44 t.Errorf("got %d, want %d", r2, expected)
45 }
46 r3 := callBridge(f)
47 if r3 != expected {
48 t.Errorf("got %d, want %d", r3, expected)
49 }
50 }
OLDNEW
« no previous file with comments | « misc/cgo/test/cgo_test.go ('k') | src/cmd/cgo/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b