Skip to content

Commit

Permalink
[TS-267] Add HardwareSerial::end() to NoteSerialReset in `note-ar…
Browse files Browse the repository at this point in the history
…duino`
  • Loading branch information
zfields committed Jun 22, 2024
1 parent 0024bc7 commit ae1a122
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 79 deletions.
1 change: 1 addition & 0 deletions src/NoteSerial_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NoteSerial_Arduino::reset (
void
)
{
_notecardSerial.end();
_notecardSerial.begin(_notecardSerialSpeed);

return true;
Expand Down
76 changes: 38 additions & 38 deletions test/NoteI2c_Arduino.test.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test/NoteLog_Arduino.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int test_make_note_log_instantiates_notelog_object()
else
{
result = static_cast<int>('d' + 'e' + 'b' + 'u' + 'g');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnotelog == " << !!notelog << ", EXPECTED: not nullptr" << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -55,7 +55,7 @@ int test_make_note_log_enforces_singleton_by_returning_same_notelog_object_for_a
else
{
result = static_cast<int>('d' + 'e' + 'b' + 'u' + 'g');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnotelog_2 == " << std::hex << notelog_2 << ", EXPECTED: " << notelog_1 << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -86,7 +86,7 @@ int test_make_note_log_deletes_singleton_when_nullptr_is_passed_as_parameter()
else
{
result = static_cast<int>('d' + 'e' + 'b' + 'u' + 'g');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnotelog == " << std::hex << notelog << ", EXPECTED: 0 (nullptr)" << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -115,7 +115,7 @@ int test_notelog_arduino_print_does_not_modify_str_parameter_value_before_passin
else
{
result = static_cast<int>('d' + 'e' + 'b' + 'u' + 'g');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tstreamPrint_Parameters.str_cache.c_str() == \"" << streamPrint_Parameters.str_cache.c_str() << "\", EXPECTED: \"" << EXPECTED_RESULT << "\"" << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -145,7 +145,7 @@ int test_notelog_arduino_print_does_not_modify_stream_print_result_value_before_
else
{
result = static_cast<int>('d' + 'e' + 'b' + 'u' + 'g');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnotelog.print(\"Hello, Test!\") == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl;
std::cout << "[";
}
Expand Down
64 changes: 46 additions & 18 deletions test/NoteSerial_Arduino.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int test_make_note_serial_instantiates_noteserial_object()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial == " << !!noteserial << ", EXPECTED: not nullptr" << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -57,7 +57,7 @@ int test_make_note_serial_enforces_singleton_by_returning_same_noteserial_object
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial_2 == " << std::hex << noteserial_2 << ", EXPECTED: " << noteserial_1 << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -89,7 +89,7 @@ int test_make_note_serial_deletes_singleton_when_nullptr_is_passed_as_parameter(
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial == " << std::hex << noteserial << ", EXPECTED: 0 (nullptr)" << std::endl;
std::cout << "[";
}
Expand All @@ -115,7 +115,7 @@ int test_noteserial_arduino_constructor_invokes_hardware_serial_parameter_begin_
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialBegin_Parameters.invoked == " << !!hardwareSerialBegin_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -143,7 +143,7 @@ int test_noteserial_arduino_constructor_does_not_modify_baud_parameter_before_pa
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialBegin_Parameters.baud == " << hardwareSerialBegin_Parameters.baud << ", EXPECTED: " << EXPECTED_BAUD_RATE << std::endl;
std::cout << "[";
}
Expand All @@ -170,7 +170,7 @@ int test_noteserial_arduino_available_invokes_hardware_serial_available()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialAvailable_Parameters.invoked == " << !!hardwareSerialAvailable_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -200,7 +200,7 @@ int test_noteserial_arduino_available_does_not_modify_hardware_serial_available_
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial.available() == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -228,7 +228,7 @@ int test_noteserial_arduino_receive_invokes_hardware_serial_read()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialRead_Parameters.invoked == " << hardwareSerialRead_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -258,14 +258,41 @@ int test_noteserial_arduino_receive_does_not_modify_hardware_serial_read_result_
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial.receive() == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl;
std::cout << "[";
}

return result;
}

int test_noteserial_arduino_reset_invokes_hardware_serial_end()
{
int result;

// Arrange
NoteSerial_Arduino noteserial(Serial, 9600);
hardwareSerialEnd_Parameters.reset();

// Action
noteserial.reset();

// Assert
if (hardwareSerialEnd_Parameters.invoked)
{
result = 0;
}
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialEnd_Parameters.invoked == " << !!hardwareSerialEnd_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}

return result;
}

int test_noteserial_arduino_reset_invokes_hardware_serial_begin()
{
int result;
Expand All @@ -285,7 +312,7 @@ int test_noteserial_arduino_reset_invokes_hardware_serial_begin()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialBegin_Parameters.invoked == " << !!hardwareSerialBegin_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -314,7 +341,7 @@ int test_noteserial_arduino_reset_invokes_hardware_serial_begin_with_the_baud_pa
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialBegin_Parameters.baud == " << hardwareSerialBegin_Parameters.baud << ", EXPECTED: " << EXPECTED_BAUD_RATE << std::endl;
std::cout << "[";
}
Expand All @@ -340,7 +367,7 @@ int test_noteserial_arduino_reset_always_returns_true()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial.reset() == " << ACTUAL_RESULT << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -368,7 +395,7 @@ int test_noteserial_arduino_transmit_invokes_hardware_serial_write()
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialWrite_Parameters.invoked == " << !!hardwareSerialWrite_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -397,7 +424,7 @@ int test_noteserial_arduino_transmit_does_not_modify_buffer_parameter_value_befo
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialWrite_Parameters.buffer_cache.c_str() == \"" << hardwareSerialWrite_Parameters.buffer_cache.c_str() << "\", EXPECTED: \"" << EXPECTED_RESULT << "\"" << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -426,7 +453,7 @@ int test_noteserial_arduino_transmit_does_not_modify_size_parameter_value_before
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialWrite_Parameters.size == " << hardwareSerialWrite_Parameters.size << ", EXPECTED: " << EXPECTED_RESULT << std::endl;
std::cout << "[";
}
Expand All @@ -453,7 +480,7 @@ int test_noteserial_arduino_transmit_invokes_hardware_serial_flush_when_flush_pa
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialFlush_Parameters.invoked == " << !!hardwareSerialFlush_Parameters.invoked << ", EXPECTED: " << true << std::endl;
std::cout << "[";
}
Expand All @@ -480,7 +507,7 @@ int test_noteserial_arduino_transmit_does_not_invoke_hardware_serial_flush_when_
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\thardwareSerialFlush_Parameters.invoked == " << !!hardwareSerialFlush_Parameters.invoked << ", EXPECTED: " << false << std::endl;
std::cout << "[";
}
Expand Down Expand Up @@ -510,7 +537,7 @@ int test_noteserial_arduino_transmit_does_not_modify_hardware_serial_write_resul
else
{
result = static_cast<int>('s' + 'e' + 'r' + 'i' + 'a' + 'l');
std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl;
std::cout << "\tnoteserial.transmit(reinterpret_cast<uint8_t *>(const_cast<char *>(\"Hello, Test!\")), 13, true) == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl;
std::cout << "[";
}
Expand All @@ -532,6 +559,7 @@ int main(void)
{test_noteserial_arduino_receive_does_not_modify_hardware_serial_read_result_value_before_returning_to_caller, "test_noteserial_arduino_receive_does_not_modify_hardware_serial_read_result_value_before_returning_to_caller"},
{test_noteserial_arduino_reset_invokes_hardware_serial_begin, "test_noteserial_arduino_reset_invokes_hardware_serial_begin"},
{test_noteserial_arduino_reset_invokes_hardware_serial_begin_with_the_baud_parameter_that_was_originally_supplied_to_the_constructor, "test_noteserial_arduino_reset_invokes_hardware_serial_begin_with_the_baud_parameter_that_was_originally_supplied_to_the_constructor"},
{test_noteserial_arduino_reset_invokes_hardware_serial_end, "test_noteserial_arduino_reset_invokes_hardware_serial_end"},
{test_noteserial_arduino_reset_always_returns_true, "test_noteserial_arduino_reset_always_returns_true"},
{test_noteserial_arduino_transmit_invokes_hardware_serial_write, "test_noteserial_arduino_transmit_invokes_hardware_serial_write"},
{test_noteserial_arduino_transmit_does_not_modify_buffer_parameter_value_before_passing_to_hardware_serial_write, "test_noteserial_arduino_transmit_does_not_modify_buffer_parameter_value_before_passing_to_hardware_serial_write"},
Expand Down
Loading

0 comments on commit ae1a122

Please sign in to comment.