Skip to content

Commit 6069690

Browse files
committed
Put utility function in their own files
1 parent fbfa8b1 commit 6069690

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

extras/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
3333

3434
set(TEST_SRCS
3535
src/RPC/test_RPCClient.cpp
36+
src/RPC/utils.cpp
3637
)
3738

3839
set(TEST_DUT_SRCS

extras/test/src/RPC/test_RPCClient.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@
77
#include <catch.hpp>
88
#include <StreamMock.h>
99
#include <Arduino_RPClite.h>
10-
11-
// Poor-man MsgPack encoder
12-
#define ARRAY_N(x) (0x90 + (x))
13-
#define STRING_N(x) (0xA0 + (x))
14-
#define NIL 0xc0
15-
#define FLOAT_32 0xcb
16-
#define CALL_TAG 0x00
17-
#define RESP_TAG 0x01
18-
19-
// convert a byte array into an hex string
20-
std::string to_hex_string(const unsigned char* data, size_t size) {
21-
std::ostringstream oss;
22-
oss << std::hex << std::setw(2) << std::setfill('0');
23-
for (size_t i = 0; i < size; ++i) {
24-
oss << static_cast<int>(data[i]);
25-
}
26-
return oss.str();
27-
}
28-
29-
#define COMPARE_ARRAYS(expected, got) \
30-
REQUIRE(to_hex_string(expected, sizeof(expected)) == to_hex_string(got, sizeof(expected)))
10+
#include "utils.h"
3111

3212
TEST_CASE("RPCClient::call", "[RPCClient-01]")
3313
{

extras/test/src/RPC/utils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <string>
2+
#include <sstream>
3+
#include <iomanip>
4+
5+
// convert a byte array into an hex string
6+
std::string to_hex_string(const unsigned char* data, size_t size) {
7+
std::ostringstream oss;
8+
oss << std::hex << std::setw(2) << std::setfill('0');
9+
for (size_t i = 0; i < size; ++i) {
10+
oss << static_cast<int>(data[i]);
11+
}
12+
return oss.str();
13+
}

extras/test/src/RPC/utils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
// Poor-man MsgPack encoder
6+
#define ARRAY_N(x) (0x90 + (x))
7+
#define STRING_N(x) (0xA0 + (x))
8+
#define NIL 0xc0
9+
#define FLOAT_32 0xcb
10+
#define CALL_TAG 0x00
11+
#define RESP_TAG 0x01
12+
13+
#define COMPARE_ARRAYS(expected, got) \
14+
REQUIRE(to_hex_string(expected, sizeof(expected)) == to_hex_string(got, sizeof(expected)))
15+
16+
std::string to_hex_string(const unsigned char* data, size_t size);

0 commit comments

Comments
 (0)