LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Basic test cases for cgo. | 5 // Basic test cases for cgo. |
6 | 6 |
7 package cgotest | 7 package cgotest |
8 | 8 |
9 /* | 9 /* |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 t.Fatalf("C.fopen: should fail") | 113 t.Fatalf("C.fopen: should fail") |
114 } | 114 } |
115 if err != syscall.ENOENT { | 115 if err != syscall.ENOENT { |
116 t.Fatalf("C.fopen: unexpected error: %v", err) | 116 t.Fatalf("C.fopen: unexpected error: %v", err) |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 func testMultipleAssign(t *testing.T) { | 120 func testMultipleAssign(t *testing.T) { |
121 p := C.CString("234") | 121 p := C.CString("234") |
122 n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10) | 122 n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10) |
123 nl, ml := C.long(0), C.long(234) | |
124 if runtime.GOOS == "openbsd" { | 123 if runtime.GOOS == "openbsd" { |
125 » » // Bug in OpenBSD's strtol(3) - base > 36 is still valid. | 124 » » // Bug in OpenBSD strtol(3) - base > 36 succeeds. |
126 » » nl = 239089 | 125 » » if (n != 0 && n != 239089) || m != 234 { |
127 » } | 126 » » » t.Fatal("Strtol x2: ", n, m) |
128 » if n != nl || m != ml { | 127 » » } |
| 128 » } else if n != 0 || m != 234 { |
129 t.Fatal("Strtol x2: ", n, m) | 129 t.Fatal("Strtol x2: ", n, m) |
130 } | 130 } |
131 C.free(unsafe.Pointer(p)) | 131 C.free(unsafe.Pointer(p)) |
132 } | 132 } |
133 | 133 |
134 var ( | 134 var ( |
135 cuint = (C.uint)(0) | 135 cuint = (C.uint)(0) |
136 culong C.ulong | 136 culong C.ulong |
137 cchar C.char | 137 cchar C.char |
138 ) | 138 ) |
(...skipping 11 matching lines...) Expand all Loading... |
150 } | 150 } |
151 | 151 |
152 // Issue 2470. | 152 // Issue 2470. |
153 func testUnsignedInt(t *testing.T) { | 153 func testUnsignedInt(t *testing.T) { |
154 a := (int64)(C.UINT32VAL) | 154 a := (int64)(C.UINT32VAL) |
155 b := (int64)(0xc008427b) | 155 b := (int64)(0xc008427b) |
156 if a != b { | 156 if a != b { |
157 t.Errorf("Incorrect unsigned int - got %x, want %x", a, b) | 157 t.Errorf("Incorrect unsigned int - got %x, want %x", a, b) |
158 } | 158 } |
159 } | 159 } |
LEFT | RIGHT |