Skip to content

Commit

Permalink
Rudimentary RPC call tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Dec 19, 2018
1 parent 4086994 commit 7c292b9
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
34 changes: 30 additions & 4 deletions tests/Arduino.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
#include "Arduino.h"


HardwareSerial::HardwareSerial(void) {
reset();
}

void HardwareSerial::reset(void) {
rx = 0;
tx = 0;
}

void HardwareSerial::readBytes(char *buf, size_t size) {
int i;

for (i = 0; i < size; i++) {
buf[i] = 'x';
rx++;
}
}

size_t HardwareSerial::write(byte *, size_t) {
return 0;
size_t HardwareSerial::write(byte *, size_t size) {
tx += size;

return size;
}

size_t HardwareSerial::write(char) {
tx += 1;

return 1;
}

size_t HardwareSerial::write(string s) {
return s.length();
int length = s.length();

tx += length;

return length;
}

String HardwareSerial::readStringUntil(char) {
return "xxx";
String s = "xxx";

rx += s.length();

return s;
}


Expand Down
7 changes: 6 additions & 1 deletion tests/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ typedef unsigned char byte;

class HardwareSerial {
public:
void readBytes(char *buf, size_t size);
HardwareSerial(void);
void reset(void),
readBytes(char *buf, size_t size);
size_t write(byte *, size_t),
write(char),
write(string);
String readStringUntil(char);
size_t rx,
tx;
};


Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXEC := tests
MAIN := test_lib
TESTS := test_types test_print test_tuple
TESTS := test_print test_rpcCall test_signature test_tuple
FIXTURES := Arduino


Expand Down
49 changes: 49 additions & 0 deletions tests/test_rpcCall.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <catch.hpp>

#include "../simpleRPC/rpcCall.tcc"


TEST_CASE("RPC call function", "[call]") {
struct S {
static void f(int, char) {}
static short int g(int, char) {
return 0;
}
};

Serial.reset();
rpcCall(S::f);

REQUIRE(Serial.rx == sizeof(int) + sizeof(char));
REQUIRE(Serial.tx == 0);

Serial.reset();
rpcCall(S::g);

REQUIRE(Serial.rx == sizeof(int) + sizeof(char));
REQUIRE(Serial.tx == sizeof(short int));
}

TEST_CASE("RPC call class member functions", "[call]") {
class C {
public:
void f(int, char) {}
short int g(int, char) {
return 0;
}
};

C c;

Serial.reset();
rpcCall(pack(&c, &C::f));

REQUIRE(Serial.rx == sizeof(int) + sizeof(char));
REQUIRE(Serial.tx == 0);

Serial.reset();
rpcCall(pack(&c, &C::g));

REQUIRE(Serial.rx == sizeof(int) + sizeof(char));
REQUIRE(Serial.tx == sizeof(short int));
}

0 comments on commit 7c292b9

Please sign in to comment.