Mercurial > code
view modules/fs/test/main.cpp @ 572:ad302d1b7335
Net: Socket is no more a template, use raw addresses instead
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 30 Jun 2016 12:35:42 +0200 |
parents | f48bb09bccc7 |
children |
line wrap: on
line source
/* * main.cpp -- test directory * * Copyright (c) 2013-2015 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 <sstream> #include <gtest/gtest.h> #include <fs.hpp> TEST(Symbols, entry) { return; FAIL() << "must not go here"; fs::Entry e1, e2; (void)(e1 == e2); (void)(e1 != e2); } TEST(Symbols, all) { return; FAIL() << "must not go here"; (void)fs::separator(); (void)fs::clean(""); (void)fs::baseName(""); (void)fs::dirName(""); (void)fs::stat(""); (void)fs::exists(""); (void)fs::isAbsolute(""); (void)fs::isRelative(""); (void)fs::isReadable(""); (void)fs::isWritable(""); (void)fs::isFile(""); (void)fs::isDirectory(""); (void)fs::isSymlink(""); (void)fs::readdir(""); (void)fs::mkdir(""); (void)fs::rmdir(""); (void)fs::cwd(); } TEST(Filter, withDot) { try { bool dot(false); bool dotdot(false); for (const auto &entry : fs::readdir(".", fs::Dot)) { if (entry.name == ".") dot = true; if (entry.name == "..") dotdot = true; } ASSERT_TRUE(dot); ASSERT_FALSE(dotdot); } catch (const std::exception &error) { FAIL() << error.what(); } } TEST(Filter, withDotDot) { try { bool dot(false); bool dotdot(false); for (const auto &entry : fs::readdir(".", fs::DotDot)) { if (entry.name == ".") dot = true; if (entry.name == "..") dotdot = true; } ASSERT_FALSE(dot); ASSERT_TRUE(dotdot); } catch (const std::exception &error) { FAIL() << error.what(); } } TEST(Filter, withBothDots) { try { bool dot(false); bool dotdot(false); for (const auto &entry : fs::readdir(".", fs::Dot | fs::DotDot)) { if (entry.name == ".") dot = true; if (entry.name == "..") dotdot = true; } ASSERT_TRUE(dot); ASSERT_TRUE(dotdot); } catch (const std::exception &error) { FAIL() << error.what(); } } TEST(Filter, withoutDots) { try { bool dot(false); bool dotdot(false); for (const auto &entry : fs::readdir(".")) { if (entry.name == ".") dot = true; if (entry.name == "..") dotdot = true; } ASSERT_FALSE(dot); ASSERT_FALSE(dotdot); } catch (const std::exception &error) { FAIL() << error.what(); } } TEST(Exists, yes) { ASSERT_TRUE(fs::exists(DIRECTORY "file-1.txt")); } TEST(Exists, no) { ASSERT_FALSE(fs::exists(DIRECTORY "does not exists")); } TEST(IsFile, yes) { ASSERT_TRUE(fs::isFile(__FILE__)); } TEST(IsFile, no) { ASSERT_FALSE(fs::isFile(DIRECTORY)); } TEST(IsDirectory, yes) { ASSERT_TRUE(fs::isDirectory(DIRECTORY)); } TEST(IsDirectory, no) { ASSERT_FALSE(fs::isDirectory(__FILE__)); } TEST(RemoveDirectory, basic) { try { std::string path = DIRECTORY "mkdir-test"; fs::mkdir(path); ASSERT_TRUE(fs::isDirectory(path)); fs::rmdir(path); ASSERT_FALSE(fs::exists(path)); } catch (const std::exception &ex) { FAIL() << ex.what(); } } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }