From 2c17ecf993238e82ed75c327a5442cd4b473f805 Mon Sep 17 00:00:00 2001 From: Kyle Ambroff-Kao Date: Wed, 1 Jan 2020 00:44:32 -0800 Subject: [PATCH] tests/kits/support/bmemoryio: Fix WriteTest This patch fixes a bug in the BMemoryIO unit tests that made them fail and adds an additional test case for read-only buffers. The failing test case invokes BMemoryIO::WriteAt() with the position parameter set to -10, which is invalid and should result in a return value of B_BAD_VALUE. And it does, but the test fails because it was testing for the return value 5, as in 5 bytes copied. An additional test case is added for read-only BMemoryIO objects. If the BMemoryIO(const void*, size_t) constructor is used then it will be marked as read-only, so writes should fail with B_NOT_ALLOWED. Change-Id: Icf4b837c77fba2be958f9d3e4b3adb18a23b037f Reviewed-on: https://review.haiku-os.org/c/haiku/+/2066 Reviewed-by: Adrien Destugues Reviewed-by: waddlesplash --- src/tests/kits/support/bmemoryio/WriteTest.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tests/kits/support/bmemoryio/WriteTest.cpp b/src/tests/kits/support/bmemoryio/WriteTest.cpp index 6c30692b67..d52ae7bf31 100644 --- a/src/tests/kits/support/bmemoryio/WriteTest.cpp +++ b/src/tests/kits/support/bmemoryio/WriteTest.cpp @@ -54,7 +54,16 @@ WriteTest::PerformTest(void) memset(buf, 0, 10); pos = mem.Position(); err = mem.WriteAt(-10, writeBuf, 5); - CPPUNIT_ASSERT(err == 5); + CPPUNIT_ASSERT(err == B_BAD_VALUE); + CPPUNIT_ASSERT(mem.Position() == pos); + + NextSubTest(); + memset(buf, 0, 10); + BMemoryIO read_only_mem(const_cast(buf), 10); + pos = read_only_mem.Position(); + err = read_only_mem.WriteAt(3, writeBuf, 2); + CPPUNIT_ASSERT(err == B_NOT_ALLOWED); + CPPUNIT_ASSERT(read_only_mem.Position() == pos); }