Skip to content

Commit

Permalink
chore: rename binary RX API
Browse files Browse the repository at this point in the history
  • Loading branch information
zfields committed Sep 8, 2023
1 parent 97ee798 commit cc3071a
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 296 deletions.
15 changes: 7 additions & 8 deletions n_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ uint32_t NoteBinaryMaxEncodedLength(uint32_t unencodedLength)

//**************************************************************************/
/*!
@brief Receive a large binary object from the Notecard's binary buffer
@brief Receive the Notecard's entire binary buffer
@param buffer A buffer to hold the binary object
@param bufLen The total length of the provided buffer
Expand All @@ -357,8 +357,8 @@ uint32_t NoteBinaryMaxEncodedLength(uint32_t unencodedLength)
`NoteBinaryDataEncodedLength()`.
*/
/**************************************************************************/
const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen,
uint32_t *dataLen)
const char * NoteBinaryReceiveAll(uint8_t *buffer, uint32_t bufLen,
uint32_t *dataLen)
{
const char *err = NULL;
uint32_t decodedLen = 0;
Expand All @@ -376,7 +376,7 @@ const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen,
decodedLen = 0;
}
// Request entire binary data store from Notecard
else if ((err = NoteBinaryReceiveRange(buffer, bufLen, 0, decodedLen))) {
else if ((err = NoteBinaryReceive(buffer, bufLen, 0, decodedLen))) {
decodedLen = 0;
}

Expand All @@ -389,7 +389,7 @@ const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen,

//**************************************************************************/
/*!
@brief Receive a large binary range from the Notecard's binary buffer
@brief Receive a large binary object from the Notecard's binary buffer
@param buffer A buffer to hold the binary range
@param bufLen The total length of the provided buffer
Expand All @@ -407,9 +407,8 @@ const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen,
entire buffer use `NoteBinaryDataEncodedLength()` instead.
*/
/**************************************************************************/
const char * NoteBinaryReceiveRange(uint8_t *buffer, uint32_t bufLen,
uint32_t decodedOffset,
uint32_t decodedLen)
const char * NoteBinaryReceive(uint8_t *buffer, uint32_t bufLen,
uint32_t decodedOffset, uint32_t decodedLen)
{
// Validate parameter(s)
if (!buffer) {
Expand Down
5 changes: 2 additions & 3 deletions note.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ const char * NoteBinaryEncode(const uint8_t *inBuf, uint32_t inLen,
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 * NoteBinaryReceiveAll(uint8_t *buffer, uint32_t bufLen,
uint32_t *dataLen);
const char * NoteBinaryReceiveRange(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 NoteSetSTSecs(uint32_t secs);
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ add_test(NoteBinaryEncode_test)
add_test(NoteBinaryMaxEncodedLength_test)
add_test(NoteBinaryMaxDecodedLength_test)
add_test(NoteBinaryReceive_test)
add_test(NoteBinaryReceiveRange_test)
add_test(NoteBinaryReceiveAll_test)
add_test(NoteBinaryTransmit_test)

if(NOTE_C_COVERAGE)
Expand Down
124 changes: 124 additions & 0 deletions test/src/NoteBinaryReceiveAll_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*!
* @file NoteBinaryReceiveAll_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
* <a href="https://github.com/blues/note-c/blob/master/LICENSE">LICENSE</a>
* file.
*
*/

#ifdef NOTE_C_TEST

#include <catch2/catch_test_macros.hpp>
#include "fff.h"

#include "n_lib.h"

DEFINE_FFF_GLOBALS
FAKE_VALUE_FUNC(const char *, NoteBinaryDataDecodedLength, uint32_t *)
FAKE_VALUE_FUNC(const char *, NoteBinaryReceive, uint8_t *, uint32_t, uint32_t, uint32_t)

uint8_t buffer[12];
const uint32_t bufLen = sizeof(buffer);
uint32_t dataLen = 0;

namespace
{

SCENARIO("NoteBinaryReceiveAll")
{
RESET_FAKE(NoteBinaryDataDecodedLength);
RESET_FAKE(NoteBinaryReceive);
dataLen = 17;

GIVEN("Bad parameters are supplied") {
WHEN("buffer is NULL") {
const char *err = NoteBinaryReceiveAll(NULL, bufLen, &dataLen);

THEN("An error is returned") {
CHECK(err != NULL);
}
}
WHEN("dataLen is NULL") {
const char *err = NoteBinaryReceiveAll(buffer, bufLen, NULL);

THEN("An error is returned") {
CHECK(err != NULL);
}
}
}

GIVEN("NoteBinaryDataDecodedLength() is invoked") {
WHEN("An error is encountered") {
const char *errMsg = "ERROR! Hacking too much time!";
NoteBinaryDataDecodedLength_fake.return_val = errMsg;
const char *err = NoteBinaryReceiveAll(buffer, bufLen, &dataLen);

REQUIRE(NoteBinaryDataDecodedLength_fake.call_count > 0);
THEN("NoteBinaryReceive() is not invoked") {
CHECK(NoteBinaryReceive_fake.call_count == 0);
}
THEN("The dataLen is set to zero") {
CHECK(dataLen == 0);
}
THEN("The error is returned") {
CHECK(!strcmp(err,errMsg));
}
}
WHEN("No error is encountered") {
const uint32_t DECODED_LEN = 79;
NoteBinaryDataDecodedLength_fake.custom_fake = [](uint32_t *len) -> const char * {
*len = DECODED_LEN;
return NULL;
};
const char *err = NoteBinaryReceiveAll(buffer, bufLen, &dataLen);

REQUIRE(NoteBinaryDataDecodedLength_fake.call_count > 0);
THEN("NoteBinaryReceive() is invoked") {
CHECK(NoteBinaryReceive_fake.call_count > 0);
}
THEN("The decoded length is passed to NoteBinaryReceive()") {
CHECK(NoteBinaryReceive_fake.arg3_history[0] == DECODED_LEN);
}
}
}
GIVEN("NoteBinaryReceive() is invoked") {
const uint32_t DECODED_LEN = 79;
NoteBinaryDataDecodedLength_fake.custom_fake = [](uint32_t *len) -> const char * {
*len = DECODED_LEN;
return NULL;
};
WHEN("An error is encountered") {
const char *errMsg = "ERROR! Hacking too much time!";
NoteBinaryReceive_fake.return_val = errMsg;
const char *err = NoteBinaryReceiveAll(buffer, bufLen, &dataLen);

REQUIRE(NoteBinaryReceive_fake.call_count > 0);
THEN("The dataLen is set to zero") {
CHECK(dataLen == 0);
}
THEN("The error is returned") {
CHECK(!strcmp(err,errMsg));
}
}
WHEN("No error is encountered") {
const char *err = NoteBinaryReceiveAll(buffer, bufLen, &dataLen);

REQUIRE(NoteBinaryReceive_fake.call_count > 0);
THEN("The decoded length is returned") {
CHECK(dataLen == DECODED_LEN);
}
THEN("The return value is NULL") {
CHECK(err == NULL);
}
}
}
}

}

#endif // NOTE_C_TEST
Loading

0 comments on commit cc3071a

Please sign in to comment.