diff --git a/.github/actions/compile-examples/Dockerfile b/.github/actions/compile-examples/Dockerfile index 998fbd8..4315868 100644 --- a/.github/actions/compile-examples/Dockerfile +++ b/.github/actions/compile-examples/Dockerfile @@ -9,7 +9,7 @@ # docker run --entrypoint bash --interactive --rm --tty --volume "$(pwd)":/host-volume/ --workdir /host-volume/ arduino-cli # Define global arguments -ARG ARDUINO_CLI_VERSION=0.22.0 +ARG ARDUINO_CLI_VERSION=0.23.0 ARG DEBIAN_FRONTEND="noninteractive" ARG UID=1000 ARG USER="blues" @@ -52,6 +52,7 @@ RUN ["dash", "-c", "\ apt-get update --quiet \ && apt-get install --assume-yes --no-install-recommends --quiet \ bash \ + bash-completion \ ca-certificates \ curl \ python-is-python3 \ @@ -70,14 +71,15 @@ RUN ["dash", "-c", "\ # Download/Install Arduino CLI RUN ["dash", "-c", "\ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=${BINDIR} sh -s ${ARDUINO_CLI_VERSION} \ -# && arduino-cli completion bash > /usr/share/bash-completion/completions/arduino-cli.sh \ && mkdir -p /etc/bash_completion.d/ \ && arduino-cli completion bash > /etc/bash_completion.d/arduino-cli.sh \ && echo >> /etc/bash.bashrc \ -# && echo \"for bcfile in /usr/share/bash-completion/completions/* ; do\" >> /etc/bash.bashrc \ -# && echo \"for bcfile in /etc/bash_completion.d/* ; do\" >> /etc/bash.bashrc \ -# && echo \" [ -f \\\"${ECHO_BC_FILE}\\\" ] && . \\\"${ECHO_BC_FILE}\\\"\" >> /etc/bash.bashrc \ -# && echo \"done\" >> /etc/bash.bashrc \ + && echo \"for bcfile in /etc/bash_completion.d/* ; do\" >> /etc/bash.bashrc \ + && echo \" [ -f \\\"${ECHO_BC_FILE}\\\" ] && . \\\"${ECHO_BC_FILE}\\\"\" >> /etc/bash.bashrc \ + && echo \"done\" >> /etc/bash.bashrc \ + && echo \"if [ -f /etc/bash_completion ]; then\" >> /etc/bash.bashrc \ + && echo \" . /etc/bash_completion\" >> /etc/bash.bashrc \ + && echo \"fi\" >> /etc/bash.bashrc \ "] # Configure Arduino CLI diff --git a/.github/actions/run-tests-in-container/Dockerfile b/.github/actions/run-tests-in-container/Dockerfile index f1eeed3..1cc4bbf 100644 --- a/.github/actions/run-tests-in-container/Dockerfile +++ b/.github/actions/run-tests-in-container/Dockerfile @@ -14,6 +14,7 @@ FROM alpine:3.14 RUN ["ash", "-c", "\ apk add --no-cache \ g++ \ + gdb \ valgrind \ "] diff --git a/.gitignore b/.gitignore index 2280c6c..9cca623 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ -.vscode/ .DS_Store *.gch *.out *.gcda *.gcno *.gcov +vgcore.* coverage/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c537547 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,78 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Failed Unit-tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/failed_test_run", + "args": [], + "cwd": "${workspaceRoot}", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + { + "name": "Debug Notecard Unit-tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/notecard.tests", + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "Compile Notecard Tests", + "postDebugTask": "Clear Test Binaries", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + { + "name": "Debug NoteI2c Arduino Unit-tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/notei2c_arduino.tests", + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "Compile NoteI2c Arduino Tests", + "postDebugTask": "Clear Test Binaries", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + { + "name": "Debug NoteI2c Arduino Unit-tests (-DWIRE_HAS_END)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/notei2c_arduino_wire_has_end.tests", + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "Compile NoteI2c Arduino Tests (-DWIRE_HAS_END)", + "postDebugTask": "Clear Test Binaries", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + { + "name": "Debug NoteLog Arduino Unit-tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/notelog_arduino.tests", + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "Compile NoteLog Arduino Tests", + "postDebugTask": "Clear Test Binaries", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + { + "name": "Debug NoteSerial Arduino Unit-tests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/noteserial_arduino.tests", + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "Compile NoteSerial Arduino Tests", + "postDebugTask": "Clear Test Binaries", + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb" + }, + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..98b6ff6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,191 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "Compile and Run ALL Tests", + "command": "./test/run_all_tests.sh", + "args": [], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "cppbuild", + "label": "Compile Notecard Tests", + "command": "g++", + "args": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "test/mock/mock-arduino.cpp", + "test/mock/mock-note-c-note.c", + "test/mock/NoteI2c_Mock.cpp", + "test/mock/NoteLog_Mock.cpp", + "test/mock/NoteSerial_Mock.cpp", + "src/Notecard.cpp", + "test/Notecard.test.cpp", + "-std=c++11", + "-Itest", + "-Isrc", + "-DNOTE_MOCK", + "-o", + "notecard.tests", + "-g", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "cppbuild", + "label": "Compile NoteI2c Arduino Tests", + "command": "g++", + "args": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "test/mock/mock-arduino.cpp", + "test/mock/mock-note-c-note.c", + "src/NoteI2c_Arduino.cpp", + "test/NoteI2c_Arduino.test.cpp", + "-std=c++11", + "-Itest", + "-Isrc", + "-DNOTE_MOCK", + "-o", + "notei2c_arduino.tests", + "-g", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "cppbuild", + "label": "Compile NoteI2c Arduino Tests (-DWIRE_HAS_END)", + "command": "g++", + "args": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "test/mock/mock-arduino.cpp", + "test/mock/mock-note-c-note.c", + "src/NoteI2c_Arduino.cpp", + "test/NoteI2c_Arduino.test.cpp", + "-std=c++11", + "-Itest", + "-Isrc", + "-DNOTE_MOCK", + "-DWIRE_HAS_END", + "-o", + "notei2c_arduino_wire_has_end.tests", + "-g", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "cppbuild", + "label": "Compile NoteLog Arduino Tests", + "command": "g++", + "args": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "test/mock/mock-arduino.cpp", + "test/mock/mock-note-c-note.c", + "src/NoteLog_Arduino.cpp", + "test/NoteLog_Arduino.test.cpp", + "-std=c++11", + "-Itest", + "-Isrc", + "-DNOTE_MOCK", + "-o", + "notelog_arduino.tests", + "-g", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "cppbuild", + "label": "Compile NoteSerial Arduino Tests", + "command": "g++", + "args": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "test/mock/mock-arduino.cpp", + "test/mock/mock-note-c-note.c", + "src/NoteSerial_Arduino.cpp", + "test/NoteSerial_Arduino.test.cpp", + "-std=c++11", + "-Itest", + "-Isrc", + "-DNOTE_MOCK", + "-o", + "noteserial_arduino.tests", + "-g", + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "shell", + "label": "Clear Test Binaries", + "command": "rm -rf *.tests", + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + }, + ] +} diff --git a/src/Notecard.cpp b/src/Notecard.cpp index 5dfc527..374cefd 100644 --- a/src/Notecard.cpp +++ b/src/Notecard.cpp @@ -42,9 +42,9 @@ #include #include -#include "NoteLog.hpp" -#include "NoteI2c.hpp" -#include "NoteSerial.hpp" +/*************************************************************************** + SINGLETON ABSTRACTION (REQUIRED BY NOTE-C) + ***************************************************************************/ namespace { @@ -139,7 +139,6 @@ void noteSerialTransmit(uint8_t *text_, size_t len_, bool flush_) } } - /*************************************************************************** PRIVATE FUNCTIONS ***************************************************************************/ @@ -163,6 +162,33 @@ extern "C" { } + +/**************************************************************************/ +/*! + @brief Platform Initialization for the Notecard. + This function configures system functions to be used + by the Notecard. + @param assignCallbacks + When `true` the system callbacks will be assigned, + when `false` the system callbacks will be cleared. + @param i2cmax + The max length of each message to send from the host to + the Notecard. Used to ensure the messages are sized appropriately + for the host. + @param wirePort + The TwoWire implementation to use for I2C communication. +*/ +/**************************************************************************/ +void Notecard::platformInit (bool assignCallbacks) +{ + NoteSetUserAgent((char *)"note-arduino"); + if (assignCallbacks) { + NoteSetFnDefault(malloc, free, platform_delay, platform_millis); + } else { + NoteSetFnDefault(nullptr, nullptr, nullptr, nullptr); + } +} + /*************************************************************************** PUBLIC FUNCTIONS ***************************************************************************/ @@ -178,26 +204,29 @@ Notecard::~Notecard (void) /**************************************************************************/ /*! @brief Initialize the Notecard for I2C. - This function configures the Notecard to use the I2C bus - for communication with the host. - @param i2caddress + This function configures the Notecard to use the I2C + bus for communication with the host. + @param noteI2c + A platform specific I2C implementation to use for + communicating with the Notecard from the host. + @param i2cAddress The I2C Address to use for the Notecard. - @param i2cmax - The max length of each message to send from the host to - the Notecard. Used to ensure the messages are sized appropriately - for the host. - @param wirePort - The TwoWire implementation to use for I2C communication. + @param i2cMax + The max length of each message to send from the host + to the Notecard. Used to ensure the messages are sized + appropriately for the host. */ /**************************************************************************/ -void Notecard::begin(uint32_t i2caddress, uint32_t i2cmax, TwoWire &wirePort) +void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_) { - NoteSetUserAgent((char *)"note-arduino"); - NoteSetFnDefault(malloc, free, platform_delay, platform_millis); - noteI2c = make_note_i2c(&wirePort); - - NoteSetFnI2C(i2caddress, i2cmax, noteI2cReset, - noteI2cTransmit, noteI2cReceive); + noteI2c = noteI2c_; + platformInit(noteI2c); + if (noteI2c) { + NoteSetFnI2C(i2cAddress_, i2cMax_, noteI2cReset, + noteI2cTransmit, noteI2cReceive); + } else { + NoteSetFnI2C(0, 0, nullptr, nullptr, nullptr); + } } /**************************************************************************/ @@ -205,37 +234,43 @@ void Notecard::begin(uint32_t i2caddress, uint32_t i2cmax, TwoWire &wirePort) @brief Initialize the Notecard for Serial communication. This function configures the Notecard to use Serial for communication with the host. - @param selectedSerialPort - The HardwareSerial bus to use. - @param selectedSpeed - The baud rate to use for communicating with the Notecard - from the host. + @param noteSerial + A platform specific serial implementation to use for + communicating with the Notecard from the host. */ /**************************************************************************/ -void Notecard::begin(HardwareSerial &selectedSerialPort, int selectedSpeed) +void Notecard::begin(NoteSerial * noteSerial_) { - NoteSetUserAgent((char *)"note-arduino"); - NoteSetFnDefault(malloc, free, platform_delay, platform_millis); - noteSerial = make_note_serial(&selectedSerialPort, selectedSpeed); - - NoteSetFnSerial(noteSerialReset, noteSerialTransmit, - noteSerialAvailable, noteSerialReceive); + noteSerial = noteSerial_; + platformInit(noteSerial); + if (noteSerial) { + NoteSetFnSerial(noteSerialReset, noteSerialTransmit, + noteSerialAvailable, noteSerialReceive); + } else { + NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr); + } } /**************************************************************************/ /*! @brief Set the debug output source. - This function takes a Stream object (for example, `Serial`) - and configures it as a source for writing debug messages - during development. - @param dbgserial - The Stream object to use for debug output. + A NoteLog object will be constructed via `make_note_log()` + using a platform specific logging channel (for example, `Serial` + on Arduino). The specified channel will be configured as the + source for debug messages provided to `notecard.logDebug()`. + @param noteLog + A platform specific log implementation to be used for + debug output. */ /**************************************************************************/ -void Notecard::setDebugOutputStream(Stream &dbgserial) +void Notecard::setDebugOutputStream(NoteLog * noteLog_) { - noteLog = make_note_log(&dbgserial); - NoteSetFnDebugOutput(noteLogPrint); + noteLog = noteLog_; + if (noteLog) { + NoteSetFnDebugOutput(noteLogPrint); + } else { + NoteSetFnDebugOutput(nullptr); + } } /**************************************************************************/ @@ -243,8 +278,9 @@ void Notecard::setDebugOutputStream(Stream &dbgserial) @brief Clear the debug output source. */ /**************************************************************************/ -void Notecard::clearDebugOutputStream() +void Notecard::clearDebugOutputStream(void) { + noteLog = nullptr; NoteSetFnDebugOutput(nullptr); } @@ -252,7 +288,7 @@ void Notecard::clearDebugOutputStream() /*! @brief Creates a new request object for population by the host. This function accepts a request string (for example, `"note.add"`) - and initializes a JSON Object to return to the host. + and initializes a JSON Object to return to the host. @param request The request name, for example, `note.add`. @return A `J` JSON Object populated with the request name. @@ -267,7 +303,7 @@ J *Notecard::newRequest(const char *request) /*! @brief Creates a new command object for population by the host. This function accepts a command string (for example, `"note.add"`) - and initializes a JSON Object to return to the host. + and initializes a JSON Object to return to the host. @param request The command name, for example, `note.add`. @return A `J` JSON Object populated with the request name. @@ -282,11 +318,11 @@ J *Notecard::newCommand(const char *request) /*! @brief Sends a request to the Notecard. This function takes a populated `J` JSON request object - and sends it to the Notecard. + and sends it to the Notecard. @param req A `J` JSON request object. @return `True` if the message was successfully sent to the Notecard, - `False` if there was an error. + `False` if there was an error. */ /**************************************************************************/ bool Notecard::sendRequest(J *req) @@ -353,13 +389,13 @@ void Notecard::logDebugf(const char *format, ...) /**************************************************************************/ /*! - @brief Periodically show Notecard sync status, - returning TRUE if something was displayed to the debug stream. + @brief Periodically show Notecard sync status, returning `TRUE` + if something was displayed to the debug stream. @param pollFrequencyMs The frequency to poll the Notecard for sync status. - @param maxLevel - The maximum log level to output to the debug console. Pass - -1 for all. + @param maxLevel + The maximum log level to output to the debug console. Pass + -1 for all. @return `True` if a pending response was displayed to the debug stream. */ /**************************************************************************/ diff --git a/src/Notecard.h b/src/Notecard.h index b54c207..44d9126 100644 --- a/src/Notecard.h +++ b/src/Notecard.h @@ -27,9 +27,16 @@ #include #include -#ifndef NOTE_MOCK +#include "NoteI2c.hpp" +#include "NoteLog.hpp" +#include "NoteSerial.hpp" + +#ifdef ARDUINO #include #include +#endif + +#ifndef NOTE_MOCK #include #else #include "mock/mock-arduino.hpp" @@ -46,11 +53,24 @@ class Notecard { public: ~Notecard(void); - void begin(uint32_t i2cAddress = NOTE_I2C_ADDR_DEFAULT, - uint32_t i2cMax = NOTE_I2C_MAX_DEFAULT, - TwoWire &wirePort = Wire); - void begin(HardwareSerial &serial, int speed = 9600); - void setDebugOutputStream(Stream &dbgserial); + void begin(NoteI2c * noteI2c, + uint32_t i2cAddress = NOTE_I2C_ADDR_DEFAULT, + uint32_t i2cMax = NOTE_I2C_MAX_DEFAULT); + void begin(NoteSerial * noteSerial); + void setDebugOutputStream(NoteLog * noteLog); +#ifdef ARDUINO + inline void begin(uint32_t i2cAddress = NOTE_I2C_ADDR_DEFAULT, + uint32_t i2cMax = NOTE_I2C_MAX_DEFAULT, + TwoWire &wirePort = Wire) { + begin(make_note_i2c(&wirePort), i2cAddress, i2cMax); + } + inline void begin(HardwareSerial &serial, uint32_t speed = 9600) { + begin(make_note_serial(&serial, speed)); + } + inline void setDebugOutputStream(Stream &dbgserial) { + setDebugOutputStream(make_note_log(&dbgserial)); + } +#endif void clearDebugOutputStream(void); J *newRequest(const char *request); J *newCommand(const char *request); @@ -61,6 +81,9 @@ class Notecard void logDebugf(const char *format, ...); bool debugSyncStatus(int pollFrequencyMs, int maxLevel); bool responseError(J *rsp); + +private: + void platformInit (bool assignCallbacks); }; #endif diff --git a/src/sleepysignal.ino b/src/sleepysignal.ino new file mode 100644 index 0000000..200b505 --- /dev/null +++ b/src/sleepysignal.ino @@ -0,0 +1,58 @@ +#include + +#define serialDebug Serial + +Notecard notecard; + +void setup() { + serialDebug.begin(115200); + while (!serialDebug); + Serial1.begin(115200); + + notecard.begin(); + notecard.setDebugOutputStream(serialDebug); + + { + J *req = notecard.newRequest("hub.set"); + JAddStringToObject(req, "product", "com.email.you:project"); + JAddStringToObject(req, "mode", "continuous"); + JAddBoolToObject(req, "sync", true); + if (!notecard.sendRequest(req)) { + notecard.logDebug("hub.set failed\n"); + } + } + + notecard.logDebug("\nSetup complete\n"); + +} + +void loop() { + { + J *req = notecard.newRequest("hub.signal"); + J *resp = notecard.requestAndResponse(req); + J *body = JGetObject(resp, "body"); + char *json_string = JConvertToJSONString(body); + JDelete(resp); + if (json_string) { + notecard.logDebugf("Signal: %s\n", json_string); + free(json_string); + // Dequeue all Signals as fast as possible + continue; + } + } + notecard.logDebug("No signal detected\n"); + + { + J *req = notecard.newRequest("card.attn"); + JAddStringToObject(req, "mode", "arm,signal"); + // This should NEVER return + if (!notecard.sendRequest(req)) { + //if resp.err == "" && !resp.Set then a signal has arrived + //continue + } + } + + // Hardware error prevented sleeping + notecard.logDebug("card.attn failed\n"); + delay(1000); +} diff --git a/test/NoteI2c_Arduino.test.cpp b/test/NoteI2c_Arduino.test.cpp index e4a86a2..1d23e33 100644 --- a/test/NoteI2c_Arduino.test.cpp +++ b/test/NoteI2c_Arduino.test.cpp @@ -66,6 +66,7 @@ int test_make_note_i2c_enforces_singleton_by_returning_same_notei2c_object_for_a return result; } +//int test_make_note_i2c_returns_nullptr_when_nullptr_is_passed_as_parameter() int test_make_note_i2c_deletes_singleton_when_nullptr_is_passed_as_parameter() { int result; diff --git a/test/NoteLog_Arduino.test.cpp b/test/NoteLog_Arduino.test.cpp index a43efc2..ea5bc4a 100644 --- a/test/NoteLog_Arduino.test.cpp +++ b/test/NoteLog_Arduino.test.cpp @@ -66,6 +66,7 @@ int test_make_note_log_enforces_singleton_by_returning_same_notelog_object_for_a return result; } +//int test_make_note_log_returns_nullptr_when_nullptr_is_passed_as_parameter() int test_make_note_log_deletes_singleton_when_nullptr_is_passed_as_parameter() { int result; diff --git a/test/NoteSerial_Arduino.test.cpp b/test/NoteSerial_Arduino.test.cpp index 949cfcd..c825fb1 100644 --- a/test/NoteSerial_Arduino.test.cpp +++ b/test/NoteSerial_Arduino.test.cpp @@ -66,6 +66,7 @@ int test_make_note_serial_enforces_singleton_by_returning_same_noteserial_object return result; } +//int test_make_note_serial_returns_nullptr_when_nullptr_is_passed_as_parameter() int test_make_note_serial_deletes_singleton_when_nullptr_is_passed_as_parameter() { int result; diff --git a/test/Notecard.test.cpp b/test/Notecard.test.cpp index baa78d4..2925893 100644 --- a/test/Notecard.test.cpp +++ b/test/Notecard.test.cpp @@ -3,32 +3,105 @@ #include #include -#include "Notecard.h" -#include "NoteI2c_Arduino.hpp" -#include "NoteLog_Arduino.hpp" -#include "NoteSerial_Arduino.hpp" #include "TestFunction.hpp" -#include "mock/mock-arduino.hpp" + +#include "Notecard.h" #include "mock/mock-parameters.hpp" #include "mock/NoteI2c_Mock.hpp" #include "mock/NoteLog_Mock.hpp" #include "mock/NoteSerial_Mock.hpp" -// Compile command: g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp mock/mock-note-c-note.c mock/NoteI2c_Mock.cpp mock/NoteLog_Mock.cpp mock/NoteSerial_Mock.cpp ../src/Notecard.cpp Notecard.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK && ./a.out || echo "Tests Result: $?" +// Compile command: g++ -Wall -Wextra -Wpedantic mock/mock-arduino.cpp mock/mock-note-c-note.c mock/NoteI2c_Mock.cpp mock/NoteLog_Mock.cpp mock/NoteSerial_Mock.cpp ../src/Notecard.cpp Notecard.test.cpp -std=c++11 -I. -I../src -DNOTE_MOCK -o notecard.tests && ./notecard.tests || echo "Tests Result: $?" -int test_notecard_begin_i2c_shares_a_memory_allocation_functon_pointer() +int test_notecard_begin_i2c_sets_user_agent_to_note_arduino() +{ + int result; + + // Arrange + //////////// + + const char * const EXPECTED_USER_AGENT = "note-arduino"; + Notecard notecard; + NoteI2c_Mock mockI2c; + + noteSetUserAgent_Parameters.reset(); + + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// + + if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent_cache.c_str() << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + + static const char * const EXPECTED_USER_AGENT = "note-arduino"; Notecard notecard; + noteSetUserAgent_Parameters.reset(); + + // Action + /////////// + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent_cache.c_str() << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_shares_a_memory_allocation_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnDefault_Parameters.mallocfn) { result = 0; @@ -36,27 +109,66 @@ int test_notecard_begin_i2c_shares_a_memory_allocation_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == " << !!noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == 0x" << std::hex << !!noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_shares_a_memory_free_functon_pointer() +int test_notecard_begin_i2c_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.mallocfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == 0x" << std::hex << noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_shares_a_memory_free_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnDefault_Parameters.freefn) { result = 0; @@ -64,27 +176,66 @@ int test_notecard_begin_i2c_shares_a_memory_free_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDefault_Parameters.freefn == " << !!noteSetFnDefault_Parameters.freefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.freefn == 0x" << std::hex << !!noteSetFnDefault_Parameters.freefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_shares_a_delay_functon_pointer() +int test_notecard_begin_i2c_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.freefn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.freefn == 0x" << std::hex << noteSetFnDefault_Parameters.freefn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_shares_a_delay_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Arrange + //////////// - // Arrange if (noteSetFnDefault_Parameters.delayfn) { result = 0; @@ -92,27 +243,66 @@ int test_notecard_begin_i2c_shares_a_delay_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDefault_Parameters.delayfn == " << !!noteSetFnDefault_Parameters.delayfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.delayfn == 0x" << std::hex << !!noteSetFnDefault_Parameters.delayfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_shares_a_millis_functon_pointer() +int test_notecard_begin_i2c_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + notecard.begin(static_cast(nullptr)); + + // Arrange + //////////// + + if (!noteSetFnDefault_Parameters.delayfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.delayfn == 0x" << std::hex << noteSetFnDefault_Parameters.delayfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_shares_a_millis_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnDefault_Parameters.millisfn) { result = 0; @@ -120,29 +310,69 @@ int test_notecard_begin_i2c_shares_a_millis_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDefault_Parameters.millisfn == " << !!noteSetFnDefault_Parameters.millisfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.millisfn == 0x" << std::hex << !!noteSetFnDefault_Parameters.millisfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_does_not_modify_i2c_address_parameter_before_passing_to_note_c() +int test_notecard_begin_i2c_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.millisfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.millisfn == 0x" << std::hex << noteSetFnDefault_Parameters.millisfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_does_not_modify_i2c_address_parameter_before_passing_to_note_c() +{ + int result; + + // Arrange + //////////// + // 0x1B binary representation => 0001 1011 const uint16_t EXPECTED_ADDRESS = 0x1B; + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); - // Action - notecard.begin(EXPECTED_ADDRESS, 79); + // Action + /////////// + + notecard.begin(&mockI2c, EXPECTED_ADDRESS); + + // Assert + /////////// - // Assert if (EXPECTED_ADDRESS == noteSetFnI2C_Parameters.i2caddr) { result = 0; @@ -150,28 +380,71 @@ int test_notecard_begin_i2c_does_not_modify_i2c_address_parameter_before_passing else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnI2C_Parameters.i2caddr == " << noteSetFnI2C_Parameters.i2caddr << ", EXPECTED: " << EXPECTED_ADDRESS << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.i2caddr == 0x" << std::hex << noteSetFnI2C_Parameters.i2caddr << ", EXPECTED: " << EXPECTED_ADDRESS << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_note_c() +int test_notecard_begin_i2c_sets_i2c_address_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + + // 0x1B binary representation => 0001 1011 + const uint16_t SUPPLIED_ADDRESS = 0x1B; + Notecard notecard; + noteSetFnI2C_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr), SUPPLIED_ADDRESS); + + // Assert + /////////// + + if (!noteSetFnI2C_Parameters.i2caddr) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.i2caddr == 0x" << std::hex << noteSetFnI2C_Parameters.i2caddr << ", EXPECTED: 0x00" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_note_c() +{ + int result; + + // Arrange + //////////// + const uint32_t EXPECTED_RESULT = 79; + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); - // Action - notecard.begin(0x1B, EXPECTED_RESULT); + // Action + /////////// + + notecard.begin(&mockI2c, 0x1B, EXPECTED_RESULT); + + // Assert + /////////// - // Assert if (EXPECTED_RESULT == noteSetFnI2C_Parameters.i2cmax) { result = 0; @@ -179,7 +452,7 @@ int test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_ else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnI2C_Parameters.i2cmax == " << noteSetFnI2C_Parameters.i2cmax << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -187,19 +460,60 @@ int test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_ return result; } -int test_notecard_begin_i2c_shares_an_i2c_reset_functon_pointer() +int test_notecard_begin_i2c_sets_i2c_max_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + + const uint32_t SUPPLIED_VALUE = 79; + Notecard notecard; + noteSetFnI2C_Parameters.reset(); + + // Action + /////////// + notecard.begin(static_cast(nullptr), 0x1B, SUPPLIED_VALUE); + + // Assert + /////////// + + if (!noteSetFnI2C_Parameters.i2cmax) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.i2cmax == " << noteSetFnI2C_Parameters.i2cmax << ", EXPECTED: 0" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_i2c_shares_an_i2c_reset_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnI2C_Parameters.resetfn) { result = 0; @@ -207,27 +521,66 @@ int test_notecard_begin_i2c_shares_an_i2c_reset_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnI2C_Parameters.resetfn == " << !!noteSetFnI2C_Parameters.resetfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.resetfn == 0x" << std::hex << !!noteSetFnI2C_Parameters.resetfn << ", EXPECTED: not 0x0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_shares_an_i2c_transmit_functon_pointer() +int test_notecard_begin_i2c_sets_i2c_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnI2C_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnI2C_Parameters.resetfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.resetfn == 0x" << std::hex << noteSetFnI2C_Parameters.resetfn << ", EXPECTED: 0x0 (`nullptr`)" << std::endl; + std::cout << "["; + } + return result; +} + +int test_notecard_begin_i2c_shares_an_i2c_transmit_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnI2C_Parameters.transmitfn) { result = 0; @@ -235,27 +588,66 @@ int test_notecard_begin_i2c_shares_an_i2c_transmit_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnI2C_Parameters.transmitfn == " << !!noteSetFnI2C_Parameters.transmitfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.transmitfn == 0x" << std::hex << !!noteSetFnI2C_Parameters.transmitfn << ", EXPECTED: not 0x0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_shares_an_i2c_receive_functon_pointer() +int test_notecard_begin_i2c_sets_i2c_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnI2C_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnI2C_Parameters.transmitfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.transmitfn == 0x" << std::hex << noteSetFnI2C_Parameters.transmitfn << ", EXPECTED: 0x0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} +int test_notecard_begin_i2c_shares_an_i2c_receive_functon_pointer() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); - // Action - notecard.begin(0x1B, 79); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (noteSetFnI2C_Parameters.receivefn) { result = 0; @@ -263,28 +655,67 @@ int test_notecard_begin_i2c_shares_an_i2c_receive_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnI2C_Parameters.receivefn == " << !!noteSetFnI2C_Parameters.receivefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.receivefn == 0x" << std::hex << !!noteSetFnI2C_Parameters.receivefn << ", EXPECTED: not 0x0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c() +int test_notecard_begin_i2c_sets_i2c_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnI2C_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnI2C_Parameters.receivefn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.receivefn == 0x" << std::hex << noteSetFnI2C_Parameters.receivefn << ", EXPECTED: 0x0 (`nullptr`)" << std::endl; + std::cout << "["; + } + return result; +} + +int test_notecard_begin_i2c_default_parameter_for_i2cMax_is_passed_to_note_c() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); noteSetFnI2C_Parameters.i2cmax = (NOTE_I2C_MAX_DEFAULT - 1); - // Action - notecard.begin(0x1B); + // Action + /////////// + + notecard.begin(&mockI2c, 0x1B); + + // Assert + /////////// - // Assert if (NOTE_I2C_MAX_DEFAULT == noteSetFnI2C_Parameters.i2cmax) { result = 0; @@ -292,7 +723,7 @@ int test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnI2C_Parameters.i2cmax == " << noteSetFnI2C_Parameters.i2cmax << ", EXPECTED: " << NOTE_I2C_MAX_DEFAULT << std::endl; std::cout << "["; } @@ -300,20 +731,26 @@ int test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c() return result; } -int test_notecard_begin_i2c_default_parameter_for_i2c_address_is_passed_to_note_c() +int test_notecard_begin_i2c_default_parameter_for_i2cAddress_is_passed_to_note_c() { int result; - // Arrange - Notecard notecard; + // Arrange + //////////// + Notecard notecard; + NoteI2c_Mock mockI2c; noteSetFnI2C_Parameters.reset(); noteSetFnI2C_Parameters.i2caddr = (NOTE_I2C_ADDR_DEFAULT - 1); - // Action - notecard.begin(); + // Action + /////////// + + notecard.begin(&mockI2c); + + // Assert + /////////// - // Assert if (NOTE_I2C_ADDR_DEFAULT == noteSetFnI2C_Parameters.i2caddr) { result = 0; @@ -321,122 +758,144 @@ int test_notecard_begin_i2c_default_parameter_for_i2c_address_is_passed_to_note_ else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnI2C_Parameters.i2caddr == " << noteSetFnI2C_Parameters.i2caddr << ", EXPECTED: " << NOTE_I2C_ADDR_DEFAULT << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnI2C_Parameters.i2caddr == 0x" << std::hex << noteSetFnI2C_Parameters.i2caddr << ", EXPECTED: 0x" << std::hex << NOTE_I2C_ADDR_DEFAULT << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_default_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wire() +int test_notecard_begin_serial_sets_user_agent_to_note_arduino() { int result; - // Arrange + // Arrange + //////////// + + static const char * const EXPECTED_USER_AGENT = "note-arduino"; Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetUserAgent_Parameters.reset(); + + // Action + /////////// - make_note_i2c_Parameters.reset(); + notecard.begin(&mockSerial); - // Action - notecard.begin(); + // Assert + /////////// - // Assert - if (&Wire == make_note_i2c_Parameters.i2c_bus) + if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tmake_note_i2c_Parameters.i2c_bus == " << !!make_note_i2c_Parameters.i2c_bus << ", EXPECTED: " << &Wire << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent_cache.c_str() << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wirePort() +int test_notecard_begin_serial_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + + static const char * const EXPECTED_USER_AGENT = "note-arduino"; Notecard notecard; - TwoWire mockWire; + noteSetUserAgent_Parameters.reset(); + + // Action + /////////// - make_note_i2c_Parameters.reset(); + notecard.begin(static_cast(nullptr)); - // Action - notecard.begin(NOTE_I2C_ADDR_DEFAULT, NOTE_I2C_MAX_DEFAULT, mockWire); + // Assert + /////////// - // Assert - if (&mockWire == make_note_i2c_Parameters.i2c_bus) + if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tmake_note_i2c_Parameters.i2c_bus == " << make_note_i2c_Parameters.i2c_bus << ", EXPECTED: " << &mockWire << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent_cache.c_str() << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_i2c_sets_user_agent_to_note_arduino() +int test_notecard_begin_serial_shares_a_memory_allocation_functon_pointer() { int result; - // Arrange - const char * const EXPECTED_USER_AGENT = "note-arduino"; + // Arrange + //////////// + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetFnDefault_Parameters.reset(); - noteSetUserAgent_Parameters.reset(); + // Action + /////////// - // Action - notecard.begin(); + notecard.begin(&mockSerial); - // Assert - if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) + // Assert + /////////// + + if (noteSetFnDefault_Parameters.mallocfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == " << !!noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_serial_shares_a_memory_allocation_functon_pointer() +int test_notecard_begin_serial_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange - Notecard notecard; + // Arrange + //////////// + Notecard notecard; noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(Serial, 9600); + // Action + /////////// - // Assert - if (noteSetFnDefault_Parameters.mallocfn) + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.mallocfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == " << !!noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.mallocfn == 0x" << std::hex << noteSetFnDefault_Parameters.mallocfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -447,15 +906,21 @@ int test_notecard_begin_serial_shares_a_memory_free_functon_pointer() { int result; - // Arrange - Notecard notecard; + // Arrange + //////////// + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(Serial, 9600); + // Action + /////////// + + notecard.begin(&mockSerial); + + // Assert + /////////// - // Assert if (noteSetFnDefault_Parameters.freefn) { result = 0; @@ -463,7 +928,7 @@ int test_notecard_begin_serial_shares_a_memory_free_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnDefault_Parameters.freefn == " << !!noteSetFnDefault_Parameters.freefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -471,19 +936,58 @@ int test_notecard_begin_serial_shares_a_memory_free_functon_pointer() return result; } -int test_notecard_begin_serial_shares_a_delay_functon_pointer() +int test_notecard_begin_serial_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.freefn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.freefn == 0x" << std::hex << noteSetFnDefault_Parameters.freefn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_serial_shares_a_delay_functon_pointer() +{ + int result; + // Arrange + //////////// + + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(Serial, 9600); + // Action + /////////// + + notecard.begin(&mockSerial); + + // Assert + /////////// - // Assert if (noteSetFnDefault_Parameters.delayfn) { result = 0; @@ -491,7 +995,7 @@ int test_notecard_begin_serial_shares_a_delay_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnDefault_Parameters.delayfn == " << !!noteSetFnDefault_Parameters.delayfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -499,27 +1003,66 @@ int test_notecard_begin_serial_shares_a_delay_functon_pointer() return result; } -int test_notecard_begin_serial_shares_a_millis_functon_pointer() +int test_notecard_begin_serial_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.delayfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.delayfn == 0x" << std::hex << noteSetFnDefault_Parameters.delayfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_serial_shares_a_millis_functon_pointer() +{ + int result; + + // Arrange + //////////// + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) noteSetFnDefault_Parameters.reset(); - // Action - notecard.begin(Serial, 9600); + // Action + /////////// + + notecard.begin(&mockSerial); - // Assert - if (nullptr != noteSetFnDefault_Parameters.millisfn) + // Assert + /////////// + + if (noteSetFnDefault_Parameters.millisfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnDefault_Parameters.millisfn == " << !!noteSetFnDefault_Parameters.millisfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -527,19 +1070,58 @@ int test_notecard_begin_serial_shares_a_millis_functon_pointer() return result; } +int test_notecard_begin_serial_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnDefault_Parameters.millisfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDefault_Parameters.millisfn == 0x" << std::hex << noteSetFnDefault_Parameters.millisfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + int test_notecard_begin_serial_shares_a_serial_reset_functon_pointer() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetFnDefault_Parameters.reset(); - noteSetFnSerial_Parameters.reset(); + // Action + /////////// - // Action - notecard.begin(Serial, 9600); + notecard.begin(&mockSerial); + + // Assert + /////////// - // Assert if (noteSetFnSerial_Parameters.resetfn) { result = 0; @@ -547,7 +1129,7 @@ int test_notecard_begin_serial_shares_a_serial_reset_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnSerial_Parameters.resetfn == " << !!noteSetFnSerial_Parameters.resetfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -555,28 +1137,100 @@ int test_notecard_begin_serial_shares_a_serial_reset_functon_pointer() return result; } +int test_notecard_begin_serial_sets_serial_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + noteSetFnSerial_Parameters.reset(); + + // Action + /////////// + + notecard.begin(static_cast(nullptr)); + + // Assert + /////////// + + if (!noteSetFnSerial_Parameters.resetfn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.resetfn == 0x" << std::hex << noteSetFnSerial_Parameters.resetfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + int test_notecard_begin_serial_shares_a_serial_transmit_functon_pointer() { int result; - // Arrange - Notecard notecard; + // Arrange + //////////// + + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// + + notecard.begin(&mockSerial); + + // Assert + /////////// + + if (noteSetFnSerial_Parameters.writefn) + { + result = 0; + } + else + { + result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.writefn == " << !!noteSetFnSerial_Parameters.writefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "["; + } + + return result; +} + +int test_notecard_begin_serial_sets_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() +{ + int result; + + // Arrange + //////////// + + Notecard notecard; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// - noteSetFnSerial_Parameters.reset(); + notecard.begin(static_cast(nullptr)); - // Action - notecard.begin(Serial, 9600); + // Assert + /////////// - // Assert - if (noteSetFnSerial_Parameters.writefn) + if (!noteSetFnSerial_Parameters.writefn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnSerial_Parameters.writefn == " << !!noteSetFnSerial_Parameters.writefn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.writefn == 0x" << std::hex << noteSetFnSerial_Parameters.writefn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -587,15 +1241,21 @@ int test_notecard_begin_serial_shares_a_serial_available_functon_pointer() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetFnDefault_Parameters.reset(); - noteSetFnSerial_Parameters.reset(); + // Action + /////////// + + notecard.begin(&mockSerial); - // Action - notecard.begin(Serial, 9600); + // Assert + /////////// - // Assert if (noteSetFnSerial_Parameters.availfn) { result = 0; @@ -603,7 +1263,7 @@ int test_notecard_begin_serial_shares_a_serial_available_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnSerial_Parameters.availfn == " << !!noteSetFnSerial_Parameters.availfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -611,143 +1271,168 @@ int test_notecard_begin_serial_shares_a_serial_available_functon_pointer() return result; } -int test_notecard_begin_serial_shares_a_serial_receive_functon_pointer() +int test_notecard_begin_serial_sets_serial_available_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; + noteSetFnDefault_Parameters.reset(); - noteSetFnSerial_Parameters.reset(); + // Action + /////////// - // Action - notecard.begin(Serial, 9600); + notecard.begin(static_cast(nullptr)); - // Assert - if (noteSetFnSerial_Parameters.readfn) + // Assert + /////////// + + if (!noteSetFnSerial_Parameters.availfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnSerial_Parameters.readfn == " << !!noteSetFnSerial_Parameters.readfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.availfn == 0x" << std::hex << noteSetFnSerial_Parameters.availfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_serial_initializes_the_provided_serial_interface_with_provided_speed() +int test_notecard_begin_serial_shares_a_serial_receive_functon_pointer() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - const unsigned int EXPECTED_BAUD_RATE = 9600; + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + noteSetFnDefault_Parameters.reset(); - make_note_serial_Parameters.reset(); + // Action + /////////// - // Action - notecard.begin(Serial, EXPECTED_BAUD_RATE); + notecard.begin(&mockSerial); - // Assert - if (EXPECTED_BAUD_RATE == make_note_serial_Parameters.baud_rate) + // Assert + /////////// + + if (noteSetFnSerial_Parameters.readfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tmake_note_serial_Parameters.baud_rate == " << make_note_serial_Parameters.baud_rate << ", EXPECTED: " << EXPECTED_BAUD_RATE << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.readfn == " << !!noteSetFnSerial_Parameters.readfn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_serial_initializes_the_provided_serial_interface_with_default_speed() +int test_notecard_begin_serial_sets_serial_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - const unsigned int EXPECTED_BAUD_RATE = 9600; + noteSetFnDefault_Parameters.reset(); + + // Action + /////////// - make_note_serial_Parameters.reset(); + notecard.begin(static_cast(nullptr)); - // Action - notecard.begin(Serial); + // Assert + /////////// - // Assert - if (EXPECTED_BAUD_RATE == make_note_serial_Parameters.baud_rate) + if (!noteSetFnSerial_Parameters.readfn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tmake_note_serial_Parameters.baud_rate == " << make_note_serial_Parameters.baud_rate << ", EXPECTED: " << EXPECTED_BAUD_RATE << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnSerial_Parameters.readfn == 0x" << std::hex << noteSetFnSerial_Parameters.readfn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_begin_serial_sets_user_agent_to_note_arduino() +int test_notecard_setDebugOutputStream_shares_a_debug_log_functon_pointer() { int result; - // Arrange - const char * const EXPECTED_USER_AGENT = "note-arduino"; + // Arrange + //////////// + Notecard notecard; + NoteLog_Mock mockLog; + noteSetFnDebugOutput_Parameters.reset(); - noteSetUserAgent_Parameters.reset(); + // Action + /////////// - // Action - notecard.begin(Serial); + notecard.setDebugOutputStream(&mockLog); - // Assert - if (noteSetUserAgent_Parameters.agent && !strcmp(EXPECTED_USER_AGENT, noteSetUserAgent_Parameters.agent)) + // Assert + /////////// + + if (noteSetFnDebugOutput_Parameters.fn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetUserAgent_Parameters.agent == " << noteSetUserAgent_Parameters.agent << ", EXPECTED: " << EXPECTED_USER_AGENT << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDebugOutput_Parameters.fn == " << !!noteSetFnDebugOutput_Parameters.fn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; std::cout << "["; } return result; } -int test_notecard_setDebugOutputStream_shares_a_debug_log_functon_pointer() +int test_notecard_setDebugOutputStream_clears_the_debug_log_functon_pointer_when_nullptr_is_provided() { int result; - // Arrange - Notecard notecard; + // Arrange + //////////// + Notecard notecard; noteSetFnDebugOutput_Parameters.reset(); + noteSetFnDebugOutput_Parameters.fn = reinterpret_cast(&result); - // Action - notecard.setDebugOutputStream(Serial); + // Action + /////////// - // Assert - if (noteSetFnDebugOutput_Parameters.fn) + notecard.setDebugOutputStream(nullptr); + + // Assert + /////////// + + if (!noteSetFnDebugOutput_Parameters.fn) { result = 0; } else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteSetFnDebugOutput_Parameters.fn == " << !!noteSetFnDebugOutput_Parameters.fn << ", EXPECTED: not 0 (`nullptr`)" << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteSetFnDebugOutput_Parameters.fn == " << !!noteSetFnDebugOutput_Parameters.fn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -758,16 +1443,22 @@ int test_notecard_clearDebugOutputStream_clears_the_debug_log_functon_pointer() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; noteSetFnDebugOutput_Parameters.reset(); noteSetFnDebugOutput_Parameters.fn = reinterpret_cast(&result); - // Action + // Action + /////////// + notecard.clearDebugOutputStream(); - // Assert + // Assert + /////////// + if (!noteSetFnDebugOutput_Parameters.fn) { result = 0; @@ -775,7 +1466,7 @@ int test_notecard_clearDebugOutputStream_clears_the_debug_log_functon_pointer() else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSetFnDebugOutput_Parameters.fn == " << !!noteSetFnDebugOutput_Parameters.fn << ", EXPECTED: 0 (`nullptr`)" << std::endl; std::cout << "["; } @@ -787,16 +1478,22 @@ int test_notecard_newRequest_does_not_modify_string_parameter_value_before_passi { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const char * const EXPECTED_RESULT = "Hello, Test!"; noteNewRequest_Parameters.reset(); - // Action + // Action + /////////// + notecard.newRequest(EXPECTED_RESULT); - // Assert + // Assert + /////////// + if (!strcmp(EXPECTED_RESULT, noteNewRequest_Parameters.request_cache.c_str())) { result = 0; @@ -804,7 +1501,7 @@ int test_notecard_newRequest_does_not_modify_string_parameter_value_before_passi else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteNewRequest_Parameters.request_cache.c_str() == \"" << noteNewRequest_Parameters.request_cache.c_str() << "\", EXPECTED: \"" << EXPECTED_RESULT << "\"" << std::endl; std::cout << "["; } @@ -816,7 +1513,9 @@ int test_notecard_newRequest_does_not_modify_note_c_result_value_before_returnin { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J * const EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); assert(nullptr != EXPECTED_JSON); @@ -829,10 +1528,14 @@ int test_notecard_newRequest_does_not_modify_note_c_result_value_before_returnin memcpy(noteNewRequest_Parameters.result, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (noteNewRequest_Parameters.result = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + const J * const ACTUAL_RESULT = notecard.newRequest(nullptr); - // Assert + // Assert + /////////// + if (!memcmp(ACTUAL_RESULT, EXPECTED_JSON, sizeof(J)) /*JCompare(EXPECTED_JSON, json_result, false)*/) { result = 0; @@ -840,7 +1543,7 @@ int test_notecard_newRequest_does_not_modify_note_c_result_value_before_returnin else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.newRequest(nullptr) != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -854,7 +1557,9 @@ int test_notecard_sendRequest_does_not_modify_j_object_parameter_value_before_pa { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J * EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); J * json_cpy; @@ -868,10 +1573,14 @@ int test_notecard_sendRequest_does_not_modify_j_object_parameter_value_before_pa memcpy(json_cpy, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (json_cpy = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + notecard.sendRequest(json_cpy); - // Assert + // Assert + /////////// + if (!memcmp(EXPECTED_JSON, noteRequest_Parameters.req, sizeof(J)) /*JCompare(EXPECTED_JSON, noteSendRequest_Parameters.req, false)*/) { result = 0; @@ -879,7 +1588,7 @@ int test_notecard_sendRequest_does_not_modify_j_object_parameter_value_before_pa else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteRequest_Parameters.req != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -893,17 +1602,23 @@ int test_notecard_sendRequest_does_not_modify_note_c_result_value_before_returni { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const bool EXPECTED_RESULT = true; noteRequest_Parameters.reset(); noteRequest_Parameters.result = EXPECTED_RESULT; - // Action + // Action + /////////// + const bool ACTUAL_RESULT = notecard.sendRequest(nullptr); - // Assert + // Assert + /////////// + if (EXPECTED_RESULT == ACTUAL_RESULT) { result = 0; @@ -911,7 +1626,7 @@ int test_notecard_sendRequest_does_not_modify_note_c_result_value_before_returni else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.sendRequest(nullptr) == \"" << ACTUAL_RESULT << "\", EXPECTED: \"" << EXPECTED_RESULT << "\"" << std::endl; std::cout << "["; } @@ -923,7 +1638,9 @@ int test_notecard_requestAndResponse_does_not_modify_j_object_parameter_value_be { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J *EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); J *json_cpy; @@ -937,10 +1654,14 @@ int test_notecard_requestAndResponse_does_not_modify_j_object_parameter_value_be memcpy(json_cpy, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (json_cpy = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + notecard.requestAndResponse(json_cpy); - // Assert + // Assert + /////////// + if (!memcmp(EXPECTED_JSON, noteRequestResponse_Parameters.req, sizeof(J)) /*JCompare(EXPECTED_JSON, noteRequestResponse_Parameters.req, false)*/) { result = 0; @@ -948,7 +1669,7 @@ int test_notecard_requestAndResponse_does_not_modify_j_object_parameter_value_be else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteRequestResponse_Parameters.req != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -962,7 +1683,9 @@ int test_notecard_requestAndResponse_does_not_modify_note_c_result_value_before_ { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J * EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); assert(nullptr != EXPECTED_JSON); @@ -975,10 +1698,14 @@ int test_notecard_requestAndResponse_does_not_modify_note_c_result_value_before_ memcpy(noteRequestResponse_Parameters.result, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (noteRequestResponse_Parameters.result = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + const J * const ACTUAL_RESULT = notecard.requestAndResponse(nullptr); - // Assert + // Assert + /////////// + if (!memcmp(EXPECTED_JSON, ACTUAL_RESULT, sizeof(J)) /*JCompare(EXPECTED_JSON, json_result, false)*/) { result = 0; @@ -986,7 +1713,7 @@ int test_notecard_requestAndResponse_does_not_modify_note_c_result_value_before_ else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.requestAndResponse(nullptr) != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -1000,16 +1727,22 @@ int test_notecard_deleteResponse_does_not_modify_j_object_parameter_pointer_befo { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J *const EXPECTED_POINTER = reinterpret_cast(0x19790917); noteDeleteResponse_Parameters.reset(); - // Action + // Action + /////////// + notecard.deleteResponse(EXPECTED_POINTER); - // Assert + // Assert + /////////// + if (EXPECTED_POINTER == noteDeleteResponse_Parameters.response) { result = 0; @@ -1017,7 +1750,7 @@ int test_notecard_deleteResponse_does_not_modify_j_object_parameter_pointer_befo else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteDeleteResponse_Parameters.response == " << std::hex << noteDeleteResponse_Parameters.response << ", EXPECTED: " << EXPECTED_POINTER << std::endl; std::cout << "["; } @@ -1029,16 +1762,22 @@ int test_notecard_logDebug_does_not_modify_string_parameter_value_before_passing { int result; - // Arrange + // Arrange + //////////// + const char str[] = "Hello, Test!"; Notecard notecard; noteDebug_Parameters.reset(); - // Action + // Action + /////////// + notecard.logDebug(str); - // Assert + // Assert + /////////// + if (!strcmp(str, noteDebug_Parameters.message_cache.c_str())) { result = 0; @@ -1046,7 +1785,7 @@ int test_notecard_logDebug_does_not_modify_string_parameter_value_before_passing else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteDebug_Parameters.message_cache.c_str() == \"" << noteDebug_Parameters.message_cache.c_str() << "\", EXPECTED: \"" << str << "\"" << std::endl; std::cout << "["; } @@ -1058,16 +1797,22 @@ int test_notecard_logDebugf_does_not_modify_string_parameter_value_before_passin { int result; - // Arrange + // Arrange + //////////// + const char str[] = "Hello, Test 123!"; Notecard notecard; noteDebug_Parameters.reset(); - // Action + // Action + /////////// + notecard.logDebugf("Hello, %s %d%c", "Test", 123, '!'); - // Assert + // Assert + /////////// + if (!strcmp(str, noteDebug_Parameters.message_cache.c_str())) { result = 0; @@ -1075,7 +1820,7 @@ int test_notecard_logDebugf_does_not_modify_string_parameter_value_before_passin else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteDebug_Parameters.message_cache.c_str() == \"" << noteDebug_Parameters.message_cache.c_str() << "\", EXPECTED: \"" << str << "\"" << std::endl; std::cout << "["; } @@ -1087,16 +1832,22 @@ int test_notecard_debugSyncStatus_does_not_modify_pollFrequencyMs_parameter_befo { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const int EXPECTED_RESULT = 79; noteDebugSyncStatus_Parameters.reset(); - // Action + // Action + /////////// + notecard.debugSyncStatus(EXPECTED_RESULT, 0); - // Assert + // Assert + /////////// + if (EXPECTED_RESULT == noteDebugSyncStatus_Parameters.pollFrequencyMs) { result = 0; @@ -1104,7 +1855,7 @@ int test_notecard_debugSyncStatus_does_not_modify_pollFrequencyMs_parameter_befo else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteDebugSyncStatus_Parameters.pollFrequencyMs == " << noteDebugSyncStatus_Parameters.pollFrequencyMs << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -1116,16 +1867,22 @@ int test_notecard_debugSyncStatus_does_not_modify_maxLevel_parameter_before_pass { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const int EXPECTED_RESULT = 79; noteDebugSyncStatus_Parameters.reset(); - // Action + // Action + /////////// + notecard.debugSyncStatus(0, EXPECTED_RESULT); - // Assert + // Assert + /////////// + if (EXPECTED_RESULT == noteDebugSyncStatus_Parameters.maxLevel) { result = 0; @@ -1133,7 +1890,7 @@ int test_notecard_debugSyncStatus_does_not_modify_maxLevel_parameter_before_pass else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteDebugSyncStatus_Parameters.maxLevel == " << noteDebugSyncStatus_Parameters.maxLevel << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -1145,17 +1902,23 @@ int test_notecard_debugSyncStatus_does_not_modify_note_c_result_value_before_ret { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const bool EXPECTED_RESULT = true; noteDebugSyncStatus_Parameters.reset(); noteDebugSyncStatus_Parameters.result = EXPECTED_RESULT; - // Action + // Action + /////////// + const bool ACTUAL_RESULT = notecard.debugSyncStatus(0, 0); - // Assert + // Assert + /////////// + if (EXPECTED_RESULT == ACTUAL_RESULT) { result = 0; @@ -1163,7 +1926,7 @@ int test_notecard_debugSyncStatus_does_not_modify_note_c_result_value_before_ret else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.debugSyncStatus(0, 0) == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -1175,7 +1938,9 @@ int test_notecard_responseError_does_not_modify_j_object_parameter_value_before_ { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J * EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); J * json_cpy; @@ -1189,10 +1954,14 @@ int test_notecard_responseError_does_not_modify_j_object_parameter_value_before_ memcpy(json_cpy, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (json_cpy = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + notecard.responseError(json_cpy); - // Assert + // Assert + /////////// + if (!memcmp(EXPECTED_JSON, noteResponseError_Parameters.rsp, sizeof(J)) /*JCompare(EXPECTED_JSON, noteRequestResponse_Parameters.rsp, false)*/) { result = 0; @@ -1200,7 +1969,7 @@ int test_notecard_responseError_does_not_modify_j_object_parameter_value_before_ else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteResponseError_Parameters.rsp != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -1214,17 +1983,23 @@ int test_notecard_responseError_does_not_modify_note_c_result_value_before_retur { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const bool EXPECTED_RESULT = true; noteResponseError_Parameters.reset(); noteResponseError_Parameters.result = EXPECTED_RESULT; - // Action + // Action + /////////// + const bool ACTUAL_RESULT = notecard.responseError(nullptr); - // Assert + // Assert + /////////// + if (EXPECTED_RESULT == ACTUAL_RESULT) { result = 0; @@ -1232,7 +2007,7 @@ int test_notecard_responseError_does_not_modify_note_c_result_value_before_retur else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.responseError(nullptr) == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -1244,16 +2019,22 @@ int test_notecard_newCommand_does_not_modify_string_parameter_value_before_passi { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; const char EXPECTED_RESULT[] = "Hello, Test!"; noteNewCommand_Parameters.reset(); - // Action + // Action + /////////// + notecard.newCommand(EXPECTED_RESULT); - // Assert + // Assert + /////////// + if (!strcmp(EXPECTED_RESULT, noteNewCommand_Parameters.request_cache.c_str())) { result = 0; @@ -1261,7 +2042,7 @@ int test_notecard_newCommand_does_not_modify_string_parameter_value_before_passi else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteNewCommand_Parameters.request_cache.c_str() == \"" << noteNewCommand_Parameters.request_cache.c_str() << "\", EXPECTED: \"" << EXPECTED_RESULT << "\"" << std::endl; std::cout << "["; } @@ -1273,7 +2054,9 @@ int test_notecard_newCommand_does_not_modify_note_c_result_value_before_returnin { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; J * EXPECTED_JSON = reinterpret_cast(malloc(sizeof(J))); // JCreateObject(); assert(nullptr != EXPECTED_JSON); @@ -1286,10 +2069,14 @@ int test_notecard_newCommand_does_not_modify_note_c_result_value_before_returnin memcpy(noteNewCommand_Parameters.result, EXPECTED_JSON, sizeof(J)); } //assert(nullptr != (noteNewCommand_Parameters.result = JDuplicate(EXPECTED_JSON,true))); - // Action + // Action + /////////// + const J * const ACTUAL_RESULT = notecard.newCommand(nullptr); - // Assert + // Assert + /////////// + if (!memcmp(EXPECTED_JSON, ACTUAL_RESULT, sizeof(J)) /*JCompare(EXPECTED_JSON, ACTUAL_RESULT, false)*/) { result = 0; @@ -1297,7 +2084,7 @@ int test_notecard_newCommand_does_not_modify_note_c_result_value_before_returnin else { result = static_cast('n' + 'o' + 't' + 'e' + 'c' + 'a' + 'r' + 'd'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnotecard.newCommand(nullptr) != EXPECTED_JSON" << std::endl; std::cout << "["; } @@ -1311,23 +2098,28 @@ int test_static_callback_note_i2c_receive_invokes_notei2c_receive() { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x17; const uint16_t SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (noteI2cReceive_Parameters.invoked) { result = 0; @@ -1335,7 +2127,7 @@ int test_static_callback_note_i2c_receive_invokes_notei2c_receive() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReceive_Parameters.invoked == " << noteI2cReceive_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -1347,7 +2139,9 @@ int test_static_callback_note_i2c_receive_does_not_modify_device_address_paramet { int result; - // Arrange + // Arrange + //////////// + // 0x1B binary representation => 0001 1011 const uint16_t EXPECTED_ADDRESS = 0x1B; const uint16_t SIZE = 13; @@ -1355,16 +2149,19 @@ int test_static_callback_note_i2c_receive_does_not_modify_device_address_paramet uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(EXPECTED_ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(EXPECTED_ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (EXPECTED_ADDRESS == noteI2cReceive_Parameters.device_address) { result = 0; @@ -1372,7 +2169,7 @@ int test_static_callback_note_i2c_receive_does_not_modify_device_address_paramet else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReceive_Parameters.device_address == " << noteI2cReceive_Parameters.device_address << ", EXPECTED: " << EXPECTED_ADDRESS << std::endl; std::cout << "["; } @@ -1384,23 +2181,28 @@ int test_static_callback_note_i2c_receive_does_not_modify_buffer_parameter_addre { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (response_buffer == noteI2cReceive_Parameters.buffer) { result = 0; @@ -1408,7 +2210,7 @@ int test_static_callback_note_i2c_receive_does_not_modify_buffer_parameter_addre else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << std::hex << "\tnoteI2cReceive_Parameters.buffer == " << noteI2cReceive_Parameters.buffer << ", EXPECTED: " << &response_buffer[0] << std::endl; std::cout << "["; } @@ -1420,23 +2222,28 @@ int test_static_callback_note_i2c_receive_does_not_modify_size_parameter_before_ { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t EXPECTED_SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, EXPECTED_SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(ADDRESS, response_buffer, EXPECTED_SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (EXPECTED_SIZE == noteI2cReceive_Parameters.requested_byte_count) { result = 0; @@ -1444,7 +2251,7 @@ int test_static_callback_note_i2c_receive_does_not_modify_size_parameter_before_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReceive_Parameters.requested_byte_count == " << noteI2cReceive_Parameters.requested_byte_count << ", EXPECTED: " << EXPECTED_SIZE << std::endl; std::cout << "["; } @@ -1456,23 +2263,28 @@ int test_static_callback_note_i2c_receive_does_not_modify_available_parameter_ad { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (&actual_response_size == noteI2cReceive_Parameters.available) { result = 0; @@ -1480,7 +2292,7 @@ int test_static_callback_note_i2c_receive_does_not_modify_available_parameter_ad else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << std::hex << "\tnoteI2cReceive_Parameters.available == " << noteI2cReceive_Parameters.available << ", EXPECTED: " << &actual_response_size << std::endl; std::cout << "["; } @@ -1492,24 +2304,29 @@ int test_static_callback_note_i2c_receive_does_not_modify_interface_method_retur { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; noteI2cReceive_Parameters.reset(); // Clear the structure for testing results noteI2cReceive_Parameters.result = "i2c: fake test error!"; - // Action - const char * const ACTUAL_RESULT = noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + const char * const ACTUAL_RESULT = noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (!strcmp(ACTUAL_RESULT, noteI2cReceive_Parameters.result)) { result = 0; @@ -1517,7 +2334,7 @@ int test_static_callback_note_i2c_receive_does_not_modify_interface_method_retur else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteI2cReceive_Parameters.result << std::endl; std::cout << "["; } @@ -1529,21 +2346,31 @@ int test_static_callback_note_i2c_receive_does_not_call_interface_method_when_in { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t response_buffer[32]; uint32_t actual_response_size; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (!noteI2cReceive_Parameters.invoked) { result = 0; @@ -1551,7 +2378,7 @@ int test_static_callback_note_i2c_receive_does_not_call_interface_method_when_in else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReceive_Parameters.invoked == " << noteI2cReceive_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -1563,7 +2390,9 @@ int test_static_callback_note_i2c_receive_returns_error_message_when_interface_h { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t response_buffer[32]; @@ -1571,14 +2400,22 @@ int test_static_callback_note_i2c_receive_returns_error_message_when_interface_h const char * const EXPECTED_RESULT = "i2c: A call to Notecard::begin() is required. {io}"; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cReceiveFn noteI2cReceive = noteSetFnI2C_Parameters.receivefn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cReceive_Parameters.reset(); // Clear the structure for testing results - // Action - const char * const ACTUAL_RESULT = noteSetFnI2C_Parameters.receivefn(ADDRESS, response_buffer, SIZE, &actual_response_size); + // Action + /////////// + + const char * const ACTUAL_RESULT = noteI2cReceive(ADDRESS, response_buffer, SIZE, &actual_response_size); + + // Assert + /////////// - // Assert if (!strcmp(ACTUAL_RESULT,EXPECTED_RESULT)) { result = 0; @@ -1586,8 +2423,8 @@ int test_static_callback_note_i2c_receive_returns_error_message_when_interface_h else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tACTUAL_RESULT == " << std::string(ACTUAL_RESULT).c_str() << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -1598,20 +2435,25 @@ int test_static_callback_note_i2c_reset_invokes_notei2c_reset() { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x17; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cResetFn noteI2cReset = noteSetFnI2C_Parameters.resetfn; noteI2cReset_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.resetfn(ADDRESS); + // Action + /////////// + + noteI2cReset(ADDRESS); + + // Assert + /////////// - // Assert if (noteI2cReset_Parameters.invoked) { result = 0; @@ -1619,7 +2461,7 @@ int test_static_callback_note_i2c_reset_invokes_notei2c_reset() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReset_Parameters.invoked == " << noteI2cReset_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -1631,21 +2473,26 @@ int test_static_callback_note_i2c_reset_does_not_modify_device_address_parameter { int result; - // Arrange + // Arrange + //////////// + // 0x1B binary representation => 0001 1011 const uint16_t EXPECTED_ADDRESS = 0x1B; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cResetFn noteI2cReset = noteSetFnI2C_Parameters.resetfn; noteI2cReset_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.resetfn(EXPECTED_ADDRESS); + // Action + /////////// + + noteI2cReset(EXPECTED_ADDRESS); + + // Assert + /////////// - // Assert if (EXPECTED_ADDRESS == noteI2cReset_Parameters.device_address) { result = 0; @@ -1653,7 +2500,7 @@ int test_static_callback_note_i2c_reset_does_not_modify_device_address_parameter else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReset_Parameters.device_address == " << noteI2cReset_Parameters.device_address << ", EXPECTED: " << EXPECTED_ADDRESS << std::endl; std::cout << "["; } @@ -1665,21 +2512,26 @@ int test_static_callback_note_i2c_reset_does_not_modify_interface_method_return_ { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cResetFn noteI2cReset = noteSetFnI2C_Parameters.resetfn; noteI2cReset_Parameters.reset(); // Clear the structure for testing results noteI2cReset_Parameters.result = true; - // Action - const bool ACTUAL_RESULT = noteSetFnI2C_Parameters.resetfn(ADDRESS); + // Action + /////////// + + const bool ACTUAL_RESULT = noteI2cReset(ADDRESS); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == noteI2cReset_Parameters.result) { result = 0; @@ -1687,7 +2539,7 @@ int test_static_callback_note_i2c_reset_does_not_modify_interface_method_return_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteI2cReset_Parameters.result << std::endl; std::cout << "["; } @@ -1699,18 +2551,28 @@ int test_static_callback_note_i2c_reset_does_not_call_interface_method_when_inte { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cResetFn noteI2cReset = noteSetFnI2C_Parameters.resetfn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cReset_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.resetfn(ADDRESS); + // Action + /////////// + + noteI2cReset(ADDRESS); + + // Assert + /////////// - // Assert if (!noteI2cReset_Parameters.invoked) { result = 0; @@ -1718,7 +2580,7 @@ int test_static_callback_note_i2c_reset_does_not_call_interface_method_when_inte else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cReset_Parameters.invoked == " << noteI2cReset_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -1730,18 +2592,29 @@ int test_static_callback_note_i2c_reset_returns_false_when_interface_has_not_bee { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cResetFn noteI2cReset = noteSetFnI2C_Parameters.resetfn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cReset_Parameters.reset(); // Clear the structure for testing results + noteI2cReset_Parameters.result = true; // Ensure that if the mock were to be invoked the test would fail - // Action - const bool ACTUAL_RESULT = noteSetFnI2C_Parameters.resetfn(ADDRESS); + // Action + /////////// + + const bool ACTUAL_RESULT = noteI2cReset(ADDRESS); + + // Assert + /////////// - // Assert if (!ACTUAL_RESULT) { result = 0; @@ -1749,7 +2622,7 @@ int test_static_callback_note_i2c_reset_returns_false_when_interface_has_not_bee else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: false (0)" << std::endl; std::cout << "["; } @@ -1761,22 +2634,27 @@ int test_static_callback_note_i2c_transmit_invokes_notei2c_transmit() { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x17; const uint16_t SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + noteI2cTransmit(ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (noteI2cTransmit_Parameters.invoked) { result = 0; @@ -1784,7 +2662,7 @@ int test_static_callback_note_i2c_transmit_invokes_notei2c_transmit() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cTransmit_Parameters.invoked == " << noteI2cTransmit_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -1796,23 +2674,28 @@ int test_static_callback_note_i2c_transmit_does_not_modify_device_address_parame { int result; - // Arrange + // Arrange + //////////// + // 0x1B binary representation => 0001 1011 const uint16_t EXPECTED_ADDRESS = 0x1B; const uint16_t SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.transmitfn(EXPECTED_ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + noteI2cTransmit(EXPECTED_ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (EXPECTED_ADDRESS == noteI2cTransmit_Parameters.device_address) { result = 0; @@ -1820,7 +2703,7 @@ int test_static_callback_note_i2c_transmit_does_not_modify_device_address_parame else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cTransmit_Parameters.device_address == " << noteI2cTransmit_Parameters.device_address << ", EXPECTED: " << EXPECTED_ADDRESS << std::endl; std::cout << "["; } @@ -1832,22 +2715,27 @@ int test_static_callback_note_i2c_transmit_does_not_modify_buffer_parameter_befo { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; uint8_t transmit_buffer[] = "Test Passed!"; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + noteI2cTransmit(ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (!strcmp(reinterpret_cast(transmit_buffer),reinterpret_cast(noteI2cTransmit_Parameters.buffer))) { result = 0; @@ -1855,8 +2743,8 @@ int test_static_callback_note_i2c_transmit_does_not_modify_buffer_parameter_befo else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tnoteI2cTransmit_Parameters.buffer == " << noteI2cTransmit_Parameters.buffer << ", EXPECTED: " << transmit_buffer << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tnoteI2cTransmit_Parameters.buffer == " << noteI2cTransmit_Parameters.buffer_cache.c_str() << ", EXPECTED: " << transmit_buffer << std::endl; std::cout << "["; } @@ -1867,22 +2755,27 @@ int test_static_callback_note_i2c_transmit_does_not_modify_size_parameter_before { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t EXPECTED_SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, EXPECTED_SIZE); + // Action + /////////// + + noteI2cTransmit(ADDRESS, transmit_buffer, EXPECTED_SIZE); + + // Assert + /////////// - // Assert if (EXPECTED_SIZE == noteI2cTransmit_Parameters.size) { result = 0; @@ -1890,7 +2783,7 @@ int test_static_callback_note_i2c_transmit_does_not_modify_size_parameter_before else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cTransmit_Parameters.size == " << noteI2cTransmit_Parameters.size << ", EXPECTED: " << EXPECTED_SIZE << std::endl; std::cout << "["; } @@ -1902,23 +2795,28 @@ int test_static_callback_note_i2c_transmit_does_not_modify_interface_method_retu { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; Notecard notecard; - NoteI2c_Arduino mockI2c_arduino(Wire); // Instantiate NoteI2c (mocked) - make_note_i2c_Parameters.reset(); - make_note_i2c_Parameters.result = &mockI2c_arduino; // Return mocked interface - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; // Instantiate NoteI2c (mocked) + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results noteI2cTransmit_Parameters.result = "i2c: fake test error!"; - // Action - const char * const ACTUAL_RESULT = noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + const char * const ACTUAL_RESULT = noteI2cTransmit(ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (!strcmp(ACTUAL_RESULT, noteI2cTransmit_Parameters.result)) { result = 0; @@ -1926,7 +2824,7 @@ int test_static_callback_note_i2c_transmit_does_not_modify_interface_method_retu else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteI2cTransmit_Parameters.result << std::endl; std::cout << "["; } @@ -1938,20 +2836,30 @@ int test_static_callback_note_i2c_transmit_does_not_call_interface_method_when_i { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + noteI2cTransmit(ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (!noteI2cTransmit_Parameters.invoked) { result = 0; @@ -1959,7 +2867,7 @@ int test_static_callback_note_i2c_transmit_does_not_call_interface_method_when_i else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteI2cTransmit_Parameters == " << noteI2cTransmit_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -1971,21 +2879,31 @@ int test_static_callback_note_i2c_transmit_returns_error_message_when_interface_ { int result; - // Arrange + // Arrange + //////////// + const uint16_t ADDRESS = 0x1B; const uint16_t SIZE = 13; - uint8_t transmit_buffer[32]; + uint8_t transmit_buffer[] = "Transmissible data"; const char * const EXPECTED_RESULT = "i2c: A call to Notecard::begin() is required. {io}"; Notecard notecard; - make_note_i2c_Parameters.reset(); - notecard.begin(); // Provides access to the hidden static callback methods through `note-c` mocks + NoteI2c_Mock mockI2c; + notecard.begin(&mockI2c); // Provides access to the hidden static callback methods through `note-c` mocks + i2cTransmitFn noteI2cTransmit = noteSetFnI2C_Parameters.transmitfn; + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteI2cTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - const char * const ACTUAL_RESULT = noteSetFnI2C_Parameters.transmitfn(ADDRESS, transmit_buffer, SIZE); + // Action + /////////// + + const char * const ACTUAL_RESULT = noteI2cTransmit(ADDRESS, transmit_buffer, SIZE); + + // Assert + /////////// - // Assert if (!strcmp(ACTUAL_RESULT,EXPECTED_RESULT)) { result = 0; @@ -1993,8 +2911,8 @@ int test_static_callback_note_i2c_transmit_returns_error_message_when_interface_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << EXPECTED_RESULT << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\tACTUAL_RESULT == " << std::string(ACTUAL_RESULT).c_str() << ", EXPECTED: " << EXPECTED_RESULT << std::endl; std::cout << "["; } @@ -2005,20 +2923,25 @@ int test_static_callback_note_log_print_invokes_notelog_print() { int result; - // Arrange + // Arrange + //////////// + const char message[] = "Test passed!"; Notecard notecard; - NoteLog_Arduino mockLog_arduino(&Serial); // Instantiate NoteLog (mocked) - make_note_log_Parameters.reset(); - make_note_log_Parameters.result = &mockLog_arduino; // Return mocked interface - notecard.setDebugOutputStream(Serial); // Provides access to the hidden static callback methods through `note-c` mocks - noteLogPrint_Parameters.reset(); // Clear the structure for testing results + NoteLog_Mock mockLog; // Instantiate NoteLog (mocked) + notecard.setDebugOutputStream(&mockLog); // Provides access to the hidden static callback methods through `note-c` mocks + debugOutputFn noteLogPrint = noteSetFnDebugOutput_Parameters.fn; // Capture the internal Notecard log function, `noteLogPrint` + noteLogPrint_Parameters.reset(); // Clear the structure for testing NoteLog::print results + + // Action + /////////// + + noteLogPrint(message); - // Action - noteSetFnDebugOutput_Parameters.fn(message); + // Assert + /////////// - // Assert if (noteLogPrint_Parameters.invoked) { result = 0; @@ -2026,7 +2949,7 @@ int test_static_callback_note_log_print_invokes_notelog_print() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteLogPrint_Parameters.invoked == " << noteLogPrint_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -2038,20 +2961,25 @@ int test_static_callback_note_log_print_does_not_modify_message_parameter_before { int result; - // Arrange + // Arrange + //////////// + const char message[] = "Test passed!"; Notecard notecard; - NoteLog_Arduino mockLog_arduino(&Serial); // Instantiate NoteLog (mocked) - make_note_log_Parameters.reset(); - make_note_log_Parameters.result = &mockLog_arduino; // Return mocked interface - notecard.setDebugOutputStream(Serial); // Provides access to the hidden static callback methods through `note-c` mocks - noteLogPrint_Parameters.reset(); // Clear the structure for testing results + NoteLog_Mock mockLog; // Instantiate NoteLog (mocked) + notecard.setDebugOutputStream(&mockLog); // Provides access to the hidden static callback methods through `note-c` mocks + debugOutputFn noteLogPrint = noteSetFnDebugOutput_Parameters.fn; // Capture the internal Notecard log function, `noteLogPrint` + noteLogPrint_Parameters.reset(); // Clear the structure for testing NoteLog::print results + + // Action + /////////// - // Action - noteSetFnDebugOutput_Parameters.fn(message); + noteLogPrint(message); + + // Assert + /////////// - // Assert if (!strcmp(message, noteLogPrint_Parameters.message)) { result = 0; @@ -2059,7 +2987,7 @@ int test_static_callback_note_log_print_does_not_modify_message_parameter_before else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteLogPrint_Parameters.message == " << noteLogPrint_Parameters.message << ", EXPECTED: " << message << std::endl; std::cout << "["; } @@ -2071,21 +2999,26 @@ int test_static_callback_note_log_print_does_not_modify_interface_method_return_ { int result; - // Arrange + // Arrange + //////////// + const char message[] = "Test passed!"; Notecard notecard; - NoteLog_Arduino mockLog_arduino(&Serial); // Instantiate NoteLog (mocked) - make_note_log_Parameters.reset(); - make_note_log_Parameters.result = &mockLog_arduino; // Return mocked interface - notecard.setDebugOutputStream(Serial); // Provides access to the hidden static callback methods through `note-c` mocks - noteLogPrint_Parameters.reset(); // Clear the structure for testing results + NoteLog_Mock mockLog; // Instantiate NoteLog (mocked) + notecard.setDebugOutputStream(&mockLog); // Provides access to the hidden static callback methods through `note-c` mocks + debugOutputFn noteLogPrint = noteSetFnDebugOutput_Parameters.fn; // Capture the internal Notecard log function, `noteLogPrint` + noteLogPrint_Parameters.reset(); // Clear the structure for testing NoteLog::print results noteLogPrint_Parameters.result = sizeof(message); - // Action - const size_t ACTUAL_RESULT = noteSetFnDebugOutput_Parameters.fn(message); + // Action + /////////// + + const size_t ACTUAL_RESULT = noteLogPrint(message); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == noteLogPrint_Parameters.result) { result = 0; @@ -2093,7 +3026,7 @@ int test_static_callback_note_log_print_does_not_modify_interface_method_return_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteLogPrint_Parameters.result << std::endl; std::cout << "["; } @@ -2105,18 +3038,30 @@ int test_static_callback_note_log_print_does_not_call_interface_method_when_inte { int result; - // Arrange + // Arrange + //////////// + const char message[] = "Test passed!"; Notecard notecard; - make_note_log_Parameters.reset(); - notecard.setDebugOutputStream(Serial); // Provides access to the hidden static callback methods through `note-c` mocks - noteLogPrint_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnDebugOutput_Parameters.fn(message); + // Capture the internal Notecard log function, `noteLogPrint` + NoteLog_Mock mockLog; + notecard.setDebugOutputStream(&mockLog); // Provides access to the internal static callback methods through `note-c` mocks + debugOutputFn noteLogPrint = noteSetFnDebugOutput_Parameters.fn; // Capture the internal Notecard log function, `noteLogPrint` + + // Reset to ensure interface is not instantiated + notecard.setDebugOutputStream(nullptr); + noteLogPrint_Parameters.reset(); // Clear the structure for testing NoteLog::print results + + // Action + /////////// + + noteLogPrint(message); + + // Assert + /////////// - // Assert if (!noteLogPrint_Parameters.invoked) { result = 0; @@ -2124,7 +3069,7 @@ int test_static_callback_note_log_print_does_not_call_interface_method_when_inte else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteLogPrint_Parameters.invoked == " << noteLogPrint_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2136,26 +3081,39 @@ int test_static_callback_note_log_print_returns_false_when_interface_has_not_bee { int result; - // Arrange + // Arrange + //////////// + const char message[] = "Test passed!"; Notecard notecard; - make_note_log_Parameters.reset(); - notecard.setDebugOutputStream(Serial); // Provides access to the hidden static callback methods through `note-c` mocks - noteLogPrint_Parameters.reset(); // Clear the structure for testing results - // Action - const size_t ACTUAL_RESULT = noteSetFnDebugOutput_Parameters.fn(message); + // Capture the internal Notecard log function, `noteLogPrint` + NoteLog_Mock mockLog; + notecard.setDebugOutputStream(&mockLog); // Provides access to the internal static callback methods through `note-c` mocks + debugOutputFn noteLogPrint = noteSetFnDebugOutput_Parameters.fn; // Capture the internal Notecard log function, `noteLogPrint` - // Assert - if (!ACTUAL_RESULT) + // Reset to ensure interface is not instantiated + notecard.setDebugOutputStream(nullptr); + noteLogPrint_Parameters.reset(); // Clear the structure for testing NoteLog::print results + noteLogPrint_Parameters.result = sizeof(message); // Ensure that if the mock were to be invoked the test would fail + + // Action + /////////// + + const size_t ACTUAL_RESULT = noteLogPrint(message); + + // Assert + /////////// + + if (!ACTUAL_RESULT && !noteLogPrint_Parameters.invoked) { result = 0; } else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2167,18 +3125,23 @@ int test_static_callback_note_serial_available_invokes_noteserial_available() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialAvailableFn noteSerialAvailable = noteSetFnSerial_Parameters.availfn; // Capture the internal Notecard serial function, `noteSerialAvailable` noteSerialAvailable_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.availfn(); + // Action + /////////// + + noteSerialAvailable(); + + // Assert + /////////// - // Assert if (noteSerialAvailable_Parameters.invoked) { result = 0; @@ -2186,7 +3149,7 @@ int test_static_callback_note_serial_available_invokes_noteserial_available() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialAvailable_Parameters.invoked == " << noteSerialAvailable_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -2198,19 +3161,24 @@ int test_static_callback_note_serial_available_does_not_modify_interface_method_ { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialAvailableFn noteSerialAvailable = noteSetFnSerial_Parameters.availfn; // Capture the internal Notecard serial function, `noteSerialAvailable` noteSerialAvailable_Parameters.reset(); // Clear the structure for testing results noteSerialAvailable_Parameters.result = true; - // Action - const bool ACTUAL_RESULT = noteSetFnSerial_Parameters.availfn(); + // Action + /////////// + + const bool ACTUAL_RESULT = noteSerialAvailable(); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == noteSerialAvailable_Parameters.result) { result = 0; @@ -2218,7 +3186,7 @@ int test_static_callback_note_serial_available_does_not_modify_interface_method_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteSerialAvailable_Parameters.result << std::endl; std::cout << "["; } @@ -2230,16 +3198,28 @@ int test_static_callback_note_serial_available_does_not_call_interface_method_wh { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialAvailableFn noteSerialAvailable = noteSetFnSerial_Parameters.availfn; // Capture the internal Notecard serial function, `noteSerialAvailable` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialAvailable_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.availfn(); + // Action + /////////// + + noteSerialAvailable(); + + // Assert + /////////// - // Assert if (!noteSerialAvailable_Parameters.invoked) { result = 0; @@ -2247,7 +3227,7 @@ int test_static_callback_note_serial_available_does_not_call_interface_method_wh else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialAvailable_Parameters.invoked == " << noteSerialAvailable_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2259,16 +3239,29 @@ int test_static_callback_note_serial_available_returns_false_when_interface_has_ { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialAvailableFn noteSerialAvailable = noteSetFnSerial_Parameters.availfn; // Capture the internal Notecard serial function, `noteSerialAvailable` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialAvailable_Parameters.reset(); // Clear the structure for testing results + noteSerialAvailable_Parameters.result = true; // Ensure that if the mock were to be invoked the test would fail + + // Action + /////////// - // Action - const bool ACTUAL_RESULT = noteSetFnSerial_Parameters.availfn(); + const bool ACTUAL_RESULT = noteSerialAvailable(); + + // Assert + /////////// - // Assert if (!ACTUAL_RESULT) { result = 0; @@ -2276,7 +3269,7 @@ int test_static_callback_note_serial_available_returns_false_when_interface_has_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: false (0)" << std::endl; std::cout << "["; } @@ -2288,18 +3281,23 @@ int test_static_callback_note_serial_receive_invokes_noteserial_receive() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialReceiveFn noteSerialReceive = noteSetFnSerial_Parameters.readfn; // Capture the internal Notecard serial function, `noteSerialReceive` noteSerialReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.readfn(); + // Action + /////////// + + noteSerialReceive(); + + // Assert + /////////// - // Assert if (noteSerialReceive_Parameters.invoked) { result = 0; @@ -2307,7 +3305,7 @@ int test_static_callback_note_serial_receive_invokes_noteserial_receive() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialReceive_Parameters.invoked == " << noteSerialReceive_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -2319,19 +3317,24 @@ int test_static_callback_note_serial_receive_does_not_modify_interface_method_re { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialReceiveFn noteSerialReceive = noteSetFnSerial_Parameters.readfn; // Capture the internal Notecard serial function, `noteSerialReceive` noteSerialReceive_Parameters.reset(); // Clear the structure for testing results noteSerialReceive_Parameters.result = 'Z'; - // Action - const char ACTUAL_RESULT = noteSetFnSerial_Parameters.readfn(); + // Action + /////////// + + const char ACTUAL_RESULT = noteSerialReceive(); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == noteSerialReceive_Parameters.result) { result = 0; @@ -2339,7 +3342,7 @@ int test_static_callback_note_serial_receive_does_not_modify_interface_method_re else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteSerialReceive_Parameters.result << std::endl; std::cout << "["; } @@ -2351,16 +3354,28 @@ int test_static_callback_note_serial_receive_does_not_call_interface_method_when { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialReceiveFn noteSerialReceive = noteSetFnSerial_Parameters.readfn; // Capture the internal Notecard serial function, `noteSerialReceive` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialReceive_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.readfn(); + // Action + /////////// + + noteSerialReceive(); + + // Assert + /////////// - // Assert if (!noteSerialReceive_Parameters.invoked) { result = 0; @@ -2368,7 +3383,7 @@ int test_static_callback_note_serial_receive_does_not_call_interface_method_when else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialReceive_Parameters.invoked == " << noteSerialReceive_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2380,17 +3395,30 @@ int test_static_callback_note_serial_receive_returns_false_when_interface_has_no { int result; - // Arrange - const char EXPECTED_RESULT = '\0'; + // Arrange + //////////// + + static const char EXPECTED_RESULT = '\0'; Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialReceiveFn noteSerialReceive = noteSetFnSerial_Parameters.readfn; // Capture the internal Notecard serial function, `noteSerialReceive` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialReceive_Parameters.reset(); // Clear the structure for testing results + noteSerialReceive_Parameters.result = 'Z'; - // Action - const char ACTUAL_RESULT = noteSetFnSerial_Parameters.readfn(); + // Action + /////////// + + const char ACTUAL_RESULT = noteSerialReceive(); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == EXPECTED_RESULT) { result = 0; @@ -2398,7 +3426,7 @@ int test_static_callback_note_serial_receive_returns_false_when_interface_has_no else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: NULL terminator ('\0')" << std::endl; std::cout << "["; } @@ -2410,18 +3438,23 @@ int test_static_callback_note_serial_reset_invokes_noteserial_reset() { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialResetFn noteSerialReset = noteSetFnSerial_Parameters.resetfn; // Capture the internal Notecard serial function, `noteSerialReset` noteSerialReset_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.resetfn(); + // Action + /////////// + + noteSerialReset(); + + // Assert + /////////// - // Assert if (noteSerialReset_Parameters.invoked) { result = 0; @@ -2429,7 +3462,7 @@ int test_static_callback_note_serial_reset_invokes_noteserial_reset() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialReset_Parameters.invoked == " << noteSerialReset_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -2441,19 +3474,24 @@ int test_static_callback_note_serial_reset_does_not_modify_interface_method_retu { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialResetFn noteSerialReset = noteSetFnSerial_Parameters.resetfn; // Capture the internal Notecard serial function, `noteSerialReset` noteSerialReset_Parameters.reset(); // Clear the structure for testing results noteSerialReset_Parameters.result = true; - // Action - const bool ACTUAL_RESULT = noteSetFnSerial_Parameters.resetfn(); + // Action + /////////// + + const bool ACTUAL_RESULT = noteSerialReset(); + + // Assert + /////////// - // Assert if (ACTUAL_RESULT == noteSerialReset_Parameters.result) { result = 0; @@ -2461,7 +3499,7 @@ int test_static_callback_note_serial_reset_does_not_modify_interface_method_retu else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: " << noteSerialReset_Parameters.result << std::endl; std::cout << "["; } @@ -2473,16 +3511,28 @@ int test_static_callback_note_serial_reset_does_not_call_interface_method_when_i { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialResetFn noteSerialReset = noteSetFnSerial_Parameters.resetfn; // Capture the internal Notecard serial function, `noteSerialReset` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialReset_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.resetfn(); + // Action + /////////// + + noteSerialReset(); + + // Assert + /////////// - // Assert if (!noteSerialReset_Parameters.invoked) { result = 0; @@ -2490,7 +3540,7 @@ int test_static_callback_note_serial_reset_does_not_call_interface_method_when_i else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialReset_Parameters.invoked == " << noteSerialReset_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2502,16 +3552,29 @@ int test_static_callback_note_serial_reset_returns_false_when_interface_has_not_ { int result; - // Arrange + // Arrange + //////////// + Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialResetFn noteSerialReset = noteSetFnSerial_Parameters.resetfn; // Capture the internal Notecard serial function, `noteSerialReset` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialReset_Parameters.reset(); // Clear the structure for testing results + noteSerialReset_Parameters.result = true; + + // Action + /////////// - // Action - const bool ACTUAL_RESULT = noteSetFnSerial_Parameters.resetfn(); + const bool ACTUAL_RESULT = noteSerialReset(); + + // Assert + /////////// - // Assert if (!ACTUAL_RESULT) { result = 0; @@ -2519,7 +3582,7 @@ int test_static_callback_note_serial_reset_returns_false_when_interface_has_not_ else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tACTUAL_RESULT == " << ACTUAL_RESULT << ", EXPECTED: false (0)" << std::endl; std::cout << "["; } @@ -2531,22 +3594,27 @@ int test_static_callback_note_serial_transmit_invokes_noteserial_transmit() { int result; - // Arrange + // Arrange + //////////// + uint8_t text[] = "Test passed!"; - const size_t LEN = sizeof(text); - const bool FLUSH = true; + static const size_t LEN = sizeof(text); + static const bool FLUSH = true; Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialTransmitFn noteSerialTransmit = noteSetFnSerial_Parameters.writefn; // Capture the internal Notecard serial function, `noteSerialTransmit` noteSerialTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.writefn(text, LEN, FLUSH); + // Action + /////////// + + noteSerialTransmit(text, LEN, FLUSH); + + // Assert + /////////// - // Assert if (noteSerialTransmit_Parameters.invoked) { result = 0; @@ -2554,7 +3622,7 @@ int test_static_callback_note_serial_transmit_invokes_noteserial_transmit() else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\noteSerialTransmit_Parameters.invoked == " << noteSerialTransmit_Parameters.invoked << ", EXPECTED: > 0" << std::endl; std::cout << "["; } @@ -2566,22 +3634,27 @@ int test_static_callback_note_serial_transmit_does_not_modify_text_parameter_bef { int result; - // Arrange + // Arrange + //////////// + uint8_t expected_text[] = "Test passed!"; const size_t LEN = sizeof(expected_text); const bool FLUSH = true; Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialTransmitFn noteSerialTransmit = noteSetFnSerial_Parameters.writefn; // Capture the internal Notecard serial function, `noteSerialTransmit` noteSerialTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.writefn(expected_text, LEN, FLUSH); + // Action + /////////// + + noteSerialTransmit(expected_text, LEN, FLUSH); + + // Assert + /////////// - // Assert if (!strcmp(reinterpret_cast(expected_text),reinterpret_cast(noteSerialTransmit_Parameters.buffer))) { result = 0; @@ -2589,8 +3662,8 @@ int test_static_callback_note_serial_transmit_does_not_modify_text_parameter_bef else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; - std::cout << "\noteSerialTransmit_Parameters.buffer == " << noteSerialTransmit_Parameters.buffer << ", EXPECTED: " << expected_text << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\noteSerialTransmit_Parameters.buffer == " << std::string(reinterpret_cast(noteSerialTransmit_Parameters.buffer)).c_str() << ", EXPECTED: " << expected_text << std::endl; std::cout << "["; } @@ -2601,22 +3674,27 @@ int test_static_callback_note_serial_transmit_does_not_modify_length_parameter_b { int result; - // Arrange + // Arrange + //////////// + uint8_t text[] = "Test passed!"; const size_t EXPECTED_LEN = sizeof(text); const bool FLUSH = true; Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialTransmitFn noteSerialTransmit = noteSetFnSerial_Parameters.writefn; // Capture the internal Notecard serial function, `noteSerialTransmit` noteSerialTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.writefn(text, EXPECTED_LEN, FLUSH); + // Action + /////////// + + noteSerialTransmit(text, EXPECTED_LEN, FLUSH); + + // Assert + /////////// - // Assert if (EXPECTED_LEN == noteSerialTransmit_Parameters.size) { result = 0; @@ -2624,7 +3702,7 @@ int test_static_callback_note_serial_transmit_does_not_modify_length_parameter_b else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\noteSerialTransmit_Parameters.size == " << noteSerialTransmit_Parameters.size << ", EXPECTED: " << EXPECTED_LEN << std::endl; std::cout << "["; } @@ -2636,22 +3714,27 @@ int test_static_callback_note_serial_transmit_does_not_modify_flush_parameter_be { int result; - // Arrange + // Arrange + //////////// + uint8_t text[] = "Test passed!"; const size_t LEN = sizeof(text); const bool EXPECTED_FLUSH = true; Notecard notecard; - NoteSerial_Arduino mockSerial_arduino(Serial,9600); // Instantiate NoteSerial (mocked) - make_note_serial_Parameters.reset(); - make_note_serial_Parameters.result = &mockSerial_arduino; // Return mocked interface - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialTransmitFn noteSerialTransmit = noteSetFnSerial_Parameters.writefn; // Capture the internal Notecard serial function, `noteSerialTransmit` noteSerialTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.writefn(text, LEN, EXPECTED_FLUSH); + // Action + /////////// + + noteSerialTransmit(text, LEN, EXPECTED_FLUSH); + + // Assert + /////////// - // Assert if (EXPECTED_FLUSH == noteSerialTransmit_Parameters.flush) { result = 0; @@ -2659,7 +3742,7 @@ int test_static_callback_note_serial_transmit_does_not_modify_flush_parameter_be else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\noteSerialTransmit_Parameters.flush == " << noteSerialTransmit_Parameters.flush << ", EXPECTED: " << EXPECTED_FLUSH << std::endl; std::cout << "["; } @@ -2671,20 +3754,32 @@ int test_static_callback_note_serial_transmit_does_not_call_interface_method_whe { int result; - // Arrange + // Arrange + //////////// + uint8_t text[] = "Test passed!"; const size_t LEN = sizeof(text); const bool EXPECTED_FLUSH = true; Notecard notecard; - make_note_serial_Parameters.reset(); - notecard.begin(Serial); // Provides access to the hidden static callback methods through `note-c` mocks + + // Capture the internal Notecard log function, `noteSerialAvailable` + NoteSerial_Mock mockSerial; // Instantiate NoteSerial (mocked) + notecard.begin(&mockSerial); // Provides access to the hidden static callback methods through `note-c` mocks + serialTransmitFn noteSerialTransmit = noteSetFnSerial_Parameters.writefn; // Capture the internal Notecard serial function, `noteSerialTransmit` + + // Reset to ensure the interface is not instantiated + notecard.begin(static_cast(nullptr)); noteSerialTransmit_Parameters.reset(); // Clear the structure for testing results - // Action - noteSetFnSerial_Parameters.writefn(text, LEN, EXPECTED_FLUSH); + // Action + /////////// + + noteSerialTransmit(text, LEN, EXPECTED_FLUSH); + + // Assert + /////////// - // Assert if (!noteSerialTransmit_Parameters.invoked) { result = 0; @@ -2692,7 +3787,7 @@ int test_static_callback_note_serial_transmit_does_not_call_interface_method_whe else { result = static_cast('c' + 'a' + 'l' + 'l' + 'b' + 'a' + 'c' + 'k'); - std::cout << "FAILED] " << __FILE__ << ":" << __LINE__ << std::endl; + std::cout << "\33[31mFAILED\33[0m] " << __FILE__ << ":" << __LINE__ << std::endl; std::cout << "\tnoteSerialTransmit_Parameters.invoked == " << noteSerialTransmit_Parameters.invoked << ", EXPECTED: zero (0)" << std::endl; std::cout << "["; } @@ -2703,32 +3798,48 @@ int test_static_callback_note_serial_transmit_does_not_call_interface_method_whe int main(void) { TestFunction tests[] = { + {test_notecard_begin_i2c_sets_user_agent_to_note_arduino, "test_notecard_begin_i2c_sets_user_agent_to_note_arduino"}, + {test_notecard_begin_i2c_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_a_memory_allocation_functon_pointer, "test_notecard_begin_i2c_shares_a_memory_allocation_functon_pointer"}, + {test_notecard_begin_i2c_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_a_memory_free_functon_pointer, "test_notecard_begin_i2c_shares_a_memory_free_functon_pointer"}, + {test_notecard_begin_i2c_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_a_delay_functon_pointer, "test_notecard_begin_i2c_shares_a_delay_functon_pointer"}, + {test_notecard_begin_i2c_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_a_millis_functon_pointer, "test_notecard_begin_i2c_shares_a_millis_functon_pointer"}, + {test_notecard_begin_i2c_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_does_not_modify_i2c_address_parameter_before_passing_to_note_c, "test_notecard_begin_i2c_does_not_modify_i2c_address_parameter_before_passing_to_note_c"}, + {test_notecard_begin_i2c_sets_i2c_address_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_i2c_address_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_note_c, "test_notecard_begin_i2c_does_not_modify_i2c_max_parameter_before_passing_to_note_c"}, + {test_notecard_begin_i2c_sets_i2c_max_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_i2c_max_parameter_to_zero_before_passing_to_note_c_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_an_i2c_reset_functon_pointer, "test_notecard_begin_i2c_shares_an_i2c_reset_functon_pointer"}, + {test_notecard_begin_i2c_sets_i2c_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_i2c_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_an_i2c_transmit_functon_pointer, "test_notecard_begin_i2c_shares_an_i2c_transmit_functon_pointer"}, + {test_notecard_begin_i2c_sets_i2c_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_i2c_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_i2c_shares_an_i2c_receive_functon_pointer, "test_notecard_begin_i2c_shares_an_i2c_receive_functon_pointer"}, - {test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c, "test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c"}, - {test_notecard_begin_i2c_default_parameter_for_i2c_address_is_passed_to_note_c, "test_notecard_begin_i2c_default_parameter_for_i2c_address_is_passed_to_note_c"}, - {test_notecard_begin_i2c_default_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wire, "test_notecard_begin_i2c_default_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wire"}, - {test_notecard_begin_i2c_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wirePort, "test_notecard_begin_i2c_parameter_for_wirePort_instantiates_the_note_i2c_interface_with_wirePort"}, - {test_notecard_begin_i2c_sets_user_agent_to_note_arduino, "test_notecard_begin_i2c_sets_user_agent_to_note_arduino"}, + {test_notecard_begin_i2c_sets_i2c_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_i2c_sets_i2c_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, + {test_notecard_begin_i2c_default_parameter_for_i2cMax_is_passed_to_note_c, "test_notecard_begin_i2c_default_parameter_for_i2c_max_is_passed_to_note_c"}, + {test_notecard_begin_i2c_default_parameter_for_i2cAddress_is_passed_to_note_c, "test_notecard_begin_i2c_default_parameter_for_i2c_address_is_passed_to_note_c"}, + {test_notecard_begin_serial_sets_user_agent_to_note_arduino, "test_notecard_begin_serial_sets_user_agent_to_note_arduino"}, + {test_notecard_begin_serial_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_user_agent_to_note_arduino_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_memory_allocation_functon_pointer, "test_notecard_begin_serial_shares_a_memory_allocation_functon_pointer"}, + {test_notecard_begin_serial_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_memory_allocation_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_memory_free_functon_pointer, "test_notecard_begin_serial_shares_a_memory_free_functon_pointer"}, + {test_notecard_begin_serial_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_memory_free_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_delay_functon_pointer, "test_notecard_begin_serial_shares_a_delay_functon_pointer"}, + {test_notecard_begin_serial_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_delay_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_millis_functon_pointer, "test_notecard_begin_serial_shares_a_millis_functon_pointer"}, + {test_notecard_begin_serial_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_millis_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_serial_reset_functon_pointer, "test_notecard_begin_serial_shares_a_serial_reset_functon_pointer"}, + {test_notecard_begin_serial_sets_serial_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_serial_reset_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_serial_transmit_functon_pointer, "test_notecard_begin_serial_shares_a_serial_transmit_functon_pointer"}, + {test_notecard_begin_serial_sets_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_transmit_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_serial_available_functon_pointer, "test_notecard_begin_serial_shares_a_serial_available_functon_pointer"}, + {test_notecard_begin_serial_sets_serial_available_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_serial_available_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_begin_serial_shares_a_serial_receive_functon_pointer, "test_notecard_begin_serial_shares_a_serial_receive_functon_pointer"}, - {test_notecard_begin_serial_initializes_the_provided_serial_interface_with_provided_speed, "test_notecard_begin_serial_initializes_the_provided_serial_interface_with_provided_speed"}, - {test_notecard_begin_serial_initializes_the_provided_serial_interface_with_default_speed, "test_notecard_begin_serial_initializes_the_provided_serial_interface_with_default_speed"}, - {test_notecard_begin_serial_sets_user_agent_to_note_arduino, "test_notecard_begin_serial_sets_user_agent_to_note_arduino"}, + {test_notecard_begin_serial_sets_serial_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated, "test_notecard_begin_serial_sets_serial_receive_functon_pointer_to_nullptr_when_interface_has_not_been_instantiated"}, {test_notecard_setDebugOutputStream_shares_a_debug_log_functon_pointer, "test_notecard_setDebugOutputStream_shares_a_debug_log_functon_pointer"}, + {test_notecard_setDebugOutputStream_clears_the_debug_log_functon_pointer_when_nullptr_is_provided, "test_notecard_setDebugOutputStream_clears_the_debug_log_functon_pointer_when_nullptr_is_provided"}, {test_notecard_clearDebugOutputStream_clears_the_debug_log_functon_pointer, "test_notecard_clearDebugOutputStream_clears_the_debug_log_functon_pointer"}, {test_notecard_newRequest_does_not_modify_string_parameter_value_before_passing_to_note_c, "test_notecard_newRequest_does_not_modify_string_parameter_value_before_passing_to_note_c"}, {test_notecard_newRequest_does_not_modify_note_c_result_value_before_returning_to_caller, "test_notecard_newRequest_does_not_modify_note_c_result_value_before_returning_to_caller"}, @@ -2762,15 +3873,15 @@ int main(void) {test_static_callback_note_i2c_transmit_invokes_notei2c_transmit, "test_static_callback_note_i2c_transmit_invokes_notei2c_transmit"}, {test_static_callback_note_i2c_transmit_does_not_modify_device_address_parameter_before_passing_to_interface_method, "test_static_callback_note_i2c_transmit_does_not_modify_device_address_parameter_before_passing_to_interface_method"}, {test_static_callback_note_i2c_transmit_does_not_modify_buffer_parameter_before_passing_to_interface_method, "test_static_callback_note_i2c_transmit_does_not_modify_buffer_parameter_before_passing_to_interface_method"}, - {test_static_callback_note_i2c_transmit_does_not_modify_interface_method_return_value, "test_static_callback_note_i2c_transmit_does_not_modify_interface_method_return_value"}, {test_static_callback_note_i2c_transmit_does_not_modify_size_parameter_before_passing_to_interface_method, "test_static_callback_note_i2c_transmit_does_not_modify_size_parameter_before_passing_to_interface_method"}, + {test_static_callback_note_i2c_transmit_does_not_modify_interface_method_return_value, "test_static_callback_note_i2c_transmit_does_not_modify_interface_method_return_value"}, {test_static_callback_note_i2c_transmit_does_not_call_interface_method_when_interface_has_not_been_instantiated, "test_static_callback_note_i2c_transmit_does_not_call_interface_method_when_interface_has_not_been_instantiated"}, {test_static_callback_note_i2c_transmit_returns_error_message_when_interface_has_not_been_instantiated, "test_static_callback_note_i2c_transmit_returns_error_message_when_interface_has_not_been_instantiated"}, - {test_static_callback_note_log_print_invokes_notelog_print, "test_static_callback_note_i2c_reset_invokes_notei2c_receive"}, + {test_static_callback_note_log_print_invokes_notelog_print, "test_static_callback_note_log_print_invokes_notelog_print"}, {test_static_callback_note_log_print_does_not_modify_message_parameter_before_passing_to_interface_method, "test_static_callback_note_log_print_does_not_modify_message_parameter_before_passing_to_interface_method"}, - {test_static_callback_note_log_print_does_not_modify_interface_method_return_value, "test_static_callback_note_i2c_reset_does_not_modify_interface_method_return_value"}, - {test_static_callback_note_log_print_does_not_call_interface_method_when_interface_has_not_been_instantiated, "test_static_callback_note_i2c_reset_does_not_call_interface_method_when_interface_has_not_been_instantiated"}, - {test_static_callback_note_log_print_returns_false_when_interface_has_not_been_instantiated, "test_static_callback_note_i2c_reset_returns_false_when_interface_has_not_been_instantiated"}, + {test_static_callback_note_log_print_does_not_modify_interface_method_return_value, "test_static_callback_note_log_print_does_not_modify_interface_method_return_value"}, + {test_static_callback_note_log_print_does_not_call_interface_method_when_interface_has_not_been_instantiated, "test_static_callback_note_log_print_does_not_call_interface_method_when_interface_has_not_been_instantiated"}, + {test_static_callback_note_log_print_returns_false_when_interface_has_not_been_instantiated, "test_static_callback_note_log_print_returns_false_when_interface_has_not_been_instantiated"}, {test_static_callback_note_serial_available_invokes_noteserial_available, "test_static_callback_note_serial_available_invokes_noteserial_available"}, {test_static_callback_note_serial_available_does_not_modify_interface_method_return_value, "test_static_callback_note_serial_available_does_not_modify_interface_method_return_value"}, {test_static_callback_note_serial_available_does_not_call_interface_method_when_interface_has_not_been_instantiated, "test_static_callback_note_serial_available_does_not_call_interface_method_when_interface_has_not_been_instantiated"}, diff --git a/test/mock/NoteI2c_Mock.cpp b/test/mock/NoteI2c_Mock.cpp index 6944c6a..0dc9df9 100644 --- a/test/mock/NoteI2c_Mock.cpp +++ b/test/mock/NoteI2c_Mock.cpp @@ -1,7 +1,5 @@ #include "mock/NoteI2c_Mock.hpp" -#include "NoteI2c_Arduino.hpp" - MakeNoteI2c_Parameters make_note_i2c_Parameters; NoteI2cReceive_Parameters noteI2cReceive_Parameters; NoteI2cReset_Parameters noteI2cReset_Parameters; @@ -22,16 +20,8 @@ make_note_i2c ( return make_note_i2c_Parameters.result; } -NoteI2c_Arduino::NoteI2c_Arduino ( - TwoWire & i2c_bus_ -) : - _i2cPort(i2c_bus_) -{ - -} - const char * -NoteI2c_Arduino::receive ( +NoteI2c_Mock::receive ( uint16_t device_address_, uint8_t * buffer_, uint16_t requested_byte_count_, @@ -51,7 +41,7 @@ NoteI2c_Arduino::receive ( } bool -NoteI2c_Arduino::reset ( +NoteI2c_Mock::reset ( uint16_t device_address_ ) { // Record invocation(s) @@ -65,7 +55,7 @@ NoteI2c_Arduino::reset ( } const char * -NoteI2c_Arduino::transmit ( +NoteI2c_Mock::transmit ( uint16_t device_address_, uint8_t * buffer_, uint16_t size_ @@ -76,6 +66,9 @@ NoteI2c_Arduino::transmit ( // Stash parameter(s) noteI2cTransmit_Parameters.device_address = device_address_; noteI2cTransmit_Parameters.buffer = buffer_; + if (buffer_) { + noteI2cTransmit_Parameters.buffer_cache = reinterpret_cast(buffer_); + } noteI2cTransmit_Parameters.size = size_; // Return user-supplied result diff --git a/test/mock/NoteI2c_Mock.hpp b/test/mock/NoteI2c_Mock.hpp index aebdcbc..5c5e12a 100644 --- a/test/mock/NoteI2c_Mock.hpp +++ b/test/mock/NoteI2c_Mock.hpp @@ -1,11 +1,21 @@ -#ifndef MOCK_I2C_ARDUINO_HPP -#define MOCK_I2C_ARDUINO_HPP +#ifndef MOCK_NOTE_I2C_HPP +#define MOCK_NOTE_I2C_HPP #include #include +#include + #include "NoteI2c.hpp" +class NoteI2c_Mock final : public NoteI2c +{ +public: + const char * receive(uint16_t device_address, uint8_t * buffer, uint16_t requested_byte_count, uint32_t * available) override; + bool reset(uint16_t device_address) override; + const char * transmit(uint16_t device_address, uint8_t * buffer, uint16_t size) override; +}; + struct MakeNoteI2c_Parameters { MakeNoteI2c_Parameters( void @@ -43,6 +53,7 @@ struct NoteI2cReceive_Parameters { invoked = 0; device_address = 0; buffer = nullptr; + buffer_cache.clear(); requested_byte_count = 0; available = nullptr; result = nullptr; @@ -50,6 +61,7 @@ struct NoteI2cReceive_Parameters { size_t invoked; uint16_t device_address; uint8_t * buffer; + std::string buffer_cache; uint16_t requested_byte_count; uint32_t * available; const char * result; @@ -91,12 +103,14 @@ struct NoteI2cTransmit_Parameters { invoked = 0; device_address = 0; buffer = nullptr; + buffer_cache.clear(); size = 0; result = nullptr; } size_t invoked; uint16_t device_address; uint8_t * buffer; + std::string buffer_cache; uint16_t size; const char * result; }; @@ -106,4 +120,4 @@ extern NoteI2cReceive_Parameters noteI2cReceive_Parameters; extern NoteI2cReset_Parameters noteI2cReset_Parameters; extern NoteI2cTransmit_Parameters noteI2cTransmit_Parameters; -#endif // MOCK_I2C_ARDUINO_HPP +#endif // MOCK_NOTE_I2C_HPP diff --git a/test/mock/NoteLog_Mock.cpp b/test/mock/NoteLog_Mock.cpp index a8babd1..2722b6a 100644 --- a/test/mock/NoteLog_Mock.cpp +++ b/test/mock/NoteLog_Mock.cpp @@ -1,7 +1,5 @@ #include "mock/NoteLog_Mock.hpp" -#include "NoteLog_Arduino.hpp" - MakeNoteLog_Parameters make_note_log_Parameters; NoteLogPrint_Parameters noteLogPrint_Parameters; @@ -20,16 +18,8 @@ make_note_log ( return make_note_log_Parameters.result; } -NoteLog_Arduino::NoteLog_Arduino ( - Stream * log_stream_ -) : - _notecardLog(log_stream_) -{ - -} - size_t -NoteLog_Arduino::print ( +NoteLog_Mock::print ( const char * message_ ) { diff --git a/test/mock/NoteLog_Mock.hpp b/test/mock/NoteLog_Mock.hpp index 84ba56c..dd16eb1 100644 --- a/test/mock/NoteLog_Mock.hpp +++ b/test/mock/NoteLog_Mock.hpp @@ -1,11 +1,17 @@ -#ifndef MOCK_LOG_ARDUINO_HPP -#define MOCK_LOG_ARDUINO_HPP +#ifndef MOCK_NOTE_LOG_HPP +#define MOCK_NOTE_LOG_HPP #include #include #include "NoteLog.hpp" +class NoteLog_Mock final : public NoteLog +{ +public: + size_t print(const char * message) override; +}; + struct MakeNoteLog_Parameters { MakeNoteLog_Parameters( void @@ -49,4 +55,4 @@ struct NoteLogPrint_Parameters { extern MakeNoteLog_Parameters make_note_log_Parameters; extern NoteLogPrint_Parameters noteLogPrint_Parameters; -#endif // MOCK_LOG_ARDUINO_HPP +#endif // MOCK_NOTE_LOG_HPP diff --git a/test/mock/NoteSerial_Mock.cpp b/test/mock/NoteSerial_Mock.cpp index 8a7f5c3..42871bf 100644 --- a/test/mock/NoteSerial_Mock.cpp +++ b/test/mock/NoteSerial_Mock.cpp @@ -1,7 +1,5 @@ #include "mock/NoteSerial_Mock.hpp" -#include "NoteSerial_Arduino.hpp" - MakeNoteSerial_Parameters make_note_serial_Parameters; NoteSerialAvailable_Parameters noteSerialAvailable_Parameters; NoteSerialReceive_Parameters noteSerialReceive_Parameters; @@ -25,18 +23,8 @@ make_note_serial ( return make_note_serial_Parameters.result; } -NoteSerial_Arduino::NoteSerial_Arduino ( - HardwareSerial & hw_serial_, - size_t baud_rate_ -) : - _notecardSerial(hw_serial_), - _notecardSerialSpeed(baud_rate_) -{ - -} - size_t -NoteSerial_Arduino::available ( +NoteSerial_Mock::available ( void ) { @@ -50,7 +38,7 @@ NoteSerial_Arduino::available ( } char -NoteSerial_Arduino::receive ( +NoteSerial_Mock::receive ( void ) { @@ -64,7 +52,7 @@ NoteSerial_Arduino::receive ( } bool -NoteSerial_Arduino::reset ( +NoteSerial_Mock::reset ( void ) { @@ -78,7 +66,7 @@ NoteSerial_Arduino::reset ( } size_t -NoteSerial_Arduino::transmit ( +NoteSerial_Mock::transmit ( uint8_t *buffer_, size_t size_, bool flush_ diff --git a/test/mock/NoteSerial_Mock.hpp b/test/mock/NoteSerial_Mock.hpp index fb9a5cf..2f4b6a4 100644 --- a/test/mock/NoteSerial_Mock.hpp +++ b/test/mock/NoteSerial_Mock.hpp @@ -1,11 +1,20 @@ -#ifndef MOCK_SERIAL_ARDUINO_HPP -#define MOCK_SERIAL_ARDUINO_HPP +#ifndef MOCK_NOTE_SERIAL_HPP +#define MOCK_NOTE_SERIAL_HPP #include #include #include "NoteSerial.hpp" +class NoteSerial_Mock final : public NoteSerial +{ +public: + size_t available(void) override; + char receive(void) override; + bool reset(void) override; + size_t transmit(uint8_t * buffer, size_t size, bool flush) override; +}; + struct MakeNoteSerial_Parameters { MakeNoteSerial_Parameters( void @@ -112,4 +121,4 @@ extern NoteSerialReceive_Parameters noteSerialReceive_Parameters; extern NoteSerialReset_Parameters noteSerialReset_Parameters; extern NoteSerialTransmit_Parameters noteSerialTransmit_Parameters; -#endif // MOCK_SERIAL_ARDUINO_HPP +#endif // MOCK_NOTE_SERIAL_HPP diff --git a/test/run_all_tests.sh b/test/run_all_tests.sh index 1b6417d..15e60bf 100755 --- a/test/run_all_tests.sh +++ b/test/run_all_tests.sh @@ -19,9 +19,10 @@ if [ 0 -eq $all_tests_result ]; then test/mock/NoteSerial_Mock.cpp \ -Isrc \ -Itest \ - -DNOTE_MOCK + -DNOTE_MOCK \ + -o failed_test_run if [ 0 -eq $? ]; then - valgrind --leak-check=full --error-exitcode=66 ./a.out + valgrind --leak-check=full --error-exitcode=66 ./failed_test_run tests_result=$? if [ 0 -eq ${tests_result} ]; then echo -e "${GREEN}Notecard tests passed!${DEFAULT}" @@ -43,9 +44,10 @@ if [ 0 -eq $all_tests_result ]; then test/mock/mock-note-c-note.c \ -Isrc \ -Itest \ - -DNOTE_MOCK + -DNOTE_MOCK \ + -o failed_test_run if [ 0 -eq $? ]; then - valgrind --leak-check=full --error-exitcode=66 ./a.out + valgrind --leak-check=full --error-exitcode=66 ./failed_test_run tests_result=$? if [ 0 -eq ${tests_result} ]; then echo -e "${GREEN}NoteI2c_Arduino tests passed!${DEFAULT}" @@ -68,9 +70,10 @@ if [ 0 -eq $all_tests_result ]; then -Isrc \ -Itest \ -DNOTE_MOCK \ - -DWIRE_HAS_END + -DWIRE_HAS_END \ + -o failed_test_run if [ 0 -eq $? ]; then - valgrind --leak-check=full --error-exitcode=66 ./a.out + valgrind --leak-check=full --error-exitcode=66 ./failed_test_run tests_result=$? if [ 0 -eq ${tests_result} ]; then echo -e "${GREEN}NoteI2c_Arduino tests passed! (-DWIRE_HAS_END)${DEFAULT}" @@ -91,9 +94,10 @@ if [ 0 -eq $all_tests_result ]; then test/mock/mock-arduino.cpp \ -Isrc \ -Itest \ - -DNOTE_MOCK + -DNOTE_MOCK \ + -o failed_test_run if [ 0 -eq $? ]; then - valgrind --leak-check=full --error-exitcode=66 ./a.out + valgrind --leak-check=full --error-exitcode=66 ./failed_test_run tests_result=$? if [ 0 -eq ${tests_result} ]; then echo -e "${GREEN}NoteLog_Arduino tests passed!${DEFAULT}" @@ -114,9 +118,10 @@ if [ 0 -eq $all_tests_result ]; then test/mock/mock-arduino.cpp \ -Isrc \ -Itest \ - -DNOTE_MOCK + -DNOTE_MOCK \ + -o failed_test_run if [ 0 -eq $? ]; then - valgrind --leak-check=full --error-exitcode=66 ./a.out + valgrind --leak-check=full --error-exitcode=66 ./failed_test_run tests_result=$? if [ 0 -eq ${tests_result} ]; then echo -e "${GREEN}NoteSerial_Arduino tests passed!${DEFAULT}" @@ -151,11 +156,12 @@ if [ 0 -eq ${all_tests_result} ]; then lcov --summary ./coverage/lcov.info fi fi + rm -f failed_test_run else echo && echo -e "${RED}TESTS FAILED!!!${DEFAULT}" fi # Clean testing artifacts -rm -f *.gcda *.gcno ./a.out +rm -f *.gcda *.gcno exit $all_tests_result