diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c1dba13..36fb4659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,8 @@ target_compile_options( -Wextra -Wpedantic -Werror + -Og + -ggdb ) target_include_directories( note_c diff --git a/n_cobs.c b/n_cobs.c index 1013a4eb..426a5a1a 100644 --- a/n_cobs.c +++ b/n_cobs.c @@ -4,6 +4,8 @@ #include +#define COBS_EOP_OVERHEAD 1 + //**************************************************************************/ /*! @brief Decode a string encoded with COBS encoding @@ -94,6 +96,7 @@ uint32_t cobsEncode(uint8_t *ptr, uint32_t length, uint8_t eop, uint8_t *dst) @param length Length of the data to encode @return the length required for encoded data + @note The computed length does not include the EOP (end-of-packet) marker */ /**************************************************************************/ @@ -123,17 +126,19 @@ uint32_t cobsEncodedLength(const uint8_t *ptr, uint32_t length) @param length Length of the data to encode @return The max length required to encode the data + @note Since the contents of the buffer are unknown, then we must assume that the entire buffer has no end-of-packet markers. This would require the injection of overhead bytes (as opposed to the replacement of end-of-packet markers with overhead bytes) at intervals of 255, thus producing the worst case scenario. + @note An additional byte is added for the EOP (end-of-packet) marker. */ /**************************************************************************/ uint32_t cobsEncodedMaxLength(uint32_t length) { const uint32_t overheadBytes = ((length / 254) + ((length % 254) > 0)); - return (length + overheadBytes); + return (length + overheadBytes + COBS_EOP_OVERHEAD); } //**************************************************************************/ @@ -144,12 +149,13 @@ uint32_t cobsEncodedMaxLength(uint32_t length) @param bufLen Length of the buffer in bytes @return the length of unencoded data - @note The computation may leave additional space at the end, including one - byte for the EOP (end-of-packet) marker. + + @note The computation may leave additional space at the end. + @note An additional byte is added for the EOP (end-of-packet) marker. */ /**************************************************************************/ uint32_t cobsGuaranteedFit(uint32_t bufLen) { - uint32_t cobsOverhead = 1 + (bufLen / 254) + 1; + uint32_t cobsOverhead = 1 + (bufLen / 254) + COBS_EOP_OVERHEAD; return (cobsOverhead > bufLen ? 0 : (bufLen - cobsOverhead)); } diff --git a/n_helpers.c b/n_helpers.c index 28ef2178..290aa106 100644 --- a/n_helpers.c +++ b/n_helpers.c @@ -84,205 +84,90 @@ NOTE_C_STATIC void setTime(JTIME seconds); NOTE_C_STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs); NOTE_C_STATIC int ytodays(int year); -static const char BINARY_EOP = '\n'; +static const char NOTE_C_BINARY_EOP = '\n'; //**************************************************************************/ /*! - @brief Get the length of the data stored on the Notecard. If there's no data - stored on the Notecard, then `*len` will return 0. + @brief Decode binary data received from the Notecard. - @param len [out] the length of the decoded contents of the Notecard's binary - data store. + @param encData The encoded binary data to decode. + @param encDataLen The length of the encoded binary data. + @param decBuf The target buffer for the decoded data. For in-place decoding, + `decBuf` can use the same address as `encData` (see note). + @param decBufSize The size of `decBuf`. - @returns An error string on error and NULL on success. - */ -/**************************************************************************/ -const char * NoteBinaryDataDecodedLength(uint32_t *len) -{ - // Validate parameter(s) - if (!len) { - NOTE_C_LOG_ERROR("len cannot be NULL"); - return ERRSTR("len cannot be NULL", c_err); - } - - // Issue a "card.binary" request. - J *rsp = NoteRequestResponse(NoteNewRequest("card.binary")); - if (!rsp) { - NOTE_C_LOG_ERROR("unable to issue binary request"); - return ERRSTR("unable to issue binary request", c_err); - } - - // Ensure the transaction doesn't return an error and confirm the binary - // feature is available. - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - NOTE_C_LOG_ERROR(err); - JDelete(rsp); - NOTE_C_LOG_ERROR("unexpected error received during handshake"); - return ERRSTR("unexpected error received during handshake", c_bad); - } - - // Examine "length" from the response to evaluate the length of the decoded - // data residing on the Notecard. - *len = JGetInt(rsp, "length"); - JDelete(rsp); - - return NULL; -} - -//**************************************************************************/ -/*! - @brief Get the required buffer length to receive the entire binary object - stored on the Notecard. + @returns The length of the decoded data, or zero on error. - @param len [out] the length required to hold the entire contents of the - Notecard's binary data store. If there's no data stored on the - Notecard, then `*len` will return 0. - - @returns An error string on error and NULL on success. + @note Use `NoteBinaryCodecMaxDecodedLength()` to calculate the required + size for the buffer pointed to by the `decBuf` parameter, which MUST + accommodate both the encoded data and newline terminator. + @note This API supports in-place decoding. If you wish to utilize in-place + decoding, then set `decBuf` to `encData` and `decBufSize` to `encLen`. */ /**************************************************************************/ -const char * NoteBinaryDataEncodedLength(uint32_t *len) +uint32_t NoteBinaryCodecDecode(const uint8_t *encData, uint32_t encDataLen, + uint8_t *decBuf, uint32_t decBufSize) { - // Validate parameter(s) - if (!len) { - NOTE_C_LOG_ERROR("size cannot be NULL"); - return ERRSTR("size cannot be NULL", c_err); - } - - // Issue a "card.binary" request. - J *rsp = NoteRequestResponse(NoteNewRequest("card.binary")); - if (!rsp) { - NOTE_C_LOG_ERROR("unable to issue binary request"); - return ERRSTR("unable to issue binary request", c_err); - } - - // Ensure the transaction doesn't return an error and confirm the binary - // feature is available. - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - NOTE_C_LOG_ERROR(err); - JDelete(rsp); - NOTE_C_LOG_ERROR("unexpected error received during handshake"); - return ERRSTR("unexpected error received during handshake", c_bad); - } - - // Examine "cobs" from the response to evaluate the space required to hold - // the COBS-encoded data to be received from the Notecard. - long int cobs = JGetInt(rsp, "cobs"); - JDelete(rsp); - if (!cobs) { - // If cobs is 0, the required buffer length is 0 because there's nothing - // to receive. - *len = 0; - } else { - // Otherwise, the required length is cobs + 1: the binary data plus - // 1 byte for the terminating newline. - *len = cobs + 1; - } - - return NULL; -} - -//**************************************************************************/ -/*! - @brief Reset the Notecard's binary buffer. - - @returns NULL on success, else an error string pointer. + uint32_t result; - @note This operation is necessary to clear the Notecard's binary buffer after - a binary object is received from the Notecard, or if the Notecard's - binary buffer has been left in an unknown state due to an error arising - from a binary transfer to the Notecard. - */ -/**************************************************************************/ -const char * NoteBinaryDataReset(void) -{ - J *req = NoteNewRequest("card.binary"); - if (req) { - JAddBoolToObject(req, "delete", true); - - // Ensure the transaction doesn't return an error. - J *rsp = NoteRequestResponse(req); - if (NoteResponseError(rsp)) { - NOTE_C_LOG_ERROR(JGetString(rsp,"err")); - JDelete(rsp); - NOTE_C_LOG_ERROR("failed to reset binary buffer"); - return ERRSTR("failed to reset binary buffer", c_err); - } + // Validate parameter(s) + if (encData == NULL || decBuf == NULL) { + NOTE_C_LOG_ERROR(ERRSTR("NULL parameter", c_err)); + result = 0; + } else if (decBufSize < cobsGuaranteedFit(encDataLen)) { + NOTE_C_LOG_ERROR(ERRSTR("output buffer too small", c_err)); + result = 0; } else { - NOTE_C_LOG_ERROR("unable to allocate request"); - return ERRSTR("unable to allocate request", c_mem); + result = cobsDecode((uint8_t *)encData, encDataLen, NOTE_C_BINARY_EOP, decBuf); } - return NULL; + return result; } //**************************************************************************/ /*! - @brief Decode a binary payload received from the Notecard. - @param inBuf The binary payload. - @param inLen The length of the binary payload. - @param outBuf The buffer to write the decoded payload to. This can be the - same address as inBuf, allowing for in-place decoding. - @param outLen On input, holds the length of outBuf. On output, holds the - length of the decoded data. + @brief Encode binary data to transmit to the Notecard. - @returns NULL on success, else an error string pointer. - */ -/**************************************************************************/ -const char * NoteBinaryDecode(const uint8_t *inBuf, uint32_t inLen, - uint8_t *outBuf, uint32_t *outLen) -{ - if (inBuf == NULL || outBuf == NULL || outLen == NULL) { - NOTE_C_LOG_ERROR("NULL parameter"); - return ERRSTR("NULL parameter", c_err); - } + @param decData The decoded binary data to encode. + @param decDataLen The length of the decoded binary data. + @param encBuf The target buffer for the encoded data. For in-place encoding, + `encBuf` can use the same buffer as `decData`, but cannot + share the same address (see note). + @param encBufSize The size of `encBuf`. - if (*outLen < cobsGuaranteedFit(inLen)) { - NOTE_C_LOG_ERROR("output buffer too small"); - return ERRSTR("output buffer too small", c_err); - } - - *outLen = cobsDecode((uint8_t *)inBuf, inLen, BINARY_EOP, outBuf); - - return NULL; -} - -//**************************************************************************/ -/*! + @returns The length of the encoded data, or zero on error. - @brief Binary encode a buffer to prepare it for transmission to the Notecard. - - @param inBuf The data to encode. - @param inLen The length of the data to encode. - @param outBuf The buffer to write the encoded data to. This can be the - same address as inBuf, allowing for in-place encoding. - @param outLen On input, holds the length of outBuf. On output, holds the - length of the encoded data. - - @returns NULL on success, else an error string pointer. + @note Use `NoteBinaryCodecMaxEncodedLength()` to calculate the required + size for the buffer pointed to by the `encBuf` parameter, which MUST + accommodate both the encoded data and newline terminator. + @note This API supports in-place encoding. If you wish to utilize in-place + encoding, shift the decoded data to the end of the buffer, update + `decBuf` accordingly, and set the value of `encBuf` to the beginning + of the buffer. */ /**************************************************************************/ -const char * NoteBinaryEncode(const uint8_t *inBuf, uint32_t inLen, - uint8_t *outBuf, uint32_t *outLen) +uint32_t NoteBinaryCodecEncode(const uint8_t *decData, uint32_t decDataLen, + uint8_t *encBuf, uint32_t encBufSize) { - if (inBuf == NULL || outBuf == NULL || outLen == NULL) { - NOTE_C_LOG_ERROR("NULL parameter"); - return ERRSTR("NULL parameter", c_err); - } + uint32_t result; - if (*outLen < cobsEncodedMaxLength(inLen)) { - if (*outLen < cobsEncodedLength(inBuf, inLen)) { - NOTE_C_LOG_ERROR("output buffer too small"); - return ERRSTR("output buffer too small", c_err); - } + // Validate parameter(s) + if (decData == NULL || encBuf == NULL) { + NOTE_C_LOG_ERROR(ERRSTR("NULL parameter", c_err)); + result = 0; + } else if ((encBufSize < cobsEncodedMaxLength(decDataLen)) + && (encBufSize < cobsEncodedLength(decData, decDataLen))) { + // NOTE: `cobsEncodedMaxLength()` provides a constant time [O(1)] means + // of checking the buffer size. Only when it fails will the linear + // time [O(n)] check, `cobsEncodedLength()`, be invoked. + NOTE_C_LOG_ERROR(ERRSTR("output buffer too small", c_err)); + result = 0; + } else { + result = cobsEncode((uint8_t *)decData, decDataLen, NOTE_C_BINARY_EOP, encBuf); } - *outLen = cobsEncode((uint8_t *)inBuf, inLen, BINARY_EOP, outBuf); - - return NULL; + return result; } //**************************************************************************/ @@ -311,7 +196,7 @@ const char * NoteBinaryEncode(const uint8_t *inBuf, uint32_t inLen, buffer, after being encoded. */ /**************************************************************************/ -uint32_t NoteBinaryMaxDecodedLength(uint32_t bufferSize) +uint32_t NoteBinaryCodecMaxDecodedLength(uint32_t bufferSize) { return cobsGuaranteedFit(bufferSize); } @@ -326,49 +211,142 @@ uint32_t NoteBinaryMaxDecodedLength(uint32_t bufferSize) @returns The max required buffer size to hold the encoded data. */ /**************************************************************************/ -uint32_t NoteBinaryMaxEncodedLength(uint32_t unencodedLength) +uint32_t NoteBinaryCodecMaxEncodedLength(uint32_t unencodedLength) { return cobsEncodedMaxLength(unencodedLength); } //**************************************************************************/ /*! - @brief Receive a large binary object from the Notecard's binary buffer + @brief Get the length of the data in the Notecard's binary store. If there's + no data on the Notecard, then `*len` will return 0. + + @param len [out] The length of the decoded contents of the Notecard's binary + store. + + @returns An error string on error and NULL on success. + */ +/**************************************************************************/ +const char * NoteBinaryStoreDecodedLength(uint32_t *len) +{ + // Validate parameter(s) + if (!len) { + const char *err = ERRSTR("len cannot be NULL", c_bad); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Issue a "card.binary" request. + J *rsp = NoteRequestResponse(NoteNewRequest("card.binary")); + if (!rsp) { + const char *err = ERRSTR("unable to issue binary request", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Ensure the transaction doesn't return an error and confirm the binary + // feature is available. + if (NoteResponseError(rsp)) { + NOTE_C_LOG_ERROR(JGetString(rsp, "err")); + JDelete(rsp); + const char *err = ERRSTR("unexpected error received during handshake", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Examine "length" from the response to evaluate the length of the decoded + // data residing on the Notecard. + *len = JGetInt(rsp, "length"); + JDelete(rsp); + + return NULL; +} + +//**************************************************************************/ +/*! + @brief Get the required buffer length to receive the entire binary object + stored in the Notecard's binary store. + + @param len [out] The length required to hold the entire contents of the + Notecard's binary store. If there's no data on the Notecard, then + `len` will return 0. + + @returns An error string on error and NULL on success. + */ +/**************************************************************************/ +const char * NoteBinaryStoreEncodedLength(uint32_t *len) +{ + // Validate parameter(s) + if (!len) { + const char *err = ERRSTR("size cannot be NULL", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Issue a "card.binary" request. + J *rsp = NoteRequestResponse(NoteNewRequest("card.binary")); + if (!rsp) { + const char *err = ERRSTR("unable to issue binary request", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Ensure the transaction doesn't return an error and confirm the binary + // feature is available. + if (NoteResponseError(rsp)) { + NOTE_C_LOG_ERROR(JGetString(rsp, "err")); + JDelete(rsp); + const char *err = ERRSTR("unexpected error received during handshake", c_bad); + NOTE_C_LOG_ERROR(err); + return err; + } + + // Examine "cobs" from the response to evaluate the space required to hold + // the encoded data to be received from the Notecard. + long int cobs = JGetInt(rsp, "cobs"); + JDelete(rsp); + *len = cobs; + + return NULL; +} + +//**************************************************************************/ +/*! + @brief Receive a large binary object from the Notecard's binary store. - @param buffer A buffer to hold the binary object - @param bufLen The total length of the provided buffer - @param decodedOffset The offset to the decoded binary data already residing - on the Notecard - @param decodedLen [in/out] The length of the decoded data to fetch from the - Notecard. If you wish to fetch the entire buffer from the - given offset, set this value to `NOTE_C_BINARY_RX_ALL`. - This parameter will return the bytes actually received from - the Notecard. + @param buffer A buffer to hold the binary range. + @param bufLen The total length of the provided buffer. + @param decodedOffset The offset to the decoded binary data residing + in the Notecard's binary store. + @param decodedLen The length of the decoded data to fetch from the Notecard. @returns NULL on success, else an error string pointer. @note The buffer must be large enough to hold the encoded value of the data store contents from the requested offset for the specified length. To determine the necessary buffer size for a given data length, use - `(NoteBinaryMaxEncodedLength() + 1)`, or if you wish to consume the - entire buffer use `NoteBinaryDataEncodedLength()` instead. + `NoteBinaryCodecMaxEncodedLength()`, or if you wish to consume the + entire buffer use `(NoteBinaryStoreEncodedLength() + 1)` instead. */ /**************************************************************************/ -const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, - uint32_t decodedOffset, uint32_t * decodedLen) +const char * NoteBinaryStoreReceive(uint8_t *buffer, uint32_t bufLen, + uint32_t decodedOffset, uint32_t decodedLen) { // Validate parameter(s) if (!buffer) { - NOTE_C_LOG_ERROR("NULL buffer"); - return ERRSTR("NULL buffer", c_err); + const char *err = ERRSTR("NULL buffer", c_bad); + NOTE_C_LOG_ERROR(err); + return err; } - if (!decodedLen) { - NOTE_C_LOG_ERROR("decodedLen cannot be NULL"); - return ERRSTR("decodedLen cannot be NULL", c_err); + if (bufLen < cobsEncodedMaxLength(decodedLen)) { + const char *err = ERRSTR("insufficient buffer size", c_bad); + NOTE_C_LOG_ERROR(err); + return err; } - if (bufLen < (cobsEncodedMaxLength(*decodedLen) + 1)) { - NOTE_C_LOG_ERROR("insufficient buffer size"); - return ERRSTR("insufficient buffer size", c_err); + if (decodedLen == 0) { + const char *err = ERRSTR("decodedLen cannot be zero (0)", c_bad); + NOTE_C_LOG_ERROR(err); + return err; } // Claim Notecard Mutex @@ -379,25 +357,27 @@ const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, J *req = NoteNewRequest("card.binary.get"); if (req) { JAddIntToObject(req, "offset", decodedOffset); - JAddIntToObject(req, "length", *decodedLen); + JAddIntToObject(req, "length", decodedLen); // Ensure the transaction doesn't return an error. J *rsp = NoteRequestResponse(req); if (NoteResponseError(rsp)) { NOTE_C_LOG_ERROR(JGetString(rsp,"err")); JDelete(rsp); - NOTE_C_LOG_ERROR("failed to initialize binary transaction"); + const char *err = ERRSTR("failed to initialize binary transaction", c_err); + NOTE_C_LOG_ERROR(err); _UnlockNote(); - return ERRSTR("failed to initialize binary transaction", c_err); + return err; } // Examine "status" from the response to evaluate the MD5 checksum. strlcpy(status, JGetString(rsp,"status"), NOTE_MD5_HASH_STRING_SIZE); JDelete(rsp); } else { - NOTE_C_LOG_ERROR("unable to allocate request"); + const char *err = ERRSTR("unable to allocate request", c_mem); + NOTE_C_LOG_ERROR(err); _UnlockNote(); - return ERRSTR("unable to allocate request", c_mem); + return err; } // Read raw bytes from the active interface into a predefined buffer @@ -414,8 +394,9 @@ const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, // Check buffer overflow condition if (available) { - NOTE_C_LOG_ERROR("unexpected data available"); - return ERRSTR("unexpected data available", c_err); + const char *err = ERRSTR("unexpected data available", c_err); + NOTE_C_LOG_ERROR(err); + return err; } // _ChunkedReceive returns the raw bytes that came off the wire, which @@ -423,14 +404,15 @@ const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, // part of the binary payload, so we decrement the length by 1 to remove it. --bufLen; - uint32_t decLen = bufLen; // Decode it in place, which is safe because decoding shrinks - err = NoteBinaryDecode(buffer, bufLen, buffer, &decLen); - if (err) { + const uint32_t decLen = NoteBinaryCodecDecode(buffer, bufLen, buffer, bufLen); + + // Ensure the decoded length matches the caller's expectations. + if (decodedLen != decLen) { + const char *err = ERRSTR("length mismatch after decoding", c_err); + NOTE_C_LOG_ERROR(err); return err; } - // Return the decoded length in the decodedLen out parameter. - *decodedLen = decLen; // Put a hard marker at the end of the decoded portion of the buffer. This // enables easier human reasoning when interrogating the buffer, if the @@ -441,8 +423,9 @@ const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, char hashString[NOTE_MD5_HASH_STRING_SIZE] = {0}; NoteMD5HashString(buffer, decLen, hashString, NOTE_MD5_HASH_STRING_SIZE); if (strncmp(hashString, status, NOTE_MD5_HASH_STRING_SIZE)) { - NOTE_C_LOG_ERROR("computed MD5 does not match received MD5"); - return ERRSTR("computed MD5 does not match received MD5", c_err); + const char *err = ERRSTR("computed MD5 does not match received MD5", c_err); + NOTE_C_LOG_ERROR(err); + return err; } // Return `NULL` if success, else error string pointer @@ -451,52 +434,100 @@ const char * NoteBinaryReceive(uint8_t * buffer, uint32_t bufLen, //**************************************************************************/ /*! - @brief Transmit a large binary object to the Notecard's binary buffer + @brief Reset the Notecard's binary store. + + @returns NULL on success, else an error string pointer. - @param unencodedData A buffer with data to encode in place - @param unencodedLen The length of the data in the buffer - @param bufLen The total length of the buffer (see notes) + @note This operation is necessary to clear the Notecard's binary buffer after + a binary object is received from the Notecard, or if the Notecard's + binary store has been left in an unknown state due to an error arising + from a binary transfer to the Notecard. + */ +/**************************************************************************/ +const char * NoteBinaryStoreReset(void) +{ + J *req = NoteNewRequest("card.binary"); + if (req) { + JAddBoolToObject(req, "delete", true); + + // Ensure the transaction doesn't return an error. + J *rsp = NoteRequestResponse(req); + if (NoteResponseError(rsp)) { + NOTE_C_LOG_ERROR(JGetString(rsp,"err")); + JDelete(rsp); + const char *err = ERRSTR("failed to reset binary buffer", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } + + JDelete(rsp); + } else { + const char *err = ERRSTR("unable to allocate request", c_mem); + NOTE_C_LOG_ERROR(err); + return err; + } + + return NULL; +} + +//**************************************************************************/ +/*! + @brief Transmit a large binary object to the Notecard's binary store. + + @param unencodedData A buffer with data to encode in place. + @param unencodedLen The length of the data in the buffer. + @param bufLen The total length of the buffer (see notes). @param notecardOffset The offset where the data buffer should be appended - to the decoded binary data already residing on the - Notecard. This does not provide random access, but + to the decoded binary data residing in the Notecard's + binary store. This does not provide random access, but rather ensures alignment across sequential writes. @returns NULL on success, else an error string pointer. @note Buffers are encoded in place, the buffer _MUST_ be larger than the data to be encoded. The original contents of the buffer will be modified. - Use `(NoteBinaryMaxEncodedLength() + 1)` to calculate the required size - for the buffer pointed to by the `bufLen` parameter, which MUST - accommodate the encoded data and newline terminator. + Use `NoteBinaryCodecMaxEncodedLength()` to calculate the required size + for the buffer pointed to by the `unencodedData` parameter, which MUST + accommodate both the encoded data and newline terminator. */ /**************************************************************************/ -const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, - uint32_t bufLen, uint32_t notecardOffset) +const char * NoteBinaryStoreTransmit(uint8_t *unencodedData, uint32_t unencodedLen, + uint32_t bufLen, uint32_t notecardOffset) { // Validate parameter(s) if (!unencodedData) { - NOTE_C_LOG_ERROR("unencodedData cannot be NULL"); - return ERRSTR("unencodedData cannot be NULL", c_err); + const char *err = ERRSTR("unencodedData cannot be NULL", c_err); + NOTE_C_LOG_ERROR(err); + return err; + } else if ((bufLen < cobsEncodedMaxLength(unencodedLen)) + && (bufLen < (cobsEncodedLength(unencodedData, unencodedLen) + 1))) { + // NOTE: `cobsEncodedMaxLength()` provides a constant time [O(1)] means + // of checking the buffer size. Only when it fails will the linear + // time [O(n)] check, `cobsEncodedLength()`, be invoked. + const char *err = ERRSTR("insufficient buffer size", c_bad); + NOTE_C_LOG_ERROR(err); + return err; } // Issue a "card.binary" request. J *rsp = NoteRequestResponse(NoteNewRequest("card.binary")); if (!rsp) { - NOTE_C_LOG_ERROR("unable to issue binary request"); - return ERRSTR("unable to issue binary request", c_err); + const char *err = ERRSTR("unable to issue binary request", c_err); + NOTE_C_LOG_ERROR(err); + return err; } // Ensure the transaction doesn't return an error // and confirm the binary feature is available - const char *err = NULL; if (NoteResponseError(rsp)) { - err = JGetString(rsp, "err"); + const char *jErr = JGetString(rsp, "err"); // Swallow `{bad-bin}` errors, because we intend to overwrite the data. - if (!NoteErrorContains(err, c_badbinerr)) { - NOTE_C_LOG_ERROR(err); + if (!NoteErrorContains(jErr, c_badbinerr)) { + NOTE_C_LOG_ERROR(jErr); JDelete(rsp); - NOTE_C_LOG_ERROR("unexpected error received during handshake"); - return ERRSTR("unexpected error received during handshake", c_bad); + const char *err = ERRSTR("unexpected error received during handshake", c_bad); + NOTE_C_LOG_ERROR(err); + return err; } } @@ -506,23 +537,26 @@ const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, const long max = JGetInt(rsp,"max"); JDelete(rsp); if (!max) { - NOTE_C_LOG_ERROR("unexpected response: max is zero or not present"); - return ERRSTR("unexpected response: max is zero or not present", c_err); + const char *err = ERRSTR("unexpected response: max is zero or not present", c_err); + NOTE_C_LOG_ERROR(err); + return err; } // Validate the index provided by the caller, against the `length` value // returned from the Notecard to ensure the caller and Notecard agree on // how much data is residing on the Notecard. if ((long)notecardOffset != len) { - NOTE_C_LOG_ERROR("notecard data length is misaligned with offset"); - return ERRSTR("notecard data length is misaligned with offset", c_mem); + const char *err = ERRSTR("notecard data length is misaligned with offset", c_mem); + NOTE_C_LOG_ERROR(err); + return err; } // When offset is zero, the Notecard's entire binary buffer is available const uint32_t remaining = (notecardOffset ? (max - len) : max); if (unencodedLen > remaining) { - NOTE_C_LOG_ERROR("buffer size exceeds available memory"); - return ERRSTR("buffer size exceeds available memory", c_mem); + const char *err = ERRSTR("buffer size exceeds available memory", c_mem); + NOTE_C_LOG_ERROR(err); + return err; } // Calculate MD5 @@ -534,16 +568,16 @@ const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, const uint32_t dataShift = (bufLen - unencodedLen); memmove(unencodedData + dataShift, unencodedData, unencodedLen); - // `encLen` holds the buffer size available for encoding. The `- 1` accounts - // for one byte of space we need to save for a newline to mark the end of - // the packet. When `NoteBinaryEncode()` returns, `encLen` will hold the - // encoded length. - uint32_t encLen = (bufLen - 1); + // Create an alias to help reason about the buffer after in-place encoding. uint8_t * const encodedData = unencodedData; - err = NoteBinaryEncode(unencodedData + dataShift, unencodedLen, encodedData, &encLen); - if (err) { - return err; - } + + // Update unencoded data pointer + unencodedData += dataShift; + + // Capture encoded length + // NOTE: `(bufLen - 1)` accounts for one byte of space we need to save for a + // newline to mark the end of the packet. + const uint32_t encLen = NoteBinaryCodecEncode(unencodedData, unencodedLen, encodedData, (bufLen - 1)); // Append the \n, which marks the end of a packet. encodedData[encLen] = '\n'; @@ -564,22 +598,24 @@ const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, // Ensure the transaction doesn't return an error. if (!NoteRequest(req)) { - NOTE_C_LOG_ERROR("failed to initialize binary transaction"); + const char *err = ERRSTR("failed to initialize binary transaction", c_err); + NOTE_C_LOG_ERROR(err); _UnlockNote(); - // On errors, we restore the caller's input buffer by COBS - // decoding it. The caller is then able to retry transmission - // with their original pointer to this buffer. - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); - return ERRSTR("failed to initialize binary transaction", c_err); + // On errors, we restore the caller's input buffer by decoding + // it. The caller is then able to retry transmission with their + // original pointer to this buffer. + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); + return err; } } else { - NOTE_C_LOG_ERROR("unable to allocate request"); + const char *err = ERRSTR("unable to allocate request", c_mem); + NOTE_C_LOG_ERROR(err); _UnlockNote(); - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); - return ERRSTR("unable to allocate request", c_mem); + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); + return err; } - // Immediately send the COBS binary. + // Immediately send the encoded binary. const char *err = _ChunkedTransmit(encodedData, (encLen + 1), false); // Release Notecard Mutex @@ -587,39 +623,41 @@ const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, // Ensure transaction was successful if (err) { - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); return ERRSTR(err, c_err); } // Issue a `"card.binary"` request. rsp = NoteRequestResponse(NoteNewRequest("card.binary")); if (!rsp) { - NOTE_C_LOG_ERROR("unable to validate request"); - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); - return ERRSTR("unable to validate request", c_err); + const char *err = ERRSTR("unable to validate request", c_err); + NOTE_C_LOG_ERROR(err); + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); + return err; } // Ensure the transaction doesn't return an error // to confirm the binary was received if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - NOTE_C_LOG_ERROR(err); - if (NoteErrorContains(err, c_badbinerr)) { + const char *jErr = JGetString(rsp, "err"); + if (NoteErrorContains(jErr, c_badbinerr)) { + NOTE_C_LOG_WARN(jErr); JDelete(rsp); if ( i < (NOTE_C_BINARY_RETRIES - 1) ) { NOTE_C_LOG_WARN("retrying binary transmission..."); continue; } - NOTE_C_LOG_ERROR("binary data invalid"); - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); - return ERRSTR("binary data invalid", c_bad); + const char *err = ERRSTR("binary data invalid", c_bad); + NOTE_C_LOG_ERROR(err); + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); + return err; } else { + NOTE_C_LOG_ERROR(jErr); JDelete(rsp); - NOTE_C_LOG_ERROR("unexpected error received during " - "confirmation"); - NoteBinaryDecode(encodedData, encLen, unencodedData, &bufLen); - return ERRSTR("unexpected error received during confirmation", - c_bad); + const char *err = ERRSTR("unexpected error received during confirmation", c_bad); + NOTE_C_LOG_ERROR(err); + NoteBinaryCodecDecode(encodedData, encLen, encodedData, bufLen); + return err; } } JDelete(rsp); diff --git a/note.h b/note.h index e78757c9..1d7317f0 100644 --- a/note.h +++ b/note.h @@ -317,20 +317,19 @@ void NoteMD5HashToString(unsigned char *hash, char *strbuf, unsigned long buflen // High-level helper functions that are both useful and serve to show developers // how to call the API -#define NOTE_C_BINARY_RX_ALL 0 -const char * NoteBinaryDataDecodedLength(uint32_t *len); -const char * NoteBinaryDataEncodedLength(uint32_t *len); -const char * NoteBinaryDataReset(void); -const char * NoteBinaryDecode(const uint8_t *inBuf, uint32_t inLen, - uint8_t *outBuf, uint32_t *outLen); -const char * NoteBinaryEncode(const uint8_t *inBuf, uint32_t inLen, - uint8_t *outBuf, uint32_t *outLen); -uint32_t NoteBinaryMaxDecodedLength(uint32_t bufferSize); -uint32_t NoteBinaryMaxEncodedLength(uint32_t unencodedLength); -const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen, - uint32_t decodedOffset, uint32_t *decodedLen); -const char * NoteBinaryTransmit(uint8_t *unencodedData, uint32_t unencodedLen, - uint32_t bufLen, uint32_t notecardOffset); +uint32_t NoteBinaryCodecDecode(const uint8_t *encData, uint32_t encDataLen, + uint8_t *decBuf, uint32_t decBufSize); +uint32_t NoteBinaryCodecEncode(const uint8_t *decData, uint32_t decDataLen, + uint8_t *encBuf, uint32_t encBufSize); +uint32_t NoteBinaryCodecMaxDecodedLength(uint32_t bufferSize); +uint32_t NoteBinaryCodecMaxEncodedLength(uint32_t unencodedLength); +const char * NoteBinaryStoreDecodedLength(uint32_t *len); +const char * NoteBinaryStoreEncodedLength(uint32_t *len); +const char * NoteBinaryStoreReceive(uint8_t *buffer, uint32_t bufLen, + uint32_t decodedOffset, uint32_t decodedLen); +const char * NoteBinaryStoreReset(void); +const char * NoteBinaryStoreTransmit(uint8_t *unencodedData, uint32_t unencodedLen, + uint32_t bufLen, uint32_t notecardOffset); uint32_t NoteSetSTSecs(uint32_t secs); bool NoteTimeValid(void); bool NoteTimeValidST(void); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b621ef1..df562ea7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,6 +46,10 @@ macro(add_test TEST_NAME) PRIVATE note_c PRIVATE Catch2::Catch2WithMain ) + target_compile_options(${TEST_NAME} + PRIVATE -Og + PRIVATE -ggdb + ) list(APPEND TEST_TARGETS ${TEST_NAME}) @@ -144,15 +148,15 @@ add_test(serialChunkedTransmit_test) add_test(i2cNoteQueryLength_test) add_test(i2cChunkedReceive_test) add_test(i2cChunkedTransmit_test) -add_test(NoteBinaryDataDecodedLength_test) -add_test(NoteBinaryDataEncodedLength_test) -add_test(NoteBinaryDataReset_test) -add_test(NoteBinaryDecode_test) -add_test(NoteBinaryEncode_test) -add_test(NoteBinaryMaxEncodedLength_test) -add_test(NoteBinaryMaxDecodedLength_test) -add_test(NoteBinaryReceive_test) -add_test(NoteBinaryTransmit_test) +add_test(NoteBinaryCodecDecode_test) +add_test(NoteBinaryCodecEncode_test) +add_test(NoteBinaryCodecMaxDecodedLength_test) +add_test(NoteBinaryCodecMaxEncodedLength_test) +add_test(NoteBinaryStoreDecodedLength_test) +add_test(NoteBinaryStoreEncodedLength_test) +add_test(NoteBinaryStoreReceive_test) +add_test(NoteBinaryStoreReset_test) +add_test(NoteBinaryStoreTransmit_test) if(NOTE_C_COVERAGE) find_program(LCOV lcov REQUIRED) diff --git a/test/src/NoteBinaryCodecDecode_test.cpp b/test/src/NoteBinaryCodecDecode_test.cpp new file mode 100644 index 00000000..6deb56c1 --- /dev/null +++ b/test/src/NoteBinaryCodecDecode_test.cpp @@ -0,0 +1,89 @@ +/*! + * @file NoteBinaryCodecDecode_test.cpp + * + * Written by the Blues Inc. team. + * + * Copyright (c) 2023 Blues Inc. MIT License. Use of this source code is + * governed by licenses granted by the copyright holder including that found in + * the + * LICENSE + * file. + * + */ + +#ifdef NOTE_C_TEST + +#include +#include "fff.h" + +#include "n_lib.h" + +DEFINE_FFF_GLOBALS +FAKE_VALUE_FUNC(uint32_t, cobsDecode, uint8_t *, uint32_t, uint8_t, uint8_t *) + +uint8_t encData[12]; +const uint32_t encDataLen = sizeof(encData); +uint8_t decBuf[10]; +const uint32_t decBufLen = sizeof(decBuf); +uint32_t decLen; + +namespace +{ + +SCENARIO("NoteBinaryCodecDecode") +{ + RESET_FAKE(cobsDecode); + decLen = 0; + + GIVEN("Bad parameters are supplied") { + decLen = 79; + WHEN("encData is NULL") { + decLen = NoteBinaryCodecDecode(NULL, encDataLen, decBuf, decBufLen); + + THEN("The decoded length is zero") { + CHECK(decLen == 0); + } + } + WHEN("decBuf is NULL") { + decLen = NoteBinaryCodecDecode(encData, encDataLen, NULL, decBufLen); + + THEN("The decoded length is zero") { + CHECK(decLen == 0); + } + } + WHEN("decBufLen is less than the size required for the worst-case decoding") { + uint32_t badDecLen = (cobsGuaranteedFit(encDataLen) - 1); + decLen = NoteBinaryCodecDecode(encData, encDataLen, decBuf, badDecLen); + + THEN("The decoded length is zero") { + CHECK(decLen == 0); + } + } + } + + GIVEN("Parameters are in order") { + const uint32_t EXPECTED_RESULT = 79; + cobsDecode_fake.return_val = EXPECTED_RESULT; + decLen = NoteBinaryCodecDecode(encData, encDataLen, decBuf, decBufLen); + + THEN("cobsDecode is invoked") { + CHECK(cobsDecode_fake.call_count > 0); + } + + WHEN("cobsDecode is invoked") { + THEN("The parameters are passed without modification") { + CHECK(cobsDecode_fake.arg0_history[0] == encData); + CHECK(cobsDecode_fake.arg1_history[0] == encDataLen); + CHECK(cobsDecode_fake.arg3_history[0] == decBuf); + } + + THEN("The result is returned without modification") { + CHECK(EXPECTED_RESULT == decLen); + } + } + } +} + +} + +#endif // NOTE_C_TEST diff --git a/test/src/NoteBinaryCodecEncode_test.cpp b/test/src/NoteBinaryCodecEncode_test.cpp new file mode 100644 index 00000000..a6ee2298 --- /dev/null +++ b/test/src/NoteBinaryCodecEncode_test.cpp @@ -0,0 +1,90 @@ +/*! + * @file NoteBinaryCodecEncode_test.cpp + * + * Written by the Blues Inc. team. + * + * Copyright (c) 2023 Blues Inc. MIT License. Use of this source code is + * governed by licenses granted by the copyright holder including that found in + * the + * LICENSE + * file. + * + */ + +#ifdef NOTE_C_TEST + +#include + +#include +#include "fff.h" + +#include "n_lib.h" + +DEFINE_FFF_GLOBALS +FAKE_VALUE_FUNC(uint32_t, cobsEncode, uint8_t *, uint32_t, uint8_t, uint8_t *) + +uint8_t decData[10] = "Hi Blues!"; +uint32_t decDataLen = strlen((const char *)decData); +uint8_t encBuf[12]; +uint32_t encBufLen = sizeof(encBuf); +uint32_t encLen; + +namespace +{ + +SCENARIO("NoteBinaryCodecEncode") +{ + RESET_FAKE(cobsEncode); + encLen = 0; + + GIVEN("Bad parameters are supplied") { + WHEN("decData is NULL") { + encLen = NoteBinaryCodecEncode(NULL, decDataLen, encBuf, encBufLen); + + THEN("The encoded length is zero") { + CHECK(encLen == 0); + } + } + WHEN("encBuf is NULL") { + encLen = NoteBinaryCodecEncode(decData, decDataLen, NULL, encBufLen); + + THEN("The encoded length is zero") { + CHECK(encLen == 0); + } + } + WHEN("encBufLen is less than the size required for in place encoding") { + uint32_t badOutLen = (cobsEncodedLength(decData, decDataLen) - 1); + encLen = NoteBinaryCodecEncode(decData, decDataLen, encBuf, badOutLen); + + THEN("The encoded length is zero") { + CHECK(encLen == 0); + } + } + } + + GIVEN("Parameters are in order") { + const uint32_t EXPECTED_RESULT = 79; + cobsEncode_fake.return_val = EXPECTED_RESULT; + encLen = NoteBinaryCodecEncode(decData, decDataLen, encBuf, encBufLen); + + THEN("cobsEncode is invoked") { + CHECK(cobsEncode_fake.call_count > 0); + } + + WHEN("cobsEncode is invoked") { + THEN("The parameters are passed without modification") { + CHECK(cobsEncode_fake.arg0_history[0] == decData); + CHECK(cobsEncode_fake.arg1_history[0] == decDataLen); + CHECK(cobsEncode_fake.arg3_history[0] == encBuf); + } + + THEN("The result is returned without modification") { + CHECK(EXPECTED_RESULT == encLen); + } + } + } +} + +} + +#endif // NOTE_C_TEST diff --git a/test/src/NoteBinaryMaxDecodedLength_test.cpp b/test/src/NoteBinaryCodecMaxDecodedLength_test.cpp similarity index 87% rename from test/src/NoteBinaryMaxDecodedLength_test.cpp rename to test/src/NoteBinaryCodecMaxDecodedLength_test.cpp index 81894220..129aaa5c 100644 --- a/test/src/NoteBinaryMaxDecodedLength_test.cpp +++ b/test/src/NoteBinaryCodecMaxDecodedLength_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryMaxDecodedLength_test.cpp + * @file NoteBinaryCodecMaxDecodedLength_test.cpp * * Written by the Blues Inc. team. * @@ -26,14 +26,14 @@ const uint32_t bufferSize = 10; namespace { -SCENARIO("NoteBinaryMaxDecodedLength") +SCENARIO("NoteBinaryCodecMaxDecodedLength") { RESET_FAKE(cobsGuaranteedFit); GIVEN("Parameters are in order") { const uint32_t EXPECTED_RESULT = 79; cobsGuaranteedFit_fake.return_val = EXPECTED_RESULT; - const uint32_t result = NoteBinaryMaxDecodedLength(bufferSize); + const uint32_t result = NoteBinaryCodecMaxDecodedLength(bufferSize); THEN("cobsGuaranteedFit is invoked") { CHECK(cobsGuaranteedFit_fake.call_count > 0); diff --git a/test/src/NoteBinaryMaxEncodedLength_test.cpp b/test/src/NoteBinaryCodecMaxEncodedLength_test.cpp similarity index 87% rename from test/src/NoteBinaryMaxEncodedLength_test.cpp rename to test/src/NoteBinaryCodecMaxEncodedLength_test.cpp index fb3227dc..012f1ade 100644 --- a/test/src/NoteBinaryMaxEncodedLength_test.cpp +++ b/test/src/NoteBinaryCodecMaxEncodedLength_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryMaxEncodedLength_test.cpp + * @file NoteBinaryCodecMaxEncodedLength_test.cpp * * Written by the Blues Inc. team. * @@ -26,14 +26,14 @@ const uint32_t unencodedLen = 10; namespace { -SCENARIO("NoteBinaryMaxEncodedLength") +SCENARIO("NoteBinaryCodecMaxEncodedLength") { RESET_FAKE(cobsEncodedMaxLength); GIVEN("Parameters are in order") { const uint32_t EXPECTED_RESULT = 79; cobsEncodedMaxLength_fake.return_val = EXPECTED_RESULT; - const uint32_t result = NoteBinaryMaxEncodedLength(unencodedLen); + const uint32_t result = NoteBinaryCodecMaxEncodedLength(unencodedLen); THEN("cobsEncodedMaxLength is invoked") { CHECK(cobsEncodedMaxLength_fake.call_count > 0); diff --git a/test/src/NoteBinaryDecode_test.cpp b/test/src/NoteBinaryDecode_test.cpp deleted file mode 100644 index 0dee3060..00000000 --- a/test/src/NoteBinaryDecode_test.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*! - * @file NoteBinaryDecode_test.cpp - * - * Written by the Blues Inc. team. - * - * Copyright (c) 2023 Blues Inc. MIT License. Use of this source code is - * governed by licenses granted by the copyright holder including that found in - * the - * LICENSE - * file. - * - */ - -#ifdef NOTE_C_TEST - -#include -#include "fff.h" - -#include "n_lib.h" - -DEFINE_FFF_GLOBALS -FAKE_VALUE_FUNC(uint32_t, cobsDecode, uint8_t *, uint32_t, uint8_t, uint8_t *) - -uint8_t inBuf[12]; -uint32_t inLen; -uint8_t outBuf[10]; -uint32_t outLen; - -namespace -{ - -SCENARIO("NoteBinaryDecode") -{ - RESET_FAKE(cobsDecode); - uint32_t inLen = sizeof(inBuf); - uint32_t outLen = sizeof(outBuf); - - GIVEN("Bad parameters are supplied") { - WHEN("inBuf is NULL") { - const char *err = NoteBinaryDecode(NULL, inLen, outBuf, &outLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outBuf is NULL") { - const char *err = NoteBinaryDecode(inBuf, inLen, NULL, &outLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outLen is NULL") { - const char *err = NoteBinaryDecode(inBuf, inLen, outBuf, NULL); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outLen is less than the size required for the worst-case decoding") { - uint32_t badOutLen = (cobsGuaranteedFit(inLen) - 1); - const char *err = NoteBinaryDecode(inBuf, inLen, outBuf, &badOutLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - } - - GIVEN("Parameters are in order") { - const uint32_t EXPECTED_RESULT = 79; - cobsDecode_fake.return_val = EXPECTED_RESULT; - const char *err = NoteBinaryDecode(inBuf, inLen, outBuf, &outLen); - - THEN("cobsDecode is invoked") { - CHECK(cobsDecode_fake.call_count > 0); - } - - WHEN("cobsDecode is invoked") { - THEN("The parameters are passed without modification") { - CHECK(cobsDecode_fake.arg0_history[0] == inBuf); - CHECK(cobsDecode_fake.arg1_history[0] == inLen); - CHECK(cobsDecode_fake.arg3_history[0] == outBuf); - } - - THEN("The result is returned without modification") { - CHECK(EXPECTED_RESULT == outLen); - } - } - } -} - -} - -#endif // NOTE_C_TEST diff --git a/test/src/NoteBinaryEncode_test.cpp b/test/src/NoteBinaryEncode_test.cpp deleted file mode 100644 index cc29822f..00000000 --- a/test/src/NoteBinaryEncode_test.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*! - * @file NoteBinaryEncode_test.cpp - * - * Written by the Blues Inc. team. - * - * Copyright (c) 2023 Blues Inc. MIT License. Use of this source code is - * governed by licenses granted by the copyright holder including that found in - * the - * LICENSE - * file. - * - */ - -#ifdef NOTE_C_TEST - -#include - -#include -#include "fff.h" - -#include "n_lib.h" - -DEFINE_FFF_GLOBALS -FAKE_VALUE_FUNC(uint32_t, cobsEncode, uint8_t *, uint32_t, uint8_t, uint8_t *) - -uint8_t inBuf[10] = "Hi there!"; -uint32_t inLen; -uint8_t outBuf[12]; -uint32_t outLen; - -namespace -{ - -SCENARIO("NoteBinaryEncode") -{ - RESET_FAKE(cobsEncode); - uint32_t inLen = strlen((const char *)inBuf); - uint32_t outLen = sizeof(outBuf); - - GIVEN("Bad parameters are supplied") { - WHEN("inBuf is NULL") { - const char *err = NoteBinaryEncode(NULL, inLen, outBuf, &outLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outBuf is NULL") { - const char *err = NoteBinaryEncode(inBuf, inLen, NULL, &outLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outLen is NULL") { - const char *err = NoteBinaryEncode(inBuf, inLen, outBuf, NULL); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - WHEN("outLen is less than the size required for in place encoding") { - uint32_t badOutLen = (cobsEncodedLength(inBuf, inLen) - 1); - const char *err = NoteBinaryEncode(inBuf, inLen, outBuf, &badOutLen); - - THEN("An error is returned") { - CHECK(err != NULL); - } - } - } - - GIVEN("Parameters are in order") { - const uint32_t EXPECTED_RESULT = 79; - cobsEncode_fake.return_val = EXPECTED_RESULT; - const char *err = NoteBinaryEncode(inBuf, inLen, outBuf, &outLen); - - THEN("cobsEncode is invoked") { - CHECK(cobsEncode_fake.call_count > 0); - } - - WHEN("cobsEncode is invoked") { - THEN("The parameters are passed without modification") { - CHECK(cobsEncode_fake.arg0_history[0] == inBuf); - CHECK(cobsEncode_fake.arg1_history[0] == inLen); - CHECK(cobsEncode_fake.arg3_history[0] == outBuf); - } - - THEN("The result is returned without modification") { - CHECK(EXPECTED_RESULT == outLen); - } - } - } -} - -} - -#endif // NOTE_C_TEST diff --git a/test/src/NoteBinaryDataDecodedLength_test.cpp b/test/src/NoteBinaryStoreDecodedLength_test.cpp similarity index 81% rename from test/src/NoteBinaryDataDecodedLength_test.cpp rename to test/src/NoteBinaryStoreDecodedLength_test.cpp index 3a0dccb8..a892b86c 100644 --- a/test/src/NoteBinaryDataDecodedLength_test.cpp +++ b/test/src/NoteBinaryStoreDecodedLength_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryDataDecodedLength_test.cpp + * @file NoteBinaryStoreDecodedLength_test.cpp * * Written by the Blues Inc. team. * @@ -26,7 +26,7 @@ const size_t len = 10; namespace { -SCENARIO("NoteBinaryDataDecodedLength") +SCENARIO("NoteBinaryStoreDecodedLength") { RESET_FAKE(NoteRequestResponse); @@ -36,7 +36,7 @@ SCENARIO("NoteBinaryDataDecodedLength") GIVEN("Bad parameters are supplied") { WHEN("Length is NULL") { - const char *err = NoteBinaryDataDecodedLength(NULL); + const char *err = NoteBinaryStoreDecodedLength(NULL); THEN("An error is returned") { CHECK(err != NULL); @@ -51,8 +51,8 @@ SCENARIO("NoteBinaryDataDecodedLength") return NULL; }; - WHEN("NoteBinaryDataDecodedLength is called") { - const char *err = NoteBinaryDataDecodedLength(&size); + WHEN("NoteBinaryStoreDecodedLength is called") { + const char *err = NoteBinaryStoreDecodedLength(&size); REQUIRE(NoteRequestResponse_fake.call_count > 0); THEN("An error is returned") { @@ -70,8 +70,8 @@ SCENARIO("NoteBinaryDataDecodedLength") return rsp; }; - WHEN("NoteBinaryDataDecodedLength is called") { - const char *err = NoteBinaryDataDecodedLength(&size); + WHEN("NoteBinaryStoreDecodedLength is called") { + const char *err = NoteBinaryStoreDecodedLength(&size); REQUIRE(NoteRequestResponse_fake.call_count > 0); THEN("An error is returned") { @@ -90,8 +90,8 @@ SCENARIO("NoteBinaryDataDecodedLength") return rsp; }; - WHEN("NoteBinaryDataDecodedLength is called") { - const char *err = NoteBinaryDataDecodedLength(&size); + WHEN("NoteBinaryStoreDecodedLength is called") { + const char *err = NoteBinaryStoreDecodedLength(&size); REQUIRE(NoteRequestResponse_fake.call_count > 0); THEN("An error is not returned") { @@ -114,8 +114,8 @@ SCENARIO("NoteBinaryDataDecodedLength") return rsp; }; - WHEN("NoteBinaryDataDecodedLength is called") { - const char *err = NoteBinaryDataDecodedLength(&size); + WHEN("NoteBinaryStoreDecodedLength is called") { + const char *err = NoteBinaryStoreDecodedLength(&size); REQUIRE(NoteRequestResponse_fake.call_count > 0); THEN("An error is not returned") { diff --git a/test/src/NoteBinaryDataEncodedLength_test.cpp b/test/src/NoteBinaryStoreEncodedLength_test.cpp similarity index 76% rename from test/src/NoteBinaryDataEncodedLength_test.cpp rename to test/src/NoteBinaryStoreEncodedLength_test.cpp index 605e6cf4..d9e5cefb 100644 --- a/test/src/NoteBinaryDataEncodedLength_test.cpp +++ b/test/src/NoteBinaryStoreEncodedLength_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryDataEncodedLength_test.cpp + * @file NoteBinaryStoreEncodedLength_test.cpp * * Written by the Blues Inc. team. * @@ -18,6 +18,8 @@ #include "n_lib.h" +const char * NoteBinaryStoreEncodedLength(uint32_t *); + DEFINE_FFF_GLOBALS FAKE_VALUE_FUNC(J *, NoteRequestResponse, J *) @@ -26,7 +28,7 @@ const uint32_t cobsLen = 10; namespace { -SCENARIO("NoteBinaryDataEncodedLength") +SCENARIO("NoteBinaryStoreEncodedLength") { RESET_FAKE(NoteRequestResponse); @@ -36,7 +38,7 @@ SCENARIO("NoteBinaryDataEncodedLength") GIVEN("Bad parameters are supplied") { WHEN("Length is NULL") { - const char *err = NoteBinaryDataEncodedLength(NULL); + const char *err = NoteBinaryStoreEncodedLength(NULL); THEN("An error is returned") { CHECK(err != NULL); @@ -51,8 +53,8 @@ SCENARIO("NoteBinaryDataEncodedLength") return NULL; }; - WHEN("NoteBinaryDataEncodedLength is called") { - const char *err = NoteBinaryDataEncodedLength(&size); + WHEN("NoteBinaryStoreEncodedLength is called") { + const char *err = NoteBinaryStoreEncodedLength(&size); THEN("An error is returned") { CHECK(err != NULL); @@ -69,8 +71,8 @@ SCENARIO("NoteBinaryDataEncodedLength") return rsp; }; - WHEN("NoteBinaryDataEncodedLength is called") { - const char *err = NoteBinaryDataEncodedLength(&size); + WHEN("NoteBinaryStoreEncodedLength is called") { + const char *err = NoteBinaryStoreEncodedLength(&size); THEN("An error is returned") { CHECK(err != NULL); @@ -88,8 +90,8 @@ SCENARIO("NoteBinaryDataEncodedLength") return rsp; }; - WHEN("NoteBinaryDataEncodedLength is called") { - const char *err = NoteBinaryDataEncodedLength(&size); + WHEN("NoteBinaryStoreEncodedLength is called") { + const char *err = NoteBinaryStoreEncodedLength(&size); THEN("An error is not returned") { CHECK(err == NULL); @@ -111,16 +113,16 @@ SCENARIO("NoteBinaryDataEncodedLength") return rsp; }; - WHEN("NoteBinaryDataEncodedLength is called") { - const char *err = NoteBinaryDataEncodedLength(&size); + WHEN("NoteBinaryStoreEncodedLength is called") { + const char *err = NoteBinaryStoreEncodedLength(&size); THEN("An error is not returned") { CHECK(err == NULL); } THEN("The size out parameter is the cobs value in the card.binary " - "response, plus 1 for the trailing newline") { - CHECK(size == cobsLen + 1); + "response") { + CHECK(size == cobsLen); } } } diff --git a/test/src/NoteBinaryReceive_test.cpp b/test/src/NoteBinaryStoreReceive_test.cpp similarity index 70% rename from test/src/NoteBinaryReceive_test.cpp rename to test/src/NoteBinaryStoreReceive_test.cpp index e85edf72..deee29fa 100644 --- a/test/src/NoteBinaryReceive_test.cpp +++ b/test/src/NoteBinaryStoreReceive_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryReceive_test.cpp + * @file NoteBinaryStoreReceive_test.cpp * * Written by the Blues Inc. team. * @@ -20,7 +20,7 @@ DEFINE_FFF_GLOBALS FAKE_VALUE_FUNC(J *, NoteNewRequest, const char *) -FAKE_VALUE_FUNC(const char *, NoteBinaryDataEncodedLength, uint32_t *) +FAKE_VALUE_FUNC(const char *, NoteBinaryStoreEncodedLength, uint32_t *) FAKE_VALUE_FUNC(J *, NoteRequestResponse, J *) FAKE_VALUE_FUNC(const char *, NoteChunkedReceive, uint8_t *, uint32_t *, bool, size_t, uint32_t *) @@ -35,7 +35,8 @@ FAKE_VOID_FUNC(NoteUnlockNote) // a compiler error. uint8_t buf[32]; uint32_t bufLen = sizeof(buf); -uint32_t dataLen = 0; +uint32_t decodedOffset = 0; +uint32_t decodedLen = 17; char rawMsg[] = "Hello Blues!"; uint32_t rawMsgLen = strlen(rawMsg); @@ -43,17 +44,15 @@ uint32_t rawMsgLen = strlen(rawMsg); namespace { -SCENARIO("NoteBinaryReceive") +SCENARIO("NoteBinaryStoreReceive") { RESET_FAKE(NoteNewRequest); - RESET_FAKE(NoteBinaryDataEncodedLength); + RESET_FAKE(NoteBinaryStoreEncodedLength); RESET_FAKE(NoteRequestResponse); RESET_FAKE(NoteChunkedReceive); RESET_FAKE(NoteLockNote); RESET_FAKE(NoteUnlockNote); - const uint32_t OFFSET_ZERO = 0; - NoteSetFnDefault(malloc, free, NULL, NULL); // These fakes are the default. Tests below may override them to exercise @@ -61,7 +60,7 @@ SCENARIO("NoteBinaryReceive") NoteNewRequest_fake.custom_fake = [](const char *req) -> J* { return JCreateObject(); }; - NoteBinaryDataEncodedLength_fake.custom_fake = [](uint32_t *size) + NoteBinaryStoreEncodedLength_fake.custom_fake = [](uint32_t *size) -> const char * { *size = bufLen; @@ -78,12 +77,36 @@ SCENARIO("NoteBinaryReceive") return rsp; }; + GIVEN("Bad parameters are supplied") { + WHEN("buffer is NULL") { + const char *err = NoteBinaryStoreReceive(NULL, bufLen, decodedOffset, decodedLen); + + THEN("An error is returned") { + CHECK(err != NULL); + } + } + WHEN("bufLen is too small") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, bufLen); + + THEN("An error is returned") { + CHECK(err != NULL); + } + } + WHEN("decodedLen is zero") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, 0); + + THEN("An error is returned") { + CHECK(err != NULL); + } + } + } + GIVEN("Allocating the card.binary.get request fails") { NoteNewRequest_fake.custom_fake = NULL; NoteNewRequest_fake.return_val = NULL; - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteNewRequest_fake.call_count > 0); THEN("An error is returned") { @@ -101,8 +124,8 @@ SCENARIO("NoteBinaryReceive") return rsp; }; - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteRequestResponse_fake.call_count > 0); THEN("An error is returned") { @@ -114,8 +137,8 @@ SCENARIO("NoteBinaryReceive") GIVEN("NoteChunkedReceive returns an error") { NoteChunkedReceive_fake.return_val = "some error"; - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteChunkedReceive_fake.call_count > 0); THEN("An error is returned") { @@ -133,8 +156,8 @@ SCENARIO("NoteBinaryReceive") return NULL; }; - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteChunkedReceive_fake.call_count > 0); THEN("An error is returned") { @@ -146,8 +169,7 @@ SCENARIO("NoteBinaryReceive") GIVEN("The binary payload is received") { NoteChunkedReceive_fake.custom_fake = [](uint8_t *buffer, uint32_t *size, bool, size_t, uint32_t *available) -> const char* { - uint32_t outLen = *size; - NoteBinaryEncode((uint8_t *)rawMsg, rawMsgLen, buffer, &outLen); + uint32_t outLen = NoteBinaryCodecEncode((uint8_t *)rawMsg, rawMsgLen, buffer, *size); buffer[outLen] = '\n'; *size = outLen + 1; @@ -165,8 +187,8 @@ SCENARIO("NoteBinaryReceive") return rsp; }; - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteChunkedReceive_fake.call_count > 0); REQUIRE(NoteRequestResponse_fake.call_count > 0); @@ -177,27 +199,22 @@ SCENARIO("NoteBinaryReceive") } AND_GIVEN("The computed MD5 matches the status field") { - WHEN("NoteBinaryReceive is called") { - const char *err = NoteBinaryReceive(buf, bufLen, OFFSET_ZERO, &dataLen); + WHEN("NoteBinaryStoreReceive is called") { + uint32_t decodedLen = rawMsgLen; + const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen); REQUIRE(NoteChunkedReceive_fake.call_count > 0); THEN("No error is returned") { CHECK(err == NULL); } - THEN("The length of the payload is returned in the dataLen out" - " parameter") { - CHECK(dataLen == rawMsgLen); - } - THEN("The decoded payload is as expected, with no trailing " "newline") { - CHECK(memcmp(buf, rawMsg, dataLen) == 0); + CHECK(memcmp(buf, rawMsg, decodedLen) == 0); } } } } - CHECK(NoteLockNote_fake.call_count > 0); CHECK(NoteLockNote_fake.call_count == NoteUnlockNote_fake.call_count); } diff --git a/test/src/NoteBinaryDataReset_test.cpp b/test/src/NoteBinaryStoreReset_test.cpp similarity index 81% rename from test/src/NoteBinaryDataReset_test.cpp rename to test/src/NoteBinaryStoreReset_test.cpp index 2ea6f5fe..3f8a3617 100644 --- a/test/src/NoteBinaryDataReset_test.cpp +++ b/test/src/NoteBinaryStoreReset_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryDataReset_test.cpp + * @file NoteBinaryStoreReset_test.cpp * * Written by the Blues Inc. team. * @@ -25,17 +25,15 @@ FAKE_VALUE_FUNC(J *, NoteRequestResponse, J *) namespace { -SCENARIO("NoteBinaryDataReset") +SCENARIO("NoteBinaryStoreReset") { - RESET_FAKE(NoteNewRequest); - RESET_FAKE(NoteRequestResponse); - NoteSetFnDefault(malloc, free, NULL, NULL); NoteNewRequest_fake.custom_fake = [](const char *req) -> J * { return JCreateObject(); }; NoteRequestResponse_fake.custom_fake = [](J *req) -> J * { + JDelete(req); return JCreateObject(); }; @@ -43,8 +41,8 @@ SCENARIO("NoteBinaryDataReset") NoteNewRequest_fake.custom_fake = NULL; NoteNewRequest_fake.return_val = NULL; - WHEN("NoteBinaryDataReset is called") { - const char *err = NoteBinaryDataReset(); + WHEN("NoteBinaryStoreReset is called") { + const char *err = NoteBinaryStoreReset(); THEN("An error is returned") { CHECK(err != NULL); @@ -61,8 +59,8 @@ SCENARIO("NoteBinaryDataReset") return rsp; }; - WHEN("NoteBinaryDataReset is called") { - const char *err = NoteBinaryDataReset(); + WHEN("NoteBinaryStoreReset is called") { + const char *err = NoteBinaryStoreReset(); THEN("An error is returned") { CHECK(err != NULL); @@ -71,14 +69,17 @@ SCENARIO("NoteBinaryDataReset") } GIVEN("The response to the card.binary indicates success") { - WHEN("NoteBinaryDataReset is called") { - const char *err = NoteBinaryDataReset(); + WHEN("NoteBinaryStoreReset is called") { + const char *err = NoteBinaryStoreReset(); THEN("An error is not returned") { CHECK(err == NULL); } } } + + RESET_FAKE(NoteNewRequest); + RESET_FAKE(NoteRequestResponse); } } diff --git a/test/src/NoteBinaryTransmit_test.cpp b/test/src/NoteBinaryStoreTransmit_test.cpp similarity index 82% rename from test/src/NoteBinaryTransmit_test.cpp rename to test/src/NoteBinaryStoreTransmit_test.cpp index 701e0929..a4ad0e76 100644 --- a/test/src/NoteBinaryTransmit_test.cpp +++ b/test/src/NoteBinaryStoreTransmit_test.cpp @@ -1,5 +1,5 @@ /*! - * @file NoteBinaryTransmit_test.cpp + * @file NoteBinaryStoreTransmit_test.cpp * * Written by the Blues Inc. team. * @@ -33,7 +33,7 @@ uint32_t bufLen = sizeof(buf); namespace { -SCENARIO("NoteBinaryTransmit") +SCENARIO("NoteBinaryStoreTransmit") { RESET_FAKE(NoteNewRequest); RESET_FAKE(NoteRequestResponse); @@ -58,8 +58,8 @@ SCENARIO("NoteBinaryTransmit") return NULL; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -76,8 +76,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -94,8 +94,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -114,8 +114,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -136,9 +136,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -158,9 +157,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - dataLen); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, dataLen); THEN("An error is returned") { CHECK(err != NULL); @@ -184,12 +182,12 @@ SCENARIO("NoteBinaryTransmit") // Discover the actual encoded length of the data const uint32_t tempBufLen = cobsEncodedMaxLength(dataLen); uint8_t *tempBuf = (uint8_t *)malloc(tempBufLen); - uint32_t newBufLen = tempBufLen; - REQUIRE(!NoteBinaryEncode(buf, dataLen, tempBuf, &newBufLen)); + uint32_t encLen = NoteBinaryCodecEncode(buf, dataLen, tempBuf, tempBufLen); + REQUIRE(encLen > 0); free(tempBuf); - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, newBufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, encLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -215,8 +213,8 @@ SCENARIO("NoteBinaryTransmit") J *noteNewReqRetSequence[] = {JCreateObject(), NULL}; SET_RETURN_SEQ(NoteNewRequest, noteNewReqRetSequence, 2); - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -235,8 +233,8 @@ SCENARIO("NoteBinaryTransmit") return false; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -256,8 +254,8 @@ SCENARIO("NoteBinaryTransmit") }; NoteChunkedTransmit_fake.return_val = "some error"; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -299,9 +297,8 @@ SCENARIO("NoteBinaryTransmit") return NULL; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -323,9 +320,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -348,9 +344,8 @@ SCENARIO("NoteBinaryTransmit") return rsp; }; - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("An error is returned") { CHECK(err != NULL); @@ -385,9 +380,8 @@ SCENARIO("NoteBinaryTransmit") SET_CUSTOM_FAKE_SEQ(NoteRequestResponse, reqRespFakeSequenceSuccess, 3); - WHEN("NoteBinaryTransmit is called") { - const char *err = NoteBinaryTransmit(buf, dataLen, bufLen, - 0); + WHEN("NoteBinaryStoreTransmit is called") { + const char *err = NoteBinaryStoreTransmit(buf, dataLen, bufLen, 0); THEN("No error is returned") { CHECK(err == NULL);