fixed a lot of issues, now successfully runs the test with --enable-pedantic; refs #8

This commit is contained in:
Marc Wäckerlin
2014-03-28 11:50:39 +00:00
parent e846c326f1
commit 190b469d56
33 changed files with 398 additions and 409 deletions

View File

@@ -48,7 +48,7 @@ public:
int i(-1);
{
mrw::AutoFile a;
CPPUNIT_ASSERT(a==-1); // init as -1
CPPUNIT_ASSERT_EQUAL(-1, (mrw::AutoFile::Type)a); // init as -1
i = a = open((std::string(mrw::ifelse(getenv("srcdir"), "."))
+"/test.dat").c_str(), O_RDONLY);
CPPUNIT_ASSERT(i==a && a>0); // file is now open
@@ -61,24 +61,24 @@ public:
CPPUNIT_ASSERT(i==b && cc==-1); // it's ok now
b = open("test.dat", O_RDONLY);
//close(i);
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // old file is closed
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // old file is closed
i = b.reset();
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // new file is closed
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // new file is closed
i = a = open("test.dat", O_RDONLY);
}
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // file is closed now
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // file is closed now
}
void AutoFree() {
const char C[] = "Hello World";
mrw::Auto<char*>::Free c(malloc(sizeof(C)));
CPPUNIT_ASSERT(c);
strncpy(c, C, sizeof(C));
CPPUNIT_ASSERT(std::string(c)==C);
CPPUNIT_ASSERT_EQUAL(std::string(C), std::string(c));
mrw::Auto<char*>::Free c2(c.release());
CPPUNIT_ASSERT(c==0 && c2!=0);
CPPUNIT_ASSERT(std::string(c2)==C);
CPPUNIT_ASSERT_EQUAL(std::string(C), std::string(c2));
c2.reset();
CPPUNIT_ASSERT(c2==0);
CPPUNIT_ASSERT_EQUAL((char*)0, (char*)c2);
}
CPPUNIT_TEST_SUITE(AutoTest);
CPPUNIT_TEST(AutoFile);