Skip to content

Commit

Permalink
feat: NoteResponseError test
Browse files Browse the repository at this point in the history
adds test case for checking the NoteResponseError macro returns the correct results for different JSON messages (#148)
  • Loading branch information
gwolffblues authored Jun 19, 2024
1 parent f0d4c04 commit 1b6c8c8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ add_test(Jtolower_test)
add_test(JSON_number_handling_test)
add_test(JAtoN_test)
add_test(JNtoA_test)
add_test(NoteResponseError_test)

if(NOTE_C_COVERAGE)
find_program(LCOV lcov REQUIRED)
Expand Down
53 changes: 53 additions & 0 deletions test/src/NoteResponseError_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*!
* @file NoteTransaction_test.cpp
*
* Written by the Blues Inc. team.
*
* Copyright (c) 2024 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.
*
*/

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

#include "n_lib.h"
#include "test_static.h"

// DEFINE_FFF_GLOBALS
// FAKE_VALUE_FUNC(bool, NoteReset)
// FAKE_VALUE_FUNC(const char *, noteJSONTransaction, const char *, size_t, char **, uint32_t)
// FAKE_VALUE_FUNC(bool, noteTransactionStart, uint32_t)
// FAKE_VALUE_FUNC(J *, NoteUserAgent)
// FAKE_VALUE_FUNC(bool, crcError, char *, uint16_t)


SCENARIO("NoteResponseError")
{
NoteSetFnDefault(malloc, free, NULL, NULL);

// // NoteReset's mock should succeed unless the test explicitly instructs
// // it to fail.
// NoteReset_fake.return_val = true;
// noteTransactionStart_fake.return_val = true;
// crcError_fake.return_val = false;

SECTION("No err field, returns false") {
J* rsp = JParse("{\"test\":\"me\"}");
//CHECK(rsp == NULL);
CHECK(!(NoteResponseError(rsp)));
JDelete(rsp);
}

SECTION("Supplying a response with err returns True") {
J* rsp = JParse("{\"err\":\"DFU mode is not yet fully active: starting communications {wait-module} {connecting} {dfu-not-ready}\"}\n");
bool hasError = NoteResponseError(rsp);
CHECK((hasError ==true && rsp != NULL));
JDelete(rsp);
}

}

0 comments on commit 1b6c8c8

Please sign in to comment.