diff --git a/src/tests/kits/storage/FileTest.cpp b/src/tests/kits/storage/FileTest.cpp index e6acf62f11..facd9e3b27 100644 --- a/src/tests/kits/storage/FileTest.cpp +++ b/src/tests/kits/storage/FileTest.cpp @@ -88,7 +88,7 @@ FileTest::InitTest1() { for (int32 i = 0; i < initTestCasesCount; i++) { if (BTestShell::GlobalBeVerbose()) { - printf("[%ld]", i); + printf("[%" B_PRId32 "]", i); fflush(stdout); } test(initTestCases[i]); @@ -197,7 +197,7 @@ FileTest::InitTest2() { for (int32 i = 0; i < initTestCasesCount; i++) { if (BTestShell::GlobalBeVerbose()) { - printf("[%ld]", i); + printf("[%" B_PRId32 "]", i); fflush(stdout); } test(initTestCases[i]); @@ -558,22 +558,22 @@ FileTest::SizeTest() off_t size; CPPUNIT_ASSERT( file.GetSize(&size) != B_OK ); CPPUNIT_ASSERT( file.SetSize(100) != B_OK ); - // read only file + // read only file, SetSize will not succeed NextSubTest(); file.SetTo(testFilename1, B_READ_ONLY | B_CREATE_FILE); CPPUNIT_ASSERT( file.InitCheck() == B_OK ); CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); CPPUNIT_ASSERT( size == 0 ); - CPPUNIT_ASSERT( file.SetSize(100) == B_OK ); + CPPUNIT_ASSERT_EQUAL(file.SetSize(100), B_BAD_VALUE); CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); - CPPUNIT_ASSERT( size == 100 ); + CPPUNIT_ASSERT_EQUAL(size, 0); file.Unset(); - // shorten existing file + // successfully set size of file with appropriate flags NextSubTest(); file.SetTo(testFilename1, B_WRITE_ONLY); CPPUNIT_ASSERT( file.InitCheck() == B_OK ); CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); - CPPUNIT_ASSERT( size == 100 ); + CPPUNIT_ASSERT_EQUAL(size, 0); CPPUNIT_ASSERT( file.SetSize(73) == B_OK ); CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); CPPUNIT_ASSERT( size == 73 ); @@ -588,16 +588,6 @@ FileTest::SizeTest() CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); CPPUNIT_ASSERT( size == 147 ); file.Unset(); - // erase existing file (read only) - NextSubTest(); - file.SetTo(testFilename1, B_READ_ONLY | B_ERASE_FILE); - CPPUNIT_ASSERT( file.InitCheck() == B_OK ); - CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); - CPPUNIT_ASSERT( size == 0 ); - CPPUNIT_ASSERT( file.SetSize(132) == B_OK ); - CPPUNIT_ASSERT( file.GetSize(&size) == B_OK ); - CPPUNIT_ASSERT( size == 132 ); - file.Unset(); // erase existing file (write only) NextSubTest(); file.SetTo(testFilename1, B_WRITE_ONLY | B_ERASE_FILE); @@ -728,13 +718,13 @@ const FileTest::InitTestCase FileTest::initTestCases[] = { { existingFilename , B_READ_ONLY , 0, 1, 0, false, B_OK }, { existingFilename , B_WRITE_ONLY, 0, 1, 0, false, B_OK }, { existingFilename , B_READ_WRITE, 0, 1, 0, false, B_OK }, - { existingFilename , B_READ_ONLY , 0, 0, 1, false, B_OK }, + { existingFilename , B_READ_ONLY , 0, 0, 1, false, B_NOT_ALLOWED }, { existingFilename , B_WRITE_ONLY, 0, 0, 1, false, B_OK }, { existingFilename , B_READ_WRITE, 0, 0, 1, false, B_OK }, { existingFilename , B_READ_ONLY , 1, 1, 0, false, B_FILE_EXISTS }, { existingFilename , B_WRITE_ONLY, 1, 1, 0, false, B_FILE_EXISTS }, { existingFilename , B_READ_WRITE, 1, 1, 0, false, B_FILE_EXISTS }, - { existingFilename , B_READ_ONLY , 1, 0, 1, false, B_OK }, + { existingFilename , B_READ_ONLY , 1, 0, 1, false, B_NOT_ALLOWED }, { existingFilename , B_WRITE_ONLY, 1, 0, 1, false, B_OK }, { existingFilename , B_READ_WRITE, 1, 0, 1, false, B_OK }, { existingFilename , B_READ_ONLY , 1, 1, 1, false, B_FILE_EXISTS }, diff --git a/src/tests/kits/storage/NodeTest.cpp b/src/tests/kits/storage/NodeTest.cpp index c3e3dcd348..193a128a2d 100644 --- a/src/tests/kits/storage/NodeTest.cpp +++ b/src/tests/kits/storage/NodeTest.cpp @@ -733,16 +733,23 @@ NodeTest::AttrTest(BNode &node) B_BAD_ADDRESS, B_BAD_VALUE) ); CPPUNIT_ASSERT( equals(node.RemoveAttr(NULL), B_BAD_ADDRESS, B_BAD_VALUE) ); // too long attribute name -// R5: Read/RemoveAttr() do not return B_NAME_TOO_LONG, but B_ENTRY_NOT_FOUND -// R5: WriteAttr() does not return B_NAME_TOO_LONG, but B_BAD_VALUE - char tooLongAttrName[B_ATTR_NAME_LENGTH + 1]; - memset(tooLongAttrName, 'a', B_ATTR_NAME_LENGTH); - tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = 0; - CPPUNIT_ASSERT( node.WriteAttr(tooLongAttrName, B_STRING_TYPE, 0, buffer, - sizeof(buffer)) == B_BAD_VALUE ); - CPPUNIT_ASSERT( node.ReadAttr(tooLongAttrName, B_STRING_TYPE, 0, buffer, - sizeof(buffer)) == B_ENTRY_NOT_FOUND ); - CPPUNIT_ASSERT( node.RemoveAttr(tooLongAttrName) == B_ENTRY_NOT_FOUND ); + // R5: Read/RemoveAttr() do not return B_NAME_TOO_LONG, but B_ENTRY_NOT_FOUND + // R5: WriteAttr() does not return B_NAME_TOO_LONG, but B_BAD_VALUE + // R5: Haiku has a max attribute size of 256, while R5's was 255, exclusive + // of the null terminator. See changeset 4069e1f30. + char tooLongAttrName[B_ATTR_NAME_LENGTH + 3]; + memset(tooLongAttrName, 'a', B_ATTR_NAME_LENGTH + 1); + tooLongAttrName[B_ATTR_NAME_LENGTH + 2] = '\0'; + CPPUNIT_ASSERT_EQUAL( + node.WriteAttr(tooLongAttrName, B_STRING_TYPE, 0, buffer, + sizeof(buffer)), + B_NAME_TOO_LONG); + CPPUNIT_ASSERT_EQUAL( + node.ReadAttr(tooLongAttrName, B_STRING_TYPE, 0, buffer, + sizeof(buffer)), + B_NAME_TOO_LONG); + CPPUNIT_ASSERT_EQUAL(node.RemoveAttr(tooLongAttrName), B_NAME_TOO_LONG); + // remove the attributes and try to read them for (int32 i = 0; i < attrCount; i++) { const char *attrName = attrNames[i]; @@ -787,20 +794,32 @@ NodeTest::AttrTest() void NodeTest::AttrRenameTest(BNode &node) { -#if !TEST_R5 const char attr1[] = "StorageKit::SomeAttribute"; const char attr2[] = "StorageKit::AnotherAttribute"; + + CPPUNIT_ASSERT( node.SetTo("./") == B_OK ); + + // Test the case of the first attribute not existing + node.RemoveAttr(attr1); + +#if 1 + // The actual tests in the else block below are disabled because as of + // right now, BFS doesn't support attribute rename. bfs_rename_attr() + // always reutrns B_NOT_SUPPORTED, which means BNode::RenameAttr() will + // also always return that result. + // + // So until that is implemented, we'll just test for B_NOT_SUPPORTED here. + // Once that functionality is implemented, this test will pass and someone + // can remove this section. + CPPUNIT_ASSERT_EQUAL(node.RenameAttr(attr1, attr2), B_NOT_SUPPORTED); +#else const char str[] = "This is my testing string and it rules your world."; const int strLen = strlen(str) + 1; const int dataLen = 1024; char data[dataLen]; - - CPPUNIT_ASSERT( node.SetTo("./") == B_OK ); - // Test the case of the first attribute not existing - node.RemoveAttr(attr1); CPPUNIT_ASSERT( node.RenameAttr(attr1, attr2) == B_BAD_VALUE ); - + // Write an attribute, read it to verify it, rename it, read the // new attribute, read the old (which fails), and then remove the new. CPPUNIT_ASSERT( node.WriteAttr(attr1, B_STRING_TYPE, 0, str, strLen) == strLen ); @@ -821,9 +840,9 @@ NodeTest::AttrRenameTest(BNode &node) B_BAD_VALUE) ); // too long attribute name // R5: RenameAttr() returns B_BAD_VALUE instead of B_NAME_TOO_LONG - char tooLongAttrName[B_ATTR_NAME_LENGTH + 1]; + char tooLongAttrName[B_ATTR_NAME_LENGTH + 2]; memset(tooLongAttrName, 'a', B_ATTR_NAME_LENGTH); - tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = 0; + tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = '\0'; CPPUNIT_ASSERT( node.RenameAttr(attr1, tooLongAttrName) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.RenameAttr(tooLongAttrName, attr1) @@ -908,9 +927,9 @@ NodeTest::AttrInfoTest(BNode &node) B_BAD_VALUE) ); // too long attribute name // R5: GetAttrInfo() does not return B_NAME_TOO_LONG - char tooLongAttrName[B_ATTR_NAME_LENGTH + 1]; + char tooLongAttrName[B_ATTR_NAME_LENGTH + 2]; memset(tooLongAttrName, 'a', B_ATTR_NAME_LENGTH); - tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = 0; + tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = '\0'; CPPUNIT_ASSERT( node.GetAttrInfo(tooLongAttrName, &info) == B_ENTRY_NOT_FOUND ); } @@ -1007,9 +1026,9 @@ NodeTest::AttrBStringTest(BNode &node) } // too long attribute name // R5: Read/WriteAttrString() do not return B_NAME_TOO_LONG - char tooLongAttrName[B_ATTR_NAME_LENGTH + 1]; + char tooLongAttrName[B_ATTR_NAME_LENGTH + 2]; memset(tooLongAttrName, 'a', B_ATTR_NAME_LENGTH); - tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = 0; + tooLongAttrName[B_ATTR_NAME_LENGTH + 1] = '\0'; CPPUNIT_ASSERT( node.WriteAttrString(tooLongAttrName, &writeValue) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.ReadAttrString(tooLongAttrName, &readValue)