mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Fixed missing implementations
This commit is contained in:
parent
6d2fa2e0f1
commit
e228a2102d
@ -56,14 +56,14 @@ esp_err_t NVSHandleSimple::get_string(const char *key, char* out_str, size_t len
|
||||
{
|
||||
if (!valid) return ESP_ERR_NVS_INVALID_HANDLE;
|
||||
|
||||
return ESP_FAIL;
|
||||
return mStoragePtr->readItem(mNsIndex, nvs::ItemType::SZ, key, out_str, len);
|
||||
}
|
||||
|
||||
esp_err_t NVSHandleSimple::get_blob(const char *key, void* out_blob, size_t len)
|
||||
{
|
||||
if (!valid) return ESP_ERR_NVS_INVALID_HANDLE;
|
||||
|
||||
return ESP_FAIL;
|
||||
return mStoragePtr->readItem(mNsIndex, nvs::ItemType::BLOB, key, out_blob, len);
|
||||
}
|
||||
|
||||
esp_err_t NVSHandleSimple::get_item_size(ItemType datatype, const char *key, size_t &size)
|
||||
|
@ -130,3 +130,62 @@ TEST_CASE("NVSHandleSimple CXX api open default part ns NULL", "[nvs cxx]")
|
||||
|
||||
nvs::NVSPartitionManager::get_instance()->deinit_partition("nvs");
|
||||
}
|
||||
|
||||
TEST_CASE("NVSHandleSimple CXX api read/write string", "[nvs cxx]")
|
||||
{
|
||||
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
|
||||
SpiFlashEmulator emu(10);
|
||||
char read_buffer [256];
|
||||
esp_err_t result;
|
||||
shared_ptr<nvs::NVSHandle> handle;
|
||||
|
||||
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom("nvs", NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
|
||||
== ESP_OK);
|
||||
|
||||
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
|
||||
|
||||
handle = nvs::open_nvs_handle("test_ns", NVS_READWRITE, &result);
|
||||
CHECK(result == ESP_OK);
|
||||
REQUIRE(handle);
|
||||
|
||||
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
|
||||
|
||||
CHECK(handle->set_string("test", "test string") == ESP_OK);
|
||||
CHECK(handle->commit() == ESP_OK);
|
||||
CHECK(handle->get_string("test", read_buffer, sizeof(read_buffer)) == ESP_OK);
|
||||
|
||||
CHECK(string(read_buffer) == "test string");
|
||||
|
||||
nvs::NVSPartitionManager::get_instance()->deinit_partition("nvs");
|
||||
}
|
||||
|
||||
TEST_CASE("NVSHandleSimple CXX api read/write blob", "[nvs cxx]")
|
||||
{
|
||||
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
|
||||
SpiFlashEmulator emu(10);
|
||||
const char blob [6] = {15, 16, 17, 18, 19};
|
||||
char read_blob[6] = {0};
|
||||
esp_err_t result;
|
||||
shared_ptr<nvs::NVSHandle> handle;
|
||||
|
||||
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom("nvs", NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
|
||||
== ESP_OK);
|
||||
|
||||
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
|
||||
|
||||
handle = nvs::open_nvs_handle("test_ns", NVS_READWRITE, &result);
|
||||
CHECK(result == ESP_OK);
|
||||
REQUIRE(handle);
|
||||
|
||||
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
|
||||
|
||||
CHECK(handle->set_blob("test", blob, sizeof(blob)) == ESP_OK);
|
||||
CHECK(handle->commit() == ESP_OK);
|
||||
CHECK(handle->get_blob("test", read_blob, sizeof(read_blob)) == ESP_OK);
|
||||
|
||||
CHECK(vector<char>(blob, blob + sizeof(blob)) == vector<char>(read_blob, read_blob + sizeof(read_blob)));
|
||||
|
||||
nvs::NVSPartitionManager::get_instance()->deinit_partition("nvs");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user