]> git.saurik.com Git - apt.git/blobdiff - test/libapt/fileutl_test.cc
accept ../ on the cmdline as start for a deb file as well
[apt.git] / test / libapt / fileutl_test.cc
index a2c303768e4c6af042e3ea241610f0c52c844c73..2bd090e5e627858a64f938b1f14a0e14c0e4c309 100644 (file)
@@ -290,11 +290,41 @@ TEST(FileUtlTest, Popen)
 TEST(FileUtlTest, flAbsPath)
 {
    std::string cwd = SafeGetCWD();
-   int res = chdir("/bin/");
+   int res = chdir("/etc/");
    EXPECT_EQ(res, 0);
-   std::string p = flAbsPath("ls");
-   EXPECT_EQ(p, "/bin/ls");
+   std::string p = flAbsPath("passwd");
+   EXPECT_EQ(p, "/etc/passwd");
 
    res = chdir(cwd.c_str());
    EXPECT_EQ(res, 0);
 }
+
+static void TestDevNullFileFd(unsigned int const filemode)
+{
+   FileFd f("/dev/null", filemode);
+   EXPECT_FALSE(f.Failed());
+   EXPECT_TRUE(f.IsOpen());
+   EXPECT_TRUE(f.IsOpen());
+
+   std::string test = "This is a test!\n";
+   EXPECT_TRUE(f.Write(test.c_str(), test.size()));
+   EXPECT_TRUE(f.IsOpen());
+   EXPECT_FALSE(f.Failed());
+
+   f.Close();
+   EXPECT_FALSE(f.IsOpen());
+   EXPECT_FALSE(f.Failed());
+}
+TEST(FileUtlTest, WorkingWithDevNull)
+{
+   TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create);
+   TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Empty);
+   TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive);
+   TestDevNullFileFd(FileFd::WriteOnly | FileFd::Atomic);
+   TestDevNullFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Atomic);
+   // short-hands for ReadWrite with these modes
+   TestDevNullFileFd(FileFd::WriteEmpty);
+   TestDevNullFileFd(FileFd::WriteAny);
+   TestDevNullFileFd(FileFd::WriteTemp);
+   TestDevNullFileFd(FileFd::WriteAtomic);
+}