[haiku-commits] Change in haiku[master]: tests/kits/storage: Fix SymLinkTest

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 20 Apr 2020 06:55:58 +0000

From Kyle Ambroff-Kao <kyle@xxxxxxxxxxxxxx>:

Kyle Ambroff-Kao has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2502 ;)


Change subject: tests/kits/storage: Fix SymLinkTest
......................................................................

tests/kits/storage: Fix SymLinkTest

This patch makes "UnitTester SymLink" pass.

This patch is similar to ee8cf35f0 which fixed tests for BNode. The
tests were failing because Haiku's error checking is just better.

BeOS allowed constructing a BSymLink with BSymLink(BDirectory*, const
char*) with the entry name of "". The same is true of the equivilant
SetTo() method. The BSymLink object will appear valid until you
attempt to use it by, for example, calling the ReadLink method, which
will return B_BAD_VALUE.

Haiku does a more appropriate thing and returns B_ENTRY_NOT_FOUND, for
this constructor and the equivilant SetTo(BDirectory*, const char*)
method.

There were also some missing error checks in BeOS's
BSymLink::ReadLink. If you provide a buffer that is too small to hold
the path the link points to, it will just copy the path into the
buffer until it runs out of room. So the path will be partially copied
into the output buffer and no error is returned and errno is not
changed, so no error is reported.

In Haiku if BSymLink::ReadLink() is provided a buffer that is too
small, then B_BUFFER_OVERFLOW is returned instead of the number of
bytes copied.

This patch fixes these tests to match Haiku behavior and updates the
docs for BSymLink::ReadLink.
---
M docs/user/storage/SymLink.dox
M src/tests/kits/storage/SymLinkTest.cpp
2 files changed, 8 insertions(+), 5 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/02/2502/1

diff --git a/docs/user/storage/SymLink.dox b/docs/user/storage/SymLink.dox
index 936bbab..7c68a55 100644
--- a/docs/user/storage/SymLink.dox
+++ b/docs/user/storage/SymLink.dox
@@ -120,6 +120,8 @@
        \retval B_BAD_VALUE \a buf was \c NULL or the object didn't refer to a
                symbolic link.
        \retval B_FILE_ERROR The object was not initialized.
+       \retval B_BUFFER_OVERFLOW if the symlink's contents is longer than
+               \a size so it does not fit in \a buffer.
 
        \since BeOS R3
 */
diff --git a/src/tests/kits/storage/SymLinkTest.cpp 
b/src/tests/kits/storage/SymLinkTest.cpp
index 782944c..f7e74b9 100644
--- a/src/tests/kits/storage/SymLinkTest.cpp
+++ b/src/tests/kits/storage/SymLinkTest.cpp
@@ -285,7 +285,7 @@
                BDirectory pathDir(dirSuperLink);
                CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
                BSymLink link(&pathDir, "");
-               CPPUNIT_ASSERT( link.InitCheck() == B_OK );
+               CPPUNIT_ASSERT(link.InitCheck() == B_ENTRY_NOT_FOUND);
        }
        NextSubTest();
        {
@@ -467,8 +467,8 @@
        //
        NextSubTest();
        CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
-       CPPUNIT_ASSERT( link.SetTo(&pathDir, "") == B_OK );
-       CPPUNIT_ASSERT( link.InitCheck() == B_OK );
+       CPPUNIT_ASSERT(link.SetTo(&pathDir, "") == B_ENTRY_NOT_FOUND);
+       CPPUNIT_ASSERT(link.InitCheck() == B_ENTRY_NOT_FOUND);
        //
        NextSubTest();
        CPPUNIT_ASSERT( pathDir.SetTo(existingSuperFile) == B_OK );
@@ -556,8 +556,9 @@
        NextSubTest();
        char smallBuffer[2];
        CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
-       CPPUNIT_ASSERT( link.ReadLink(smallBuffer, sizeof(smallBuffer))
-                                       == (ssize_t)strlen(dirLink) );
+       CPPUNIT_ASSERT_EQUAL(
+               link.ReadLink(smallBuffer, sizeof(smallBuffer)),
+               B_BUFFER_OVERFLOW);
        CPPUNIT_ASSERT( strncmp(smallBuffer, existingDir, sizeof(smallBuffer)) 
== 0 );
        // bad args
        NextSubTest();

--
To view, visit https://review.haiku-os.org/c/haiku/+/2502
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I8bcb8b2a0c9333059c84ace15844c32d4efeed9d
Gerrit-Change-Number: 2502
Gerrit-PatchSet: 1
Gerrit-Owner: Kyle Ambroff-Kao <kyle@xxxxxxxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: tests/kits/storage: Fix SymLinkTest - Gerrit