diff options
Diffstat (limited to 'src/drivers/test')
| -rw-r--r-- | src/drivers/test/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/drivers/test/test_example.cpp | 9 | ||||
| -rw-r--r-- | src/drivers/test/test_storage.cpp | 74 |
3 files changed, 75 insertions, 10 deletions
diff --git a/src/drivers/test/CMakeLists.txt b/src/drivers/test/CMakeLists.txt index f6690c4d..83904339 100644 --- a/src/drivers/test/CMakeLists.txt +++ b/src/drivers/test/CMakeLists.txt @@ -1 +1 @@ -idf_component_register(SRC_DIRS "." INCLUDE_DIRS "." REQUIRES catch2 cmock drivers) +idf_component_register(SRCS "test_storage.cpp" INCLUDE_DIRS "." REQUIRES catch2 cmock drivers) diff --git a/src/drivers/test/test_example.cpp b/src/drivers/test/test_example.cpp deleted file mode 100644 index ef90cf8f..00000000 --- a/src/drivers/test/test_example.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "catch2/catch.hpp" - -TEST_CASE("Example test case", "[cooltag]") { - REQUIRE ( 1 == 1 ); -} - -TEST_CASE("test that doesn't run", "[cooltag][!mayfail]") { - REQUIRE ( 0 == 1 ); -} diff --git a/src/drivers/test/test_storage.cpp b/src/drivers/test/test_storage.cpp new file mode 100644 index 00000000..178ec815 --- /dev/null +++ b/src/drivers/test/test_storage.cpp @@ -0,0 +1,74 @@ +#include <dirent.h> +#include <cstdio> +#include <fstream> +#include <iostream> + +#include "gpio-expander.hpp" +#include "storage.hpp" +#include "i2c.hpp" +#include "spi.hpp" + +#include "catch2/catch.hpp" + +namespace drivers { + +static const std::string kTestFilename = "test"; +static const std::string kTestFilePath = + std::string(kStoragePath) + "/" + kTestFilename; + +TEST_CASE("sd card storage", "[integration]") { + REQUIRE( drivers::init_i2c() == ESP_OK ); + REQUIRE( drivers::init_spi() == ESP_OK ); + GpioExpander expander; + + { + std::unique_ptr<SdStorage> result = SdStorage::create(&expander).value(); + + SECTION("write to a file") { + + { + std::ofstream test_file; + test_file.open(kTestFilePath.c_str()); + test_file << "hello here is some test"; + test_file.close(); + } + + SECTION("read from a file") { + std::ifstream test_file; + test_file.open(kTestFilePath.c_str()); + + std::string line; + REQUIRE(std::getline(test_file, line)); + REQUIRE(line == "hello here is some test"); + + test_file.close(); + } + + SECTION("list files") { + DIR* dir; + struct dirent* ent; + + dir = opendir(kStoragePath); + REQUIRE(dir != nullptr); + + bool found_test_file = false; + while (ent = readdir(dir)) { + if (ent->d_name == kTestFilename) { + found_test_file = true; + } + } + closedir(dir); + + REQUIRE(found_test_file); + + } + + REQUIRE(remove(kTestFilePath.c_str()) == 0); + } + } + + REQUIRE( drivers::deinit_i2c() == ESP_OK ); + REQUIRE( drivers::deinit_spi() == ESP_OK ); +} + +} // namespace drivers |
