summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2016-12-25 16:19:12 +0100
committerFelix Morgner <felix.morgner@gmail.com>2016-12-25 16:19:12 +0100
commite1d780910569abd7019b7aa40d94fbfe6a42d398 (patch)
tree8eb492234d3638168153aea25689b9a89b63ee3c
parent6b6c50c740954e10d1d50f4b1ae69aac4b1c9599 (diff)
downloadextfs-e1d780910569abd7019b7aa40d94fbfe6a42d398.tar.xz
extfs-e1d780910569abd7019b7aa40d94fbfe6a42d398.zip
extfs: Add exisiting image construction tests
-rw-r--r--test/fs/CMakeLists.txt25
-rw-r--r--test/fs/extfs_test.cpp97
2 files changed, 117 insertions, 5 deletions
diff --git a/test/fs/CMakeLists.txt b/test/fs/CMakeLists.txt
index b1ccc1b..bfd593e 100644
--- a/test/fs/CMakeLists.txt
+++ b/test/fs/CMakeLists.txt
@@ -1,3 +1,26 @@
set(CUTE_GROUP "fs")
-cute_test(extfs LIBRARIES extfs)
+file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test/extfs_data")
+message(STATUS "Creating test disk images")
+execute_process(
+ COMMAND dd if=/dev/zero of=${CMAKE_BINARY_DIR}/test/extfs_data/labeled.img bs=1M count=1
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+execute_process(
+ COMMAND mkfs.ext2 -L labeleddisk ${CMAKE_BINARY_DIR}/test/extfs_data/labeled.img
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+execute_process(
+ COMMAND dd if=/dev/zero of=${CMAKE_BINARY_DIR}/test/extfs_data/unlabeled.img bs=1M count=1
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+execute_process(
+ COMMAND mkfs.ext2 ${CMAKE_BINARY_DIR}/test/extfs_data/unlabeled.img
+ OUTPUT_QUIET
+ ERROR_QUIET
+ )
+
+cute_test(extfs LIBRARIES extfs stdc++fs)
diff --git a/test/fs/extfs_test.cpp b/test/fs/extfs_test.cpp
index 46149e9..4533e60 100644
--- a/test/fs/extfs_test.cpp
+++ b/test/fs/extfs_test.cpp
@@ -5,21 +5,105 @@
#include <cute/ostream_listener.h>
#include <cute/xml_listener.h>
+#if __has_include(<experimental/filesystem>)
+#include <experimental/filesystem>
+namespace stdfs = std::experimental::filesystem;
+#elif __has_include(<filesystem>)
+#include <filesystem>
+namespace stdfs = std::filesystem;
+#else
+#error The standard library has no support for the Filesystem TS
+#endif
+
+#include <initializer_list>
+#include <stdexcept>
+#include <string>
+
+auto constexpr kNonExistantImage = "THIS_DISK_DOES_NOT_EXIST";
+auto constexpr kLabeledDiskImage = "../test/extfs_data/labeled.img";
+auto constexpr kUnlabeledDiskImage = "../test/extfs_data/unlabeled.img";
+
+bool disk_exists(stdfs::path const & imagePath)
+ {
+ return stdfs::exists(imagePath) && stdfs::is_regular_file(imagePath);
+ }
+
+auto guard_disk_image_any(std::initializer_list<char const *> imageList,
+ fs::extfs::mode const mode = fs::extfs::mode::read_only)
+ {
+ ASSERT_GREATER_EQUALM("imageList must not be emtpy!", imageList.size(), 0);
+
+ for(auto && path : imageList)
+ {
+ if(disk_exists(path))
+ {
+ return fs::extfs(path, mode);
+ }
+ }
+
+ throw std::runtime_error{"None of the expected disk images could be found!"};
+ }
+
+auto guard_disk_image_none(std::initializer_list<char const *> imageList)
+ {
+ ASSERT_GREATER_EQUALM("imageList must not be emtpy!", imageList.size(), 0);
+
+ for(auto && path : imageList)
+ {
+ if(disk_exists(path))
+ {
+ throw std::runtime_error{"Found unexpected disk image!"};
+ }
+ }
+
+ return fs::extfs{*imageList.begin()};
+ }
+
void construction_with_inexistent_file_creates_extfs_that_is_not_open()
{
- auto && disk = fs::extfs{"./THIS_DISK_DOES_NOT_EXIST"};
+ auto && disk = guard_disk_image_none({kNonExistantImage});
ASSERT(!disk.open());
}
void non_open_file_system_has_no_label()
{
- auto && disk = fs::extfs{"./THIS_DISK_DOES_NOT_EXIST"};
+ auto && disk = guard_disk_image_none({kNonExistantImage});
ASSERT(!disk.has_label());
}
void non_open_file_system_has_empty_label()
{
- auto && disk = fs::extfs{"./THIS_DISK_DOES_NOT_EXIST"};
+ auto && disk = guard_disk_image_none({kNonExistantImage});
+ ASSERT_EQUAL("", disk.label());
+ }
+
+void construction_with_existing_file_creates_extfs_that_is_open()
+ {
+ auto && disk = guard_disk_image_any({kLabeledDiskImage, kUnlabeledDiskImage});
+ ASSERT(disk.open());
+ }
+
+void construction_with_labeled_image_creates_extfs_that_has_label()
+ {
+ auto && disk = guard_disk_image_any({kLabeledDiskImage});
+ ASSERT(disk.has_label());
+ }
+
+void construction_with_unlabeled_image_creates_extfs_that_has_no_label()
+ {
+ auto && disk = guard_disk_image_any({kUnlabeledDiskImage});
+ ASSERT(!disk.has_label());
+ }
+
+void construction_with_labeled_image_creates_extfs_that_has_label_labeleddisk()
+ {
+ auto && disk = guard_disk_image_any({kLabeledDiskImage});
+ ASSERT_EQUAL("labeleddisk", disk.label());
+ }
+
+void construction_with_unlabeled_image_creates_extfs_that_has_empty_string_for_label()
+ {
+ auto && disk = guard_disk_image_any({kUnlabeledDiskImage});
ASSERT_EQUAL("", disk.label());
}
@@ -28,7 +112,12 @@ int main(int argc, char * argv[])
auto tests = cute::suite{
CUTE(construction_with_inexistent_file_creates_extfs_that_is_not_open),
CUTE(non_open_file_system_has_no_label),
- CUTE(non_open_file_system_has_empty_label)
+ CUTE(non_open_file_system_has_empty_label),
+ CUTE(construction_with_existing_file_creates_extfs_that_is_open),
+ CUTE(construction_with_labeled_image_creates_extfs_that_has_label),
+ CUTE(construction_with_unlabeled_image_creates_extfs_that_has_no_label),
+ CUTE(construction_with_labeled_image_creates_extfs_that_has_label_labeleddisk),
+ CUTE(construction_with_unlabeled_image_creates_extfs_that_has_empty_string_for_label),
};
cute::xml_file_opener resultFile{argc, argv};