Skip to content

Commit

Permalink
Added unit tests for the interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Dec 28, 2018
1 parent 83ad355 commit 9270522
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion simpleRPC/interface.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "rpcCall.tcc"
#include "signature.tcc"

#define _LIST_REQ 0xff
#define _LIST_REQ (byte)0xff


/**
Expand Down
51 changes: 50 additions & 1 deletion tests/test_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,53 @@ TEST_CASE("Multiple functions", "[describe]") {
REQUIRE(Serial.inspect<String>() == ":;f");
}

// TODO: select and interface.
TEST_CASE("Select by number", "[select]") {
struct S {
static short int f(void) {
return 1;
}
static short int g(void) {
return 2;
}
};

// Select first function.
Serial.reset();
_select(0, 0, S::f, "", S::g, "");
REQUIRE(Serial.inspect<short int>() == 1);

// Select second function.
Serial.reset();
_select(1, 0, S::f, "", S::g, "");
REQUIRE(Serial.inspect<short int>() == 2);
}

TEST_CASE("RPC interface", "[interface]") {
struct S {
static short int f(void) {
return 1;
}
static short int g(void) {
return 2;
}
};

// Describe interface.
Serial.reset();
Serial.prepare(_LIST_REQ);
rpcInterface(S::f, "f", S::g, "g");
REQUIRE(Serial.inspect<String>() == "<h:;f");
REQUIRE(Serial.inspect<String>() == "<h:;g");

// Select first function.
Serial.reset();
Serial.prepare((byte)0x00);
rpcInterface(S::f, "f", S::g, "g");
REQUIRE(Serial.inspect<short int>() == 1);

// Select second function.
Serial.reset();
Serial.prepare((byte)0x01);
rpcInterface(S::f, "f", S::g, "g");
REQUIRE(Serial.inspect<short int>() == 2);
}

0 comments on commit 9270522

Please sign in to comment.