github.com/kortschak/utter@v1.5.0/testdata/dumpcgo.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 code should really only be in the dumpcgo_test.go file,
    19  // but unfortunately Go will not allow cgo in test files, so this is a
    20  // workaround to allow cgo types to be tested.  This configuration is used
    21  // because utter itself does not require cgo to run even though it does handle
    22  // certain cgo types specially.  Rather than forcing all clients to require cgo
    23  // and an external C compiler just to run the tests, this scheme makes them
    24  // optional.
    25  // +build cgo,testcgo
    26  
    27  package testdata
    28  
    29  /*
    30  #include <stdint.h>
    31  typedef unsigned char custom_uchar_t;
    32  
    33  char            *ncp = 0;
    34  char            *cp = "test";
    35  char             ca[6] = {'t', 'e', 's', 't', '2', '\0'};
    36  unsigned char    uca[6] = {'t', 'e', 's', 't', '3', '\0'};
    37  signed char      sca[6] = {'t', 'e', 's', 't', '4', '\0'};
    38  uint8_t          ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'};
    39  custom_uchar_t   tuca[6] = {'t', 'e', 's', 't', '6', '\0'};
    40  */
    41  import "C"
    42  
    43  // GetCgoNullCharPointer returns a null char pointer via cgo.  This is only
    44  // used for tests.
    45  func GetCgoNullCharPointer() interface{} {
    46  	return C.ncp
    47  }
    48  
    49  // GetCgoCharPointer returns a char pointer via cgo.  This is only used for
    50  // tests.
    51  func GetCgoCharPointer() interface{} {
    52  	return C.cp
    53  }
    54  
    55  // GetCgoCharArray returns a char array via cgo and the array's len and cap.
    56  // This is only used for tests.
    57  func GetCgoCharArray() interface{} {
    58  	return C.ca
    59  }
    60  
    61  // GetCgoUnsignedCharArray returns an unsigned char array via cgo and the
    62  // array's len and cap.  This is only used for tests.
    63  func GetCgoUnsignedCharArray() interface{} {
    64  	return C.uca
    65  }
    66  
    67  // GetCgoSignedCharArray returns a signed char array via cgo and the array's len
    68  // and cap.  This is only used for tests.
    69  func GetCgoSignedCharArray() interface{} {
    70  	return C.sca
    71  }
    72  
    73  // GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and
    74  // cap.  This is only used for tests.
    75  func GetCgoUint8tArray() interface{} {
    76  	return C.ui8ta
    77  }
    78  
    79  // GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via
    80  // cgo and the array's len and cap.  This is only used for tests.
    81  func GetCgoTypdefedUnsignedCharArray() interface{} {
    82  	return C.tuca
    83  }