mirror of https://github.com/mono/CppSharp.git
8 changed files with 190 additions and 1 deletions
@ -1,4 +1,4 @@ |
|||||||
#!/bin/bash |
#!/usr/bin/env bash |
||||||
set -e |
set -e |
||||||
DIR=$( cd "$( dirname "$0" )" && pwd ) |
DIR=$( cd "$( dirname "$0" )" && pwd ) |
||||||
$DIR/build.sh test "$@" |
$DIR/build.sh test "$@" |
||||||
|
@ -0,0 +1,53 @@ |
|||||||
|
#include <cstdint> |
||||||
|
|
||||||
|
void ReturnsVoid () { } |
||||||
|
|
||||||
|
std::nullptr_t ReturnsNullptr () { return nullptr; } |
||||||
|
std::nullptr_t PassAndReturnsNullptr (std::nullptr_t t) { return t; } |
||||||
|
|
||||||
|
bool ReturnsBool () { return true; } |
||||||
|
bool PassAndReturnsBool (bool v) { return v; } |
||||||
|
|
||||||
|
// Character types
|
||||||
|
char ReturnsChar () { return 'a'; } |
||||||
|
signed char ReturnsSChar () { return 'a'; } |
||||||
|
unsigned char ReturnsUChar () { return 'a'; } |
||||||
|
char PassAndReturnsChar (char v) { return v; } |
||||||
|
signed char PassAndReturnsSChar (signed char v) { return v; } |
||||||
|
unsigned char PassAndReturnsUChar (unsigned char v) { return v; } |
||||||
|
|
||||||
|
|
||||||
|
wchar_t ReturnsWChar () { return 'a'; } |
||||||
|
#if __cplusplus > 201703L |
||||||
|
char8_t ReturnsChar8 () { return 'a'; } |
||||||
|
#endif |
||||||
|
char16_t ReturnsChar16 () { return 'a'; } |
||||||
|
char32_t ReturnsChar32 () { return 'a'; } |
||||||
|
|
||||||
|
// Floating-point types
|
||||||
|
float ReturnsFloat () { return 5.0; } |
||||||
|
double ReturnsDouble () { return -5.0; } |
||||||
|
long double ReturnsLongDouble () { return -5.0; } |
||||||
|
|
||||||
|
float PassAndReturnsFloat (float v) { return v; } |
||||||
|
double PassAndReturnsDouble (double v) { return v; } |
||||||
|
long double PassAndReturnsLongDouble (long double v) { return v; } |
||||||
|
|
||||||
|
// Integer types
|
||||||
|
int8_t ReturnsInt8 () { return -5; } |
||||||
|
uint8_t ReturnsUInt8 () { return 5; } |
||||||
|
int16_t ReturnsInt16 () { return -5; } |
||||||
|
uint16_t ReturnsUInt16 () { return 5; } |
||||||
|
int32_t ReturnsInt32 () { return -5; } |
||||||
|
uint32_t ReturnsUInt32 () { return 5; } |
||||||
|
int64_t ReturnsInt64 () { return -5; } |
||||||
|
uint64_t ReturnsUInt64 () { return 5; } |
||||||
|
|
||||||
|
int8_t PassAndReturnsInt8 (int8_t v) { return v; } |
||||||
|
uint8_t PassAndReturnsUInt8 (uint8_t v) { return v; } |
||||||
|
int16_t PassAndReturnsInt16 (int16_t v) { return v; } |
||||||
|
uint16_t PassAndReturnsUInt16 (uint16_t v) { return v; } |
||||||
|
int32_t PassAndReturnsInt32 (int32_t v) { return v; } |
||||||
|
uint32_t PassAndReturnsUInt32 (uint32_t v) { return v; } |
||||||
|
int64_t PassAndReturnsInt64 (int64_t v) { return v; } |
||||||
|
uint64_t PassAndReturnsUInt64 (uint64_t v) { return v; } |
@ -0,0 +1,3 @@ |
|||||||
|
int Overload(int, int) { return 1; } |
||||||
|
int Overload(int, float) { return 2; } |
||||||
|
int Overload(float, int) { return 3; } |
@ -0,0 +1,11 @@ |
|||||||
|
workspace "test" |
||||||
|
configurations {"Debug", "Release"} |
||||||
|
location "gen" |
||||||
|
symbols "On" |
||||||
|
optimize "Off" |
||||||
|
project "tests" |
||||||
|
kind "SharedLib" |
||||||
|
files {"gen/**.cpp"} |
||||||
|
includedirs {".."} |
||||||
|
targetprefix "" |
||||||
|
targetextension ".node" |
@ -0,0 +1,92 @@ |
|||||||
|
var test = require('./gen/bin/Debug/tests.node') |
||||||
|
const assert = require('assert').strict; |
||||||
|
|
||||||
|
const eq = assert.strictEqual; |
||||||
|
const floateq = (actual, expected) => { assert(Math.abs(actual - expected) < Number.EPSILON) } |
||||||
|
|
||||||
|
const ascii = v => v.charCodeAt(0) |
||||||
|
|
||||||
|
function builtins() |
||||||
|
{ |
||||||
|
eq(test.ReturnsVoid(), undefined) |
||||||
|
eq(test.ReturnsBool(), true) |
||||||
|
eq(test.PassAndReturnsBool(false), false) |
||||||
|
eq(test.ReturnsNullptr(), null) |
||||||
|
//eq(test.PassAndReturnsNullptr(null), null)
|
||||||
|
eq(test.ReturnsNullptr(), null) |
||||||
|
|
||||||
|
eq(test.ReturnsChar (), ascii('a')); |
||||||
|
eq(test.ReturnsSChar(), ascii('a')); |
||||||
|
eq(test.ReturnsUChar(), ascii('a')); |
||||||
|
|
||||||
|
eq(test.PassAndReturnsChar (ascii('a')), ascii('a')); |
||||||
|
eq(test.PassAndReturnsSChar(ascii('b')), ascii('b')); |
||||||
|
eq(test.PassAndReturnsUChar(ascii('c')), ascii('c')); |
||||||
|
|
||||||
|
eq(test.ReturnsFloat (), 5.0); |
||||||
|
eq(test.ReturnsDouble(), -5.0); |
||||||
|
//eq(test.ReturnsLongDouble(), -5.0);
|
||||||
|
|
||||||
|
//floateq(test.PassAndReturnsFloat (1.32), 1.32);
|
||||||
|
floateq(test.PassAndReturnsDouble(1.32), 1.32); |
||||||
|
//float(test.PassAndReturnsLongDouble(1.32), 1.32);
|
||||||
|
|
||||||
|
eq(test.ReturnsInt8 (), -5); |
||||||
|
eq(test.ReturnsUInt8 (), 5); |
||||||
|
eq(test.ReturnsInt16 (), -5); |
||||||
|
eq(test.ReturnsUInt16(), 5); |
||||||
|
eq(test.ReturnsInt32 (), -5); |
||||||
|
eq(test.ReturnsUInt32(), 5); |
||||||
|
eq(test.ReturnsInt64 (), -5n); |
||||||
|
eq(test.ReturnsUInt64(), 5n); |
||||||
|
|
||||||
|
const int8 = { min: -(2**7), max: (2**7) - 1 }; |
||||||
|
eq(test.PassAndReturnsInt8(int8.min), int8.min); |
||||||
|
eq(test.PassAndReturnsInt8(int8.max), int8.max); |
||||||
|
|
||||||
|
const uint8 = { min: 0, max: (2**8) - 1 }; |
||||||
|
eq(test.PassAndReturnsUInt8(uint8.min), uint8.min); |
||||||
|
eq(test.PassAndReturnsUInt8(uint8.max), uint8.max); |
||||||
|
|
||||||
|
const int16 = { min: -(2**15), max: (2**15) - 1 }; |
||||||
|
eq(test.PassAndReturnsInt16(int16.min), int16.min); |
||||||
|
eq(test.PassAndReturnsInt16(int16.max), int16.max); |
||||||
|
|
||||||
|
const uint16 = { min: 0, max: (2**16) - 1 }; |
||||||
|
eq(test.PassAndReturnsUInt16(uint16.min), uint16.min); |
||||||
|
eq(test.PassAndReturnsUInt16(uint16.max), uint16.max); |
||||||
|
|
||||||
|
const int32 = { min: -(2**31), max: (2**31) - 1 }; |
||||||
|
eq(test.PassAndReturnsInt32(int32.min), int32.min); |
||||||
|
eq(test.PassAndReturnsInt32(int32.max), int32.max); |
||||||
|
|
||||||
|
const uint32 = { min: 0, max: (2**32) - 1 }; |
||||||
|
eq(test.PassAndReturnsUInt32(uint32.min), uint32.min); |
||||||
|
eq(test.PassAndReturnsUInt32(uint32.max), uint32.max); |
||||||
|
|
||||||
|
const int64 = { min: BigInt(2**63) * -1n, max: BigInt(2**63) - 1n }; |
||||||
|
eq(test.PassAndReturnsInt64(int64.min), int64.min); |
||||||
|
eq(test.PassAndReturnsInt64(int64.max), int64.max); |
||||||
|
|
||||||
|
const uint64 = { min: BigInt(0), max: BigInt(2**64) - 1n }; |
||||||
|
eq(test.PassAndReturnsUInt64(uint64.min), uint64.min); |
||||||
|
eq(test.PassAndReturnsUInt64(uint64.max), uint64.max); |
||||||
|
} |
||||||
|
|
||||||
|
function enums() |
||||||
|
{ |
||||||
|
eq(test.Enum0.Item0, 0); |
||||||
|
eq(test.Enum0.Item1, 1); |
||||||
|
eq(test.Enum0.Item2, 5); |
||||||
|
} |
||||||
|
|
||||||
|
function overloads() |
||||||
|
{ |
||||||
|
eq(test.Overload(1, 2), 1) |
||||||
|
eq(test.Overload(1, 2.032), 2); |
||||||
|
eq(test.Overload(1.23, 2), 3); |
||||||
|
} |
||||||
|
|
||||||
|
builtins(); |
||||||
|
enums(); |
||||||
|
overloads(); |
@ -0,0 +1,23 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
set -e |
||||||
|
dir=$(cd "$(dirname "$0")"; pwd) |
||||||
|
rootdir="$dir/../.." |
||||||
|
configuration=Release |
||||||
|
platform=x64 |
||||||
|
|
||||||
|
red=`tput setaf 1` |
||||||
|
green=`tput setaf 2` |
||||||
|
reset=`tput sgr0` |
||||||
|
|
||||||
|
echo "${green}Generating bindings${reset}" |
||||||
|
dotnet $rootdir/bin/${configuration}_${platform}/CppSharp.CLI.dll \ |
||||||
|
--gen=napi -I$dir/.. -o $dir/gen -m tests $dir/../*.h |
||||||
|
|
||||||
|
echo "${green}Building generated binding files${reset}" |
||||||
|
premake=$rootdir/build/premake.sh |
||||||
|
$premake --file=$dir/premake5.lua gmake |
||||||
|
make -C $dir/gen |
||||||
|
echo |
||||||
|
|
||||||
|
echo "${green}Executing JS tests with Node${reset}" |
||||||
|
node $dir/test.js |
Loading…
Reference in new issue