Skip to content

Commit

Permalink
Time to start adding tests for things that fail
Browse files Browse the repository at this point in the history
  • Loading branch information
fgenesis committed Apr 6, 2014
1 parent 5628a7b commit 8190991
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option(TTVFS_SUPPORT_ZIP "Build support for zip archives?" FALSE)
option(TTVFS_LARGEFILE_SUPPORT "Enable support for files > 4 GB? (experimental!)" TRUE)
option(TTVFS_IGNORE_CASE "Enable full case-insensitivity even on case-sensitive OSes like Linux and alike?" TRUE)
option(TTVFS_BUILD_CFILEAPI "Build C-style API wrapper" TRUE)
option(TTVFS_BUILD_TESTS "Build tests" FALSE)

# Be sure to copy this part to your root CMakeLists.txt if you prefer to use CMake for configuring
# instead of editing the config header directly!
Expand Down Expand Up @@ -58,3 +59,8 @@ endif()
if(TTVFS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(TTVFS_BUILD_TESTS)
add_subdirectory(test)
endif()

7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

include_directories(${TTVFS_INCLUDE_DIRS})

add_executable(test1 test1.cpp)

target_link_libraries(test1 ttvfs)

1 change: 1 addition & 0 deletions test/a/data/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions test/b/data/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions test/c/data/misc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:misc
63 changes: 63 additions & 0 deletions test/test1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@


#include <ttvfs.h>
#include <cstdio>

template <typename T> static void assume(const T& what, const char *err)
{
if(!what)
{
puts("##### FAILED #####");
puts(err);
exit(2);
}
}

static void testmount_shared(ttvfs::Root& vfs)
{
ttvfs::File *vf = vfs.GetFile("data/file.txt");
assume(vf, "File not found");
assume(vf->open("r"), "Failed to open");
char buf[32];
assume(vf->read(&buf, sizeof(buf)) == 1, "Failed to read");
assume(buf[0] == 'B', "Mounted incorrectly - wrong file");
}


static bool testmount1()
{
puts("- testmount1...");
ttvfs::Root vfs;
vfs.AddLoader(new ttvfs::DiskLoader);
vfs.Mount("a/data", "data");
vfs.Mount("b/data", "data");
vfs.Mount("c/data", "data");
testmount_shared(vfs);
return true;
}

static bool testmount2()
{
puts("- testmount2...");
ttvfs::Root vfs;
vfs.AddLoader(new ttvfs::DiskLoader);
vfs.Mount("a", "");
vfs.Mount("b", "");
vfs.Mount("c", "");
testmount_shared(vfs);
return true;
}


int main(int argc, char *argv[])
{
if (testmount1()
&& testmount2()
){
puts("Tests passed!");
return 0;
}

puts("FAIL?!");
return 1;
}

0 comments on commit 8190991

Please sign in to comment.