Added unittests for FileFinder::find function.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
actorid
Lukasz Gromanowski 11 years ago
parent 515a865daa
commit 303e02cab5

@ -12,6 +12,7 @@ if (GTEST_FOUND AND GMOCK_FOUND)
file(GLOB UNITTEST_SRC_FILES
components/misc/test_*.cpp
components/file_finder/test_*.cpp
)
source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES})

@ -0,0 +1,74 @@
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <fstream>
#include "components/file_finder/search.hpp"
struct SearchTest : public ::testing::Test
{
protected:
SearchTest()
: mTestDir("./test_dir/")
{
}
virtual void SetUp()
{
boost::filesystem::create_directory(boost::filesystem::path(mTestDir));
std::ofstream ofs(std::string(mTestDir + "test2.txt").c_str(), std::ofstream::out);
ofs << std::endl;
ofs.close();
}
virtual void TearDown()
{
boost::filesystem::remove_all(boost::filesystem::path(mTestDir));
}
std::string mTestDir;
};
TEST_F(SearchTest, file_not_found)
{
struct Result : public FileFinder::ReturnPath
{
Result(const boost::filesystem::path& expectedPath)
: mExpectedPath(expectedPath)
{
}
void add(const boost::filesystem::path& p)
{
ASSERT_FALSE(p == mExpectedPath);
}
private:
boost::filesystem::path mExpectedPath;
} r(boost::filesystem::path(mTestDir + "test.txt"));
FileFinder::find(mTestDir, r, false);
}
TEST_F(SearchTest, file_found)
{
struct Result : public FileFinder::ReturnPath
{
Result(const boost::filesystem::path& expectedPath)
: mExpectedPath(expectedPath)
{
}
void add(const boost::filesystem::path& p)
{
ASSERT_TRUE(p == mExpectedPath);
}
private:
boost::filesystem::path mExpectedPath;
} r(boost::filesystem::path(mTestDir + "test2.txt"));
FileFinder::find(mTestDir, r, false);
}
Loading…
Cancel
Save