Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/microStore/Adapters/PosixFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ class PosixFileSystem : public microStore::FileSystem {
}

inline virtual bool rmdir(const char* path) override {
if (::rmdir(path) == 0) {
return false;
}
return true;
return (::rmdir(path) == 0);
}


Expand Down
5 changes: 1 addition & 4 deletions include/microStore/Adapters/StdioFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ class StdioFileSystem : public microStore::FileSystem {
}

inline virtual bool rmdir(const char* path) override {
if (::rmdir(path) == 0) {
return false;
}
return true;
return (::rmdir(path) == 0);
}


Expand Down
75 changes: 75 additions & 0 deletions test/test_posix_fs/test_posix_fs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Tests for the POSIX and stdio filesystem adapters against a real
* temporary directory.
*/

#include <unity.h>
#include <microStore/Adapters/PosixFileSystem.h>
#include <microStore/Adapters/StdioFileSystem.h>

#include <cstdlib>
#include <string>
#include <sys/stat.h>
#include <unistd.h>

static std::string tmp;

static bool is_dir(const std::string& path) {
struct stat st;
return ::stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
}

/* ---- rmdir ---- */

static void check_rmdir(microStore::FileSystem fs) {
const std::string dir = tmp + "/sub";
TEST_ASSERT_TRUE(fs.mkdir(dir.c_str()));
TEST_ASSERT_TRUE(fs.rmdir(dir.c_str()));
TEST_ASSERT_FALSE(is_dir(dir));
TEST_ASSERT_FALSE(fs.rmdir(dir.c_str()));
}

void test_posix_rmdir_reports_result() {
check_rmdir(microStore::Adapters::PosixFileSystem());
}

void test_stdio_rmdir_reports_result() {
check_rmdir(microStore::Adapters::StdioFileSystem());
}

/* ---- Main ---- */

void setUp() {
char tmpl[] = "/tmp/microstore_fs_XXXXXX";
TEST_ASSERT_NOT_NULL(::mkdtemp(tmpl));
tmp = tmpl;
}

void tearDown() {
std::string cmd = "rm -rf '" + tmp + "'";
(void)std::system(cmd.c_str());
}

int runUnityTests(void) {
UNITY_BEGIN();
RUN_TEST(test_posix_rmdir_reports_result);
RUN_TEST(test_stdio_rmdir_reports_result);
return UNITY_END();
}

// For native dev-platform or for some embedded frameworks
int main(void) {
return runUnityTests();
}

#ifdef ARDUINO
// For Arduino framework
void setup() {
// Wait ~2 seconds before the Unity test runner
// establishes connection with a board Serial interface
delay(2000);

runUnityTests();
}
void loop() {}
#endif