Skip to content

Commit 44600f0

Browse files
committed
Fixed serial validation testing
1 parent b6f5803 commit 44600f0

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

testing/Command_Interpreter_Testing.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,35 @@
55

66
#include <wiringSerial.h>
77

8-
bool initializeGPIO(int* serial) {
8+
void echoOn(int serial) {
9+
serialPuts(serial, "echo on\n");
10+
}
11+
12+
bool initializeSerial(int* serial) {
913
if ((*serial = serialOpen("/dev/serial/by-id/usb-MicroPython_Board_in_FS_mode_e6614864d3798738-if00", 115200)) < 0) {
1014
return false;
1115
}
16+
echoOn(*serial);
1217
return true;
1318
}
1419

1520
int getSerialChar(int* serial) {
1621
if (*serial == -1) {
17-
if (!initializeGPIO(serial)) {
22+
if (!initializeSerial
23+
(serial)) {
1824
std::cerr << "Unable to open serial port! Exiting." << std::endl;
1925
exit(42);
2026
}
2127
}
2228
return serialGetchar(*serial); // from wiringSerial
2329
}
2430

25-
void echoOn(int serial) {
26-
serialPuts(serial, "echo on\n");
27-
}
28-
2931
#else
3032

31-
bool initializeGPIO(int* serial) {
33+
bool initializeSerial(int* serial) {
3234
return true;
3335
}
3436

35-
void echoOn(int serial) {
36-
return;
37-
}
38-
3937
int getSerialChar(int* serial) {
4038
return EOF;
4139
}
@@ -45,7 +43,8 @@ int getSerialChar(int* serial) {
4543
TEST(CommandInterpreterTest, CreateCommandInterpreter) {
4644
testing::internal::CaptureStdout();
4745
int serial = -1;
48-
initializeGPIO(&serial);
46+
initializeSerial
47+
(&serial);
4948

5049
auto pinNumbers = std::vector<int>{4, 5, 2, 3, 9, 7, 8, 6};
5150

@@ -83,14 +82,16 @@ TEST(CommandInterpreterTest, CreateCommandInterpreter) {
8382
ASSERT_EQ(output, expectedOutput);
8483
}
8584
else {
85+
expectedOutput.insert(0, "echo on\n");
8686
ASSERT_EQ(serialOutput, expectedOutput);
8787
}
8888
}
8989

9090
TEST(CommandInterpreterTest, CreateCommandInterpreterWithDigitalPins) {
9191
testing::internal::CaptureStdout();
9292
int serial = -1;
93-
initializeGPIO(&serial);
93+
initializeSerial
94+
(&serial);
9495

9596
auto pinNumbers = std::vector<int>{4, 5, 2, 3, 9, 7, 8, 6};
9697

@@ -133,14 +134,16 @@ TEST(CommandInterpreterTest, CreateCommandInterpreterWithDigitalPins) {
133134
ASSERT_EQ(output, expectedOutput);
134135
}
135136
else {
137+
expectedOutput.insert(0, "echo on\n");
136138
ASSERT_EQ(serialOutput, expectedOutput);
137139
}
138140
}
139141

140142
TEST(CommandInterpreterTest, BlindExecuteHardwarePwm) {
141143
testing::internal::CaptureStdout();
142144
int serial = -1;
143-
initializeGPIO(&serial);
145+
initializeSerial
146+
(&serial);
144147

145148
const CommandComponent acceleration = {1900, 1900, 1100,
146149
1250, 1300, 1464, 1535,
@@ -195,14 +198,16 @@ TEST(CommandInterpreterTest, BlindExecuteHardwarePwm) {
195198
ASSERT_EQ(output, expectedOutput);
196199
}
197200
else {
201+
expectedOutput.insert(0, "echo on\n");
198202
ASSERT_EQ(serialOutput, expectedOutput);
199203
}
200204
}
201205

202206
TEST(CommandInterpreterTest, BlindExecuteSoftwarePwm) {
203207
testing::internal::CaptureStdout();
204208
int serial = -1;
205-
initializeGPIO(&serial);
209+
initializeSerial
210+
(&serial);
206211

207212
const CommandComponent acceleration = {1100, 1900, 1100,
208213
1250, 1300, 1464, 1535,
@@ -258,6 +263,7 @@ TEST(CommandInterpreterTest, BlindExecuteSoftwarePwm) {
258263
ASSERT_EQ(output, expectedOutput);
259264
}
260265
else {
266+
expectedOutput.insert(0, "echo on\n");
261267
ASSERT_EQ(serialOutput, expectedOutput);
262268
}
263269
}

0 commit comments

Comments
 (0)