view C++/tests/Directory/main.cpp @ 334:0b576ee64d45

* Create brand new hierarchy * Rename DynLib to Dynlib * Remove some warnings
author David Demelier <markand@malikania.fr>
date Sun, 08 Mar 2015 14:26:33 +0100
parents C++/Tests/Directory/main.cpp@b686a09fb9c6
children 83ef77841ff1
line wrap: on
line source

/*
 * main.cpp -- test directory
 *
 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <gtest/gtest.h>

#include <Directory.h>

TEST(Filter, withDot)
{
	try {
		auto flags = Directory::NotDotDot;
		Directory directory(".", flags);
		bool dot(false);
		bool dotdot(false);

		for (const auto &entry : directory) {
			if (entry.name == ".")
				dot = true;
			if (entry.name == "..")
				dotdot = true;
		}

		ASSERT_TRUE(dot);
		ASSERT_FALSE(dotdot);
	} catch (const std::runtime_error &error) {
		FAIL() << "skipping test because: " << error.what();
	}
}

TEST(Filter, withDotDot)
{
	try {
		auto flags = Directory::NotDot;
		Directory directory(".", flags);
		bool dot(false);
		bool dotdot(false);

		for (const auto &entry : directory) {
			if (entry.name == ".")
				dot = true;
			if (entry.name == "..")
				dotdot = true;
		}

		ASSERT_FALSE(dot);
		ASSERT_TRUE(dotdot);
	} catch (const std::runtime_error &error) {
		FAIL() << "skipping test because: " << error.what();
	}
}

TEST(Filter, withBothDots)
{
	try {
		Directory directory(".");
		bool dot(false);
		bool dotdot(false);

		for (const auto &entry : directory) {
			if (entry.name == ".")
				dot = true;
			if (entry.name == "..")
				dotdot = true;
		}

		ASSERT_TRUE(dot);
		ASSERT_TRUE(dotdot);
	} catch (const std::runtime_error &error) {
		FAIL() << "skipping test because: " << error.what();
	}
}

TEST(Filter, withoutDots)
{
	try {
		auto flags = Directory::NotDot | Directory::NotDotDot;
		Directory directory(".", flags);
		bool dot(false);
		bool dotdot(false);

		for (const auto &entry : directory) {
			if (entry.name == ".")
				dot = true;
			if (entry.name == "..")
				dotdot = true;
		}

		ASSERT_FALSE(dot);
		ASSERT_FALSE(dotdot);
	} catch (const std::runtime_error &error) {
		FAIL() << "skipping test because: " << error.what();
	}
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}