github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/misc/cgo/test/issue4417.go (about)

     1  // Copyright 2012 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  // Issue 4417:	cmd/cgo: bool alignment/padding issue.
     6  // bool alignment is wrong and causing wrong arguments when calling functions.
     7  //
     8  
     9  package cgotest
    10  
    11  /*
    12  #include <stdbool.h>
    13  
    14  static int c_bool(bool a, bool b, int c, bool d, bool e)  {
    15     return c;
    16  }
    17  */
    18  import "C"
    19  import "testing"
    20  
    21  func testBoolAlign(t *testing.T) {
    22  	b := C.c_bool(true, true, 10, true, false)
    23  	if b != 10 {
    24  		t.Fatalf("found %d expected 10\n", b)
    25  	}
    26  	b = C.c_bool(true, true, 5, true, true)
    27  	if b != 5 {
    28  		t.Fatalf("found %d expected 5\n", b)
    29  	}
    30  	b = C.c_bool(true, true, 3, true, false)
    31  	if b != 3 {
    32  		t.Fatalf("found %d expected 3\n", b)
    33  	}
    34  	b = C.c_bool(false, false, 1, true, false)
    35  	if b != 1 {
    36  		t.Fatalf("found %d expected 1\n", b)
    37  	}
    38  	b = C.c_bool(false, true, 200, true, false)
    39  	if b != 200 {
    40  		t.Fatalf("found %d expected 200\n", b)
    41  	}
    42  }