hrev54272 adds 1 changeset to branch 'master'
old head: ca3e2eaaeab55c7ba3b531811878279da6ecf3aa
new head: 57672294e9b1c02ecea302b60664decdf9f4226b
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=57672294e9b1+%5Eca3e2eaaeab5
----------------------------------------------------------------------------
57672294e9b1: tests/storage: Fix BDirectory tests
After this patch "UnitTester BDirectory" passes.
Most of this test suite already documented the differences in behavior
between BeOS R5 and Haiku. I verified whether these comments were
accurate and removed the cases which handle BeOS specific behavior.
Most of the differences are just Haiku using more specific errors:
* Initializing BDirectory with an entry that is not a directory
results in B_NOT_A_DIRECTORY.
* There is obviously no /boot/beos. Use /boot/system for this test
instead. BDirectory::IsRootDirectory returns true for this path
since it is the root of the system package.
* Initializing to child path "" results in B_ENTRY_NOT_FOUND instead
of successful initialization with B_OK only to later return
B_BAD_VALUE if the BDirectory is used.
* BDirectory::Find(NULL, BEntry*) doesn't touch the BEntry parameter
since the provided path is NULL, where BeOS R5 will set the BEntry's
status to B_BAD_VALUE.
* Clean up -Wparentheses warnings for assertions of the form
CPPUNIT_ASSERT(path == existingSub == B_OK), which is another way of
saying path != existingSub. This is because the path ends up being a
normalied path, but the input path is not. For example
/tmp/existing-dir becomes /boot/system/cache/tmp/existing-dir. I
verified that this is the same behavior as BeOS, and then added some
normalized paths to compare against.
Change-Id: I5125ef221fba92793959efead96d7daaa181a119
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2826
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
[ Kyle Ambroff-Kao <kyle@xxxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev54272
Commit: 57672294e9b1c02ecea302b60664decdf9f4226b
URL: https://git.haiku-os.org/haiku/commit/?id=57672294e9b1
Author: Kyle Ambroff-Kao <kyle@xxxxxxxxxxxxxx>
Date: Sat May 9 06:30:41 2020 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Fri May 29 14:34:47 2020 UTC
----------------------------------------------------------------------------
1 file changed, 74 insertions(+), 64 deletions(-)
src/tests/kits/storage/DirectoryTest.cpp | 138 ++++++++++++++-------------
----------------------------------------------------------------------------
diff --git a/src/tests/kits/storage/DirectoryTest.cpp
b/src/tests/kits/storage/DirectoryTest.cpp
index 3ba05922e5..ee1b17fb5a 100644
--- a/src/tests/kits/storage/DirectoryTest.cpp
+++ b/src/tests/kits/storage/DirectoryTest.cpp
@@ -138,14 +138,14 @@ DirectoryTest::InitTest1()
NextSubTest();
{
BDirectory dir("");
- // R5 returns B_ENTRY_NOT_FOUND instead of B_BAD_VALUE.
+ // BeOS R5 returns B_ENTRY_NOT_FOUND instead of B_BAD_VALUE.
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir(existingFile);
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
@@ -155,7 +155,7 @@ DirectoryTest::InitTest1()
NextSubTest();
{
BDirectory dir(fileDirname);
- // R5 returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
+ // BeOS R5 returns B_ENTRY_NOT_FOUND instead of
B_NOT_A_DIRECTORY.
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
@@ -190,13 +190,13 @@ DirectoryTest::InitTest1()
BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BDirectory dir(&entry);
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BEntry entry(tooLongEntryname);
- // R5 returns E2BIG instead of B_NAME_TOO_LONG
+ // BeOS R5 returns E2BIG instead of B_NAME_TOO_LONG
CPPUNIT_ASSERT( equals(entry.InitCheck(), E2BIG,
B_NAME_TOO_LONG) );
BDirectory dir(&entry);
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS,
B_BAD_VALUE) );
@@ -233,8 +233,8 @@ DirectoryTest::InitTest1()
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
BDirectory dir(&ref);
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
// 5. BDirectory(const node_ref*)
@@ -247,14 +247,11 @@ DirectoryTest::InitTest1()
BDirectory dir(&nref);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
-// R5: crashs, when passing a NULL node_ref.
-#if !TEST_R5
NextSubTest();
{
BDirectory dir((node_ref *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
-#endif
NextSubTest();
{
BNode node(existingFile);
@@ -262,9 +259,8 @@ DirectoryTest::InitTest1()
node_ref nref;
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
BDirectory dir(&nref);
- // R5: returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- // OBOS: returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_VALUE,
B_ENTRY_NOT_FOUND) );
+ // BeOS R5: returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
// 6. BDirectory(const BDirectory*, const char*)
@@ -311,16 +307,15 @@ DirectoryTest::InitTest1()
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, "");
- // This does not fail in R5, but inits the object to pathDir.
- CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
}
NextSubTest();
{
BDirectory pathDir(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, existingRelFile);
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
@@ -334,7 +329,7 @@ DirectoryTest::InitTest1()
BDirectory pathDir(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, fileRelDirname);
- // R5 returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
+ // BeOS R5 returns B_ENTRY_NOT_FOUND instead of
B_NOT_A_DIRECTORY.
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
}
@@ -370,15 +365,14 @@ DirectoryTest::InitTest2()
dir.Unset();
//
NextSubTest();
- // R5 returns B_ENTRY_NOT_FOUND instead of B_BAD_VALUE.
CPPUNIT_ASSERT( dir.SetTo("") == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
//
NextSubTest();
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.SetTo(existingFile) == B_BAD_VALUE );
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(existingFile), B_NOT_A_DIRECTORY);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
//
NextSubTest();
@@ -387,9 +381,8 @@ DirectoryTest::InitTest2()
dir.Unset();
//
NextSubTest();
- // R5 returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.SetTo(fileDirname) == B_ENTRY_NOT_FOUND );
- CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(fileDirname), B_ENTRY_NOT_FOUND);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
dir.Unset();
// 3. BDirectory(const BEntry*)
@@ -421,14 +414,14 @@ DirectoryTest::InitTest2()
NextSubTest();
entry.SetTo(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.SetTo(&entry) == B_BAD_VALUE );
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(&entry), B_NOT_A_DIRECTORY);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
//
NextSubTest();
entry.SetTo(tooLongEntryname);
- // R5 returns E2BIG instead of B_NAME_TOO_LONG
+ // BeOS R5 returns E2BIG instead of B_NAME_TOO_LONG
CPPUNIT_ASSERT( equals(entry.InitCheck(), E2BIG, B_NAME_TOO_LONG) );
CPPUNIT_ASSERT( equals(dir.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
@@ -461,9 +454,9 @@ DirectoryTest::InitTest2()
entry.SetTo(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.SetTo(&ref) == B_BAD_VALUE );
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(&ref), B_NOT_A_DIRECTORY);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
// 5. BDirectory(const node_ref*)
@@ -476,21 +469,17 @@ DirectoryTest::InitTest2()
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
//
-// R5: crashs, when passing a NULL node_ref.
-#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((node_ref *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
-#endif
//
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- // OBOS: returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( equals(dir.SetTo(&nref), B_BAD_VALUE,
B_ENTRY_NOT_FOUND) );
- CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_VALUE, B_ENTRY_NOT_FOUND)
);
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(&nref), B_NOT_A_DIRECTORY);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
// 6. BDirectory(const BDirectory*, const char*)
@@ -535,17 +524,18 @@ DirectoryTest::InitTest2()
NextSubTest();
pathDir.SetTo(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
- // This does not fail in R5, but inits the object to pathDir.
- CPPUNIT_ASSERT( dir.SetTo(&pathDir, "") == B_OK );
- CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
+ // BeOS R5 initializes dir to pathDir instead of B_ENTRY_NOT_FOUND
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(&pathDir, ""), B_ENTRY_NOT_FOUND);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
dir.Unset();
//
NextSubTest();
pathDir.SetTo(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
- // R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
- CPPUNIT_ASSERT( dir.SetTo(&pathDir, existingRelFile) == B_BAD_VALUE );
- CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
+ // BeOS R5 returns B_BAD_VALUE instead of B_NOT_A_DIRECTORY.
+ CPPUNIT_ASSERT_EQUAL(dir.SetTo(&pathDir, existingRelFile),
+ B_NOT_A_DIRECTORY);
+ CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
//
NextSubTest();
@@ -559,7 +549,6 @@ DirectoryTest::InitTest2()
NextSubTest();
pathDir.SetTo(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
- // R5 returns B_ENTRY_NOT_FOUND instead of B_NOT_A_DIRECTORY.
CPPUNIT_ASSERT( dir.SetTo(&pathDir, fileRelDirname) ==
B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
@@ -622,9 +611,9 @@ DirectoryTest::IsRootTest()
CPPUNIT_ASSERT( dir.IsRootDirectory() == true );
//
NextSubTest();
- CPPUNIT_ASSERT( dir.SetTo("/boot/beos") == B_OK );
+ CPPUNIT_ASSERT(dir.SetTo("/boot/system") == B_OK);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
- CPPUNIT_ASSERT( dir.IsRootDirectory() == false );
+ CPPUNIT_ASSERT_EQUAL(dir.IsRootDirectory(), true);
//
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/tmp") == B_OK );
@@ -651,6 +640,26 @@ DirectoryTest::FindEntryTest()
const char *dirLink = dirLinkname;
const char *badLink = badLinkname;
const char *cyclicLink1 = cyclicLinkname1;
+
+ // These are for verification after finding an entry from a BDirectory.
+ // On BeOS and Haiku, calling BEntry::GetPath() returns the normalized
+ // path, but the paths we are using to initialize the BDirectory are not
+ // normalized. So we use these for comparison.
+ BPath normalizedExistingPath(existing, NULL, true);
+ CPPUNIT_ASSERT_EQUAL(normalizedExistingPath.InitCheck(), B_OK);
+
+ BPath normalizedExistingSubPath(existingSub, NULL, true);
+ CPPUNIT_ASSERT_EQUAL(normalizedExistingSubPath.InitCheck(), B_OK);
+
+ BPath normalizedDirLinkPath(dirLink, NULL, true);
+ CPPUNIT_ASSERT_EQUAL(normalizedDirLinkPath.InitCheck(), B_OK);
+
+ BPath normalizedBadLinkPath(badLink, NULL, true);
+ CPPUNIT_ASSERT_EQUAL(normalizedBadLinkPath.InitCheck(), B_OK);
+
+ BPath normalizedCyclicLink1(cyclicLink1, NULL, true);
+ CPPUNIT_ASSERT_EQUAL(normalizedCyclicLink1.InitCheck(), B_OK);
+
// existing absolute path, uninitialized BDirectory
NextSubTest();
BDirectory dir;
@@ -660,7 +669,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(existing, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == existing == B_OK );
+ CPPUNIT_ASSERT(path != existing);
+ CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -671,7 +681,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(existing, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == existing == B_OK );
+ CPPUNIT_ASSERT(path != existing);
+ CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -682,7 +693,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(existingRelSub, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == existingSub == B_OK );
+ CPPUNIT_ASSERT(path != existingSub);
+ CPPUNIT_ASSERT(path == normalizedExistingSubPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -716,17 +728,11 @@ DirectoryTest::FindEntryTest()
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
-// R5: crashs, when passing a NULL BEntry.
-#if !TEST_R5
CPPUNIT_ASSERT( dir.FindEntry(existingRelSub, NULL) == B_BAD_VALUE );
-#endif
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( dir.FindEntry(NULL, &entry) == B_BAD_VALUE );
- CPPUNIT_ASSERT( equals(entry.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
-// R5: crashs, when passing a NULL BEntry.
-#if !TEST_R5
+ CPPUNIT_ASSERT(entry.InitCheck() == B_OK);
CPPUNIT_ASSERT( dir.FindEntry(NULL, NULL) == B_BAD_VALUE );
-#endif
dir.Unset();
entry.Unset();
path.Unset();
@@ -736,7 +742,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(dirLink, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == dirLink == B_OK );
+ CPPUNIT_ASSERT(path != dirLink);
+ CPPUNIT_ASSERT(path == normalizedDirLinkPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -746,7 +753,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(dirLink, &entry, true) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == existing == B_OK );
+ CPPUNIT_ASSERT(path != existing);
+ CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -756,7 +764,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(badLink, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == badLink == B_OK );
+ CPPUNIT_ASSERT(path != badLink);
+ CPPUNIT_ASSERT(path == normalizedBadLinkPath);
dir.Unset();
entry.Unset();
path.Unset();
@@ -774,7 +783,8 @@ DirectoryTest::FindEntryTest()
CPPUNIT_ASSERT( dir.FindEntry(cyclicLink1, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
- CPPUNIT_ASSERT( path == cyclicLink1 == B_OK );
+ CPPUNIT_ASSERT(path != cyclicLink1);
+ CPPUNIT_ASSERT(path == normalizedCyclicLink1);
dir.Unset();
entry.Unset();
path.Unset();