Skip to content

Commit 6246659

Browse files
committed
A few tests for filesystem APIs
1 parent 5724f38 commit 6246659

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/host/fs/test_fs.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// test_fs.cpp
3+
// esp8266-host-tests
4+
//
5+
// Created by Ivan Grokhotkov on 02/03/16.
6+
// Copyright © 2016 esp8266.com. All rights reserved.
7+
//
8+
9+
#include <catch.hpp>
10+
#include <FS.h>
11+
#include "../common/spiffs_mock.h"
12+
13+
#define SPIFFS_SIZE (64*1024)
14+
#define SPIFFS_BLOCK (2*4096)
15+
#define SPIFFS_PAGE (512)
16+
#define SPIFFS_MOCK_DECLARE(size_kb, block_kb, page_b) SpiffsMock mock(size_kb * 1024, block_kb * 1024, page_b)
17+
18+
TEST_CASE("FS can begin","[fs]")
19+
{
20+
SPIFFS_MOCK_DECLARE(1024, 8, 512);
21+
REQUIRE(SPIFFS.begin());
22+
}
23+
24+
TEST_CASE("FS can create file","[fs]")
25+
{
26+
SPIFFS_MOCK_DECLARE(1024, 8, 512);
27+
REQUIRE(SPIFFS.begin());
28+
{
29+
File f = SPIFFS.open("config.txt", "w");
30+
REQUIRE(f);
31+
}
32+
REQUIRE(SPIFFS.exists("config.txt"));
33+
}
34+
35+
TEST_CASE("Files can be written and appended to","[fs]")
36+
{
37+
SPIFFS_MOCK_DECLARE(1024, 8, 512);
38+
REQUIRE(SPIFFS.begin());
39+
{
40+
File f = SPIFFS.open("config1.txt", "w");
41+
f.println("file 1");
42+
REQUIRE(f);
43+
}
44+
{
45+
File f = SPIFFS.open("config1.txt", "a");
46+
REQUIRE(f);
47+
f.println("file 1 again");
48+
}
49+
{
50+
File f = SPIFFS.open("config1.txt", "r");
51+
REQUIRE(f);
52+
char buf[128];
53+
size_t len = f.read((uint8_t*)buf, sizeof(buf));
54+
buf[len] = 0;
55+
REQUIRE(strcmp(buf, "file 1\r\nfile 1 again\r\n") == 0);
56+
}
57+
}
58+
59+

0 commit comments

Comments
 (0)