From f3328fec5c49707fea1e551a6295a82c0c9549dc Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 12 Jul 2016 16:03:08 -0700 Subject: [PATCH] Add tests for native GetFileOwner --- src/libpsl-native/test/CMakeLists.txt | 1 + src/libpsl-native/test/test-getfileowner.cpp | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/libpsl-native/test/test-getfileowner.cpp diff --git a/src/libpsl-native/test/CMakeLists.txt b/src/libpsl-native/test/CMakeLists.txt index 4ddc53836..1ab2bfd3e 100644 --- a/src/libpsl-native/test/CMakeLists.txt +++ b/src/libpsl-native/test/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(googletest) add_executable(psl-native-test + test-getfileowner.cpp test-locale.cpp test-getcurrentprocessid.cpp test-getusername.cpp diff --git a/src/libpsl-native/test/test-getfileowner.cpp b/src/libpsl-native/test/test-getfileowner.cpp new file mode 100644 index 000000000..77f1e2fc8 --- /dev/null +++ b/src/libpsl-native/test/test-getfileowner.cpp @@ -0,0 +1,32 @@ +//! @file test-getfileowner.cpp +//! @author Andrew Schwartzmeyer +//! @brief Tests GetFileOwner + +#include +#include +#include +#include "getfileowner.h" + +using namespace std; + +//! Test fixture for GetFileOwner +class GetFileOwnerTest : public ::testing::Test +{ +}; + +TEST_F(GetFileOwnerTest, CanGetOwnerOfRoot) +{ + ASSERT_STREQ(GetFileOwner("/"), "root"); +} + +TEST_F(GetFileOwnerTest, CannotGetOwnerOfFakeFile) +{ + EXPECT_STREQ(GetFileOwner("SomeMadeUpFileNameThatDoesNotExist"), NULL); + EXPECT_EQ(errno, ERROR_FILE_NOT_FOUND); +} + +TEST_F(GetFileOwnerTest, ReturnsNullForNullInput) +{ + EXPECT_STREQ(GetFileOwner(NULL), NULL); + EXPECT_EQ(errno, ERROR_INVALID_PARAMETER); +}