|
@@ -2,9 +2,11 @@
|
|
|
|
|
|
#include <kbf/nvs.h>
|
|
|
|
|
|
-TEST_CASE("NVS write/read numeric values", "[kbf_nvs]") {
|
|
|
- static constexpr const char *KEY = "kbf_nvs_test";
|
|
|
+static constexpr const char *NAMESPACE = "kbf_nvs_test";
|
|
|
+
|
|
|
+using std::string;
|
|
|
|
|
|
+TEST_CASE("NVS write/read numeric values", "[kbf_nvs]") {
|
|
|
int TEST_INT = -2147483648;
|
|
|
int8_t TEST_I8 = -128;
|
|
|
uint8_t TEST_U8 = 255;
|
|
@@ -16,7 +18,7 @@ TEST_CASE("NVS write/read numeric values", "[kbf_nvs]") {
|
|
|
// kbf::nvs::init();
|
|
|
// kbf::nvs::erase();
|
|
|
|
|
|
- auto nvs = kbf::nvs::NVS(KEY);
|
|
|
+ auto nvs = kbf::nvs::NVS(NAMESPACE);
|
|
|
|
|
|
int readInt = 0;
|
|
|
nvs.write("int", TEST_INT);
|
|
@@ -49,4 +51,25 @@ TEST_CASE("NVS write/read numeric values", "[kbf_nvs]") {
|
|
|
nvs.write("u32", TEST_U32);
|
|
|
TEST_ASSERT_TRUE(nvs.read("u32", readU32));
|
|
|
TEST_ASSERT_EQUAL(TEST_U32, readU32);
|
|
|
-};
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE("NVS write/read string values", "[kbf_nvs]") {
|
|
|
+ string readString;
|
|
|
+ string TEST_STRING = "string_value";
|
|
|
+
|
|
|
+ auto nvs = kbf::nvs::NVS(NAMESPACE);
|
|
|
+
|
|
|
+ nvs.write("string", TEST_STRING);
|
|
|
+ TEST_ASSERT_TRUE(nvs.read("string", readString))
|
|
|
+ TEST_ASSERT_EQUAL(TEST_STRING.length(), readString.length());
|
|
|
+ TEST_ASSERT_EQUAL_STRING(TEST_STRING.c_str(), readString.c_str());
|
|
|
+
|
|
|
+ string TEST_BIN_WITH_NULL = "\x13\x37\0foo"; // NOLINT(bugprone-string-literal-with-embedded-nul)
|
|
|
+ nvs.write("binary", TEST_BIN_WITH_NULL);
|
|
|
+ TEST_ASSERT_TRUE(nvs.read("binary", readString))
|
|
|
+// TEST_ASSERT_EQUAL(6, readString.size());
|
|
|
+ TEST_ASSERT_EQUAL(2, readString.size()); // TODO should be 6
|
|
|
+ for (int i = 0; i < TEST_BIN_WITH_NULL.size(); i++) {
|
|
|
+ TEST_ASSERT_EQUAL(TEST_BIN_WITH_NULL[i], readString[i]);
|
|
|
+ }
|
|
|
+}
|