Skip to content

Commit

Permalink
Add more tests for callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Jan 17, 2017
1 parent d7a4a7b commit 392c1da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/Callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Callback {
static double callIncrementDouble(const nbind::cbFunction &incrementDouble, double x) {return(incrementDouble.call<double>(x));}

static std::string callCatenate(nbind::cbFunction &catenate, const char *a, const char *b) {return(catenate.call<std::string>(a, b));}
static std::string callCatenate2(nbind::cbFunction &catenate, const char *a, const char *b) {return(catenate.call<std::string>(a, b));}

static void callCStrings(nbind::cbFunction &cb) {
std::string foo = "foo";
Expand Down Expand Up @@ -51,7 +52,10 @@ NBIND_CLASS(Callback) {
method(callAddInt2);

method(callIncrementDouble);

method(callCatenate);
method(callCatenate2);

method(callCStrings);
}

Expand Down
1 change: 1 addition & 0 deletions test/reflect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Callback {
static int32_t callAddInt2(const std::function<int32_t (int32_t, int32_t)> &, int32_t, int32_t);
static float64_t callIncrementDouble(const cbFunction &, float64_t);
static std::string callCatenate(cbFunction &, const char *, const char *);
static std::string callCatenate2(cbFunction &, const char *, const char *);
static void callCStrings(cbFunction &);
};

Expand Down
1 change: 1 addition & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ test('Callbacks', function(t: any) {
t.strictEqual(Type.callAddInt2(function(x: number, y: number) {return(x + y);}, 40, 2), 42);
t.strictEqual(Type.callIncrementDouble(function(x: number) {return(x + 0.25);}, 0.5), 0.75);
t.strictEqual(Type.callCatenate(function(x: string, y: string) {return(x + y);}, 'foo', 'bar'), 'foobar');
t.strictEqual(Type.callCatenate2(function(x: string, y: string) {return(x + y);}, 'foo', 'bar'), 'foobar');

t.throws(function() {
Type.callNegate({} as any as (x: boolean) => boolean, true);
Expand Down

0 comments on commit 392c1da

Please sign in to comment.