Skip to content

Commit

Permalink
Switch findlib unit tests to googletest
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Jan 2, 2018
1 parent 7e3bae7 commit 8df868a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions cmake/BareosFindAllLibraries.cmake
Expand Up @@ -68,6 +68,8 @@ BareosFindLibrary("util")
BareosFindLibrary("dl")
BareosFindLibrary("acl")
BareosFindLibrary("wrap")
BareosFindLibrary("gtest")
BareosFindLibrary("gtest_main")

if (${HAVE_CAP})
SET(HAVE_LIBCAP 1)
Expand Down
9 changes: 6 additions & 3 deletions src/findlib/unittests/CMakeLists.txt
Expand Up @@ -20,9 +20,8 @@
include_directories(.. ../.. ../../include/)

set (TEST_SRC
drivetype_test.cc
// drivetype_test.cc
fstype_test.cc
test_findlib.cc
)

add_executable(test_findlib
Expand All @@ -32,12 +31,16 @@ target_link_libraries(test_findlib
bareosfind bareos
${JANSSON_LIBRARIES}
${CMOCKA_LIBRARIES}
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

add_test(NAME test_findlib
COMMAND "test_findlib"
)
set_property(TEST test_findlib
PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/lib:${CMAKE_BINARY_DIR}/src/findlib")
PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/lib:${CMAKE_BINARY_DIR}/src/findlib"
PROPERTY ENVIRONMENT "GTEST_COLOR=yes"
)

add_dependencies(check test_findlib)
46 changes: 25 additions & 21 deletions src/findlib/unittests/fstype_test.cc
Expand Up @@ -26,30 +26,34 @@
*
* Philipp Storz, April 2015
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>

extern "C" {
#include <cmocka.h>
}

#include "gtest/gtest.h"
#include <stdio.h>
#include "bareos.h"
#include "findlib/find.h"

void test_fstype(void **state) {
#ifdef HAVE_WIN32
char *fs_to_check[] = {"/", "c:/", NULL};
#else
char *fs_to_check[] = {"/proc", NULL};
#endif
char fs[1000];

char **p = fs_to_check;
while ( *p ) {
assert_true( fstype(*p, fs, sizeof(fs)) );
printf("%s\t%s\n", fs, *p);
p++;
}
TEST(FstypeTest, RootFs) {
char fs[1000];
bool retval;
retval = fstype("/", fs, sizeof(fs));
EXPECT_TRUE(retval);
EXPECT_STREQ("xfs", (const char *) fs) << "checking root fs to be xfs";
}

TEST(FstypeTest, Proc) {
char fs[1000];
bool retval;

retval = fstype("/proc", fs, sizeof(fs));
EXPECT_TRUE(retval);
EXPECT_STREQ("proc", (const char *) fs) << "checking proc to be proc";
}

TEST(FstypeTest, Run) {
char fs[1000];
bool retval;

retval = fstype("/run", fs, sizeof(fs));
EXPECT_TRUE(retval);
EXPECT_STREQ("tmpfs", (const char *) fs) << "checking run to be tmpfs";
}

0 comments on commit 8df868a

Please sign in to comment.