diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9849431..f517e0f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/src/NoteResponseError_test.cpp b/test/src/NoteResponseError_test.cpp new file mode 100644 index 0000000..ef1c6f5 --- /dev/null +++ b/test/src/NoteResponseError_test.cpp @@ -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 + * LICENSE + * file. + * + */ + +#include +//#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); + } + +} +