From 624665911dfac958d8bbb0f024a937cb9d017276 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 3 Mar 2016 09:38:26 +0300 Subject: [PATCH] A few tests for filesystem APIs --- tests/host/fs/test_fs.cpp | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/host/fs/test_fs.cpp diff --git a/tests/host/fs/test_fs.cpp b/tests/host/fs/test_fs.cpp new file mode 100644 index 000000000..c510f4ac5 --- /dev/null +++ b/tests/host/fs/test_fs.cpp @@ -0,0 +1,59 @@ +// +// test_fs.cpp +// esp8266-host-tests +// +// Created by Ivan Grokhotkov on 02/03/16. +// Copyright © 2016 esp8266.com. All rights reserved. +// + +#include +#include +#include "../common/spiffs_mock.h" + +#define SPIFFS_SIZE (64*1024) +#define SPIFFS_BLOCK (2*4096) +#define SPIFFS_PAGE (512) +#define SPIFFS_MOCK_DECLARE(size_kb, block_kb, page_b) SpiffsMock mock(size_kb * 1024, block_kb * 1024, page_b) + +TEST_CASE("FS can begin","[fs]") +{ + SPIFFS_MOCK_DECLARE(1024, 8, 512); + REQUIRE(SPIFFS.begin()); +} + +TEST_CASE("FS can create file","[fs]") +{ + SPIFFS_MOCK_DECLARE(1024, 8, 512); + REQUIRE(SPIFFS.begin()); + { + File f = SPIFFS.open("config.txt", "w"); + REQUIRE(f); + } + REQUIRE(SPIFFS.exists("config.txt")); +} + +TEST_CASE("Files can be written and appended to","[fs]") +{ + SPIFFS_MOCK_DECLARE(1024, 8, 512); + REQUIRE(SPIFFS.begin()); + { + File f = SPIFFS.open("config1.txt", "w"); + f.println("file 1"); + REQUIRE(f); + } + { + File f = SPIFFS.open("config1.txt", "a"); + REQUIRE(f); + f.println("file 1 again"); + } + { + File f = SPIFFS.open("config1.txt", "r"); + REQUIRE(f); + char buf[128]; + size_t len = f.read((uint8_t*)buf, sizeof(buf)); + buf[len] = 0; + REQUIRE(strcmp(buf, "file 1\r\nfile 1 again\r\n") == 0); + } +} + +