summaryrefslogtreecommitdiff
path: root/test/libapt/fileutl_test.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2015-06-23 12:17:35 +0100
committerMichael Vogt <mvo@debian.org>2015-06-23 12:17:35 +0100
commit245dde96193702f7f51389d3583dee547f8ba366 (patch)
tree6cf8c191641c760bcc6a6c08fb0ff65d27e0cffd /test/libapt/fileutl_test.cc
parent5530255b5f3ad7de2e23dfcb39ce325001126501 (diff)
parentc8a4ce6cbed57ae108dc955d4a850f9b129a0693 (diff)
Merge remote-tracking branch 'donkult/debian/experimental' into debian/experimental
Diffstat (limited to 'test/libapt/fileutl_test.cc')
-rw-r--r--test/libapt/fileutl_test.cc38
1 files changed, 23 insertions, 15 deletions
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 8d47c5098..a2c303768 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -53,11 +53,16 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission
// ensure the memory is as predictably messed up
#define APT_INIT_READBACK \
char readback[20]; \
- memset(readback, 'D', sizeof(readback)/sizeof(readback[0])); \
+ memset(readback, 'D', sizeof(readback)*sizeof(readback[0])); \
readback[19] = '\0';
#define EXPECT_N_STR(expect, actual) \
EXPECT_EQ(0, strncmp(expect, actual, strlen(expect)));
-
+ {
+ APT_INIT_READBACK
+ char const * const expect = "DDDDDDDDDDDDDDDDDDD";
+ EXPECT_STREQ(expect,readback);
+ EXPECT_N_STR(expect, readback);
+ }
{
APT_INIT_READBACK
char const * const expect = "This";
@@ -247,37 +252,40 @@ TEST(FileUtlTest, Popen)
// output something
const char* Args[10] = {"/bin/echo", "meepmeep", NULL};
- bool res = Popen(Args, Fd, Child, FileFd::ReadOnly);
- Fd.Read(buf, sizeof(buf)-1, &n);
+ EXPECT_TRUE(Popen(Args, Fd, Child, FileFd::ReadOnly));
+ EXPECT_TRUE(Fd.Read(buf, sizeof(buf)-1, &n));
buf[n] = 0;
EXPECT_NE(n, 0);
- EXPECT_EQ(res, true);
EXPECT_STREQ(buf, "meepmeep\n");
// wait for the child to exit and cleanup
- ExecWait(Child, "PopenRead");
- Fd.Close();
+ EXPECT_TRUE(ExecWait(Child, "PopenRead"));
+ EXPECT_TRUE(Fd.Close());
// ensure that after a close all is good again
if(FileExists("/proc/self/fd"))
EXPECT_EQ(Glob("/proc/self/fd/*").size(), OpenFds.size());
-
// ReadWrite is not supported
- res = Popen(Args, Fd, Child, FileFd::ReadWrite);
- EXPECT_EQ(res, false);
- _error->Discard();
+ _error->PushToStack();
+ EXPECT_FALSE(Popen(Args, Fd, Child, FileFd::ReadWrite));
+ EXPECT_FALSE(Fd.IsOpen());
+ EXPECT_FALSE(Fd.Failed());
+ EXPECT_TRUE(_error->PendingError());
+ _error->RevertToStack();
// write something
Args[0] = "/bin/bash";
Args[1] = "-c";
Args[2] = "read";
Args[3] = NULL;
- res = Popen(Args, Fd, Child, FileFd::WriteOnly);
+ EXPECT_TRUE(Popen(Args, Fd, Child, FileFd::WriteOnly));
s = "\n";
- Fd.Write(s.c_str(), s.size());
- Fd.Close();
- ExecWait(Child, "PopenWrite");
+ EXPECT_TRUE(Fd.Write(s.c_str(), s.length()));
+ EXPECT_TRUE(Fd.Close());
+ EXPECT_FALSE(Fd.IsOpen());
+ EXPECT_FALSE(Fd.Failed());
+ EXPECT_TRUE(ExecWait(Child, "PopenWrite"));
}
TEST(FileUtlTest, flAbsPath)
{