Refactor Kernel FS tests

Change-Id: Ic8c403bf02a080c12d199bb44d30c694e600f351
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10674
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Kacper Kasper
2026-04-07 13:16:46 +00:00
parent 71fc6a97b4
commit 499154375f
3 changed files with 312 additions and 404 deletions
+33 -83
View File
@@ -4,15 +4,14 @@
*/ */
#include "KPathTest.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fs/KPath.h> #include <fs/KPath.h>
#include <cppunit/TestCaller.h> #include <TestSuiteAddon.h>
#include <cppunit/TestSuite.h> #include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
typedef void* mutex; typedef void* mutex;
@@ -73,21 +72,24 @@ _mutex_unlock(mutex* lock)
} }
// #pragma mark - class KPathTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(KPathTest);
CPPUNIT_TEST(TestSetToAndPath);
CPPUNIT_TEST(TestLazyAlloc);
CPPUNIT_TEST(TestLeaf);
CPPUNIT_TEST(TestReplaceLeaf);
CPPUNIT_TEST(TestRemoveLeaf);
CPPUNIT_TEST(TestAdopt);
CPPUNIT_TEST(TestLockBuffer);
CPPUNIT_TEST(TestDetachBuffer);
CPPUNIT_TEST(TestNormalize);
CPPUNIT_TEST(TestAssign);
CPPUNIT_TEST(TestEquals);
CPPUNIT_TEST(TestNotEquals);
CPPUNIT_TEST_SUITE_END();
public:
KPathTest::KPathTest() void TestSetToAndPath()
{
}
KPathTest::~KPathTest()
{
}
void
KPathTest::TestSetToAndPath()
{ {
KPath path; KPath path;
status_t status = path.InitCheck(); status_t status = path.InitCheck();
@@ -120,9 +122,7 @@ KPathTest::TestSetToAndPath()
CPPUNIT_ASSERT(status == B_NO_MEMORY); CPPUNIT_ASSERT(status == B_NO_MEMORY);
} }
void TestLazyAlloc()
void
KPathTest::TestLazyAlloc()
{ {
KPath path(NULL, KPath::LAZY_ALLOC); KPath path(NULL, KPath::LAZY_ALLOC);
CPPUNIT_ASSERT(path.Path() == NULL); CPPUNIT_ASSERT(path.Path() == NULL);
@@ -149,9 +149,7 @@ KPathTest::TestLazyAlloc()
CPPUNIT_ASSERT(path.InitCheck() == B_NO_MEMORY); CPPUNIT_ASSERT(path.InitCheck() == B_NO_MEMORY);
} }
void TestLeaf()
void
KPathTest::TestLeaf()
{ {
KPath path("a"); KPath path("a");
CPPUNIT_ASSERT(strcmp(path.Path(), "a") == 0); CPPUNIT_ASSERT(strcmp(path.Path(), "a") == 0);
@@ -178,9 +176,7 @@ KPathTest::TestLeaf()
CPPUNIT_ASSERT(strcmp(path.Leaf(), "c") == 0); CPPUNIT_ASSERT(strcmp(path.Leaf(), "c") == 0);
} }
void TestReplaceLeaf()
void
KPathTest::TestReplaceLeaf()
{ {
KPath path; KPath path;
status_t status = path.ReplaceLeaf("x"); status_t status = path.ReplaceLeaf("x");
@@ -205,9 +201,7 @@ KPathTest::TestReplaceLeaf()
CPPUNIT_ASSERT(strcmp(path.Path(), "/c") == 0); CPPUNIT_ASSERT(strcmp(path.Path(), "/c") == 0);
} }
void TestRemoveLeaf()
void
KPathTest::TestRemoveLeaf()
{ {
KPath path; KPath path;
bool removed = path.RemoveLeaf(); bool removed = path.RemoveLeaf();
@@ -241,9 +235,7 @@ KPathTest::TestRemoveLeaf()
CPPUNIT_ASSERT(path.Length() == 1); CPPUNIT_ASSERT(path.Length() == 1);
} }
void TestAdopt()
void
KPathTest::TestAdopt()
{ {
KPath one("first", false, 10); KPath one("first", false, 10);
CPPUNIT_ASSERT(one.InitCheck() == B_OK); CPPUNIT_ASSERT(one.InitCheck() == B_OK);
@@ -277,9 +269,7 @@ KPathTest::TestAdopt()
CPPUNIT_ASSERT(one.Length() == 4); CPPUNIT_ASSERT(one.Length() == 4);
} }
void TestLockBuffer()
void
KPathTest::TestLockBuffer()
{ {
KPath path; KPath path;
CPPUNIT_ASSERT(path.Path() != NULL); CPPUNIT_ASSERT(path.Path() != NULL);
@@ -309,9 +299,7 @@ KPathTest::TestLockBuffer()
CPPUNIT_ASSERT(third.Length() == 4); CPPUNIT_ASSERT(third.Length() == 4);
} }
void TestDetachBuffer()
void
KPathTest::TestDetachBuffer()
{ {
KPath path("test"); KPath path("test");
CPPUNIT_ASSERT(path.InitCheck() == B_OK); CPPUNIT_ASSERT(path.InitCheck() == B_OK);
@@ -324,9 +312,7 @@ KPathTest::TestDetachBuffer()
CPPUNIT_ASSERT(path.InitCheck() == B_NO_INIT); CPPUNIT_ASSERT(path.InitCheck() == B_NO_INIT);
} }
void TestNormalize()
void
KPathTest::TestNormalize()
{ {
// Outside the kernel, we only test the error case. // Outside the kernel, we only test the error case.
KPath path("test/../out"); KPath path("test/../out");
@@ -345,9 +331,7 @@ KPathTest::TestNormalize()
CPPUNIT_ASSERT(path.Path() == path.Leaf()); CPPUNIT_ASSERT(path.Path() == path.Leaf());
} }
void TestAssign()
void
KPathTest::TestAssign()
{ {
KPath one("first", false, 10); KPath one("first", false, 10);
CPPUNIT_ASSERT(one.Length() == 5); CPPUNIT_ASSERT(one.Length() == 5);
@@ -365,9 +349,7 @@ KPathTest::TestAssign()
CPPUNIT_ASSERT(strcmp(one.Path(), "/whatever") == 0); CPPUNIT_ASSERT(strcmp(one.Path(), "/whatever") == 0);
} }
void TestEquals()
void
KPathTest::TestEquals()
{ {
KPath a("one"); KPath a("one");
KPath b("two"); KPath b("two");
@@ -380,9 +362,7 @@ KPathTest::TestEquals()
CPPUNIT_ASSERT_MESSAGE("3.", !(a == b)); CPPUNIT_ASSERT_MESSAGE("3.", !(a == b));
} }
void TestNotEquals()
void
KPathTest::TestNotEquals()
{ {
KPath a("one"); KPath a("one");
KPath b("two"); KPath b("two");
@@ -394,37 +374,7 @@ KPathTest::TestNotEquals()
b = "ones"; b = "ones";
CPPUNIT_ASSERT_MESSAGE("3.", a != b); CPPUNIT_ASSERT_MESSAGE("3.", a != b);
} }
};
/*static*/ void CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(KPathTest, getTestSuiteName());
KPathTest::AddTests(BTestSuite& parent)
{
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("KPathTest");
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestSetToAndPath", &KPathTest::TestSetToAndPath));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestLazyAlloc", &KPathTest::TestLazyAlloc));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestLeaf", &KPathTest::TestLeaf));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestReplaceLeaf", &KPathTest::TestReplaceLeaf));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestRemoveLeaf", &KPathTest::TestRemoveLeaf));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestAdopt", &KPathTest::TestAdopt));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestLockBuffer", &KPathTest::TestLockBuffer));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestDetachBuffer", &KPathTest::TestDetachBuffer));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestNormalize", &KPathTest::TestNormalize));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestAssign", &KPathTest::TestAssign));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestEquals", &KPathTest::TestEquals));
suite.addTest(new CppUnit::TestCaller<KPathTest>(
"KPathTest::TestNotEquals", &KPathTest::TestNotEquals));
parent.addTest("KPathTest", &suite);
}
-35
View File
@@ -1,35 +0,0 @@
/*
* Copyright 2017, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef KPATH_TEST_H
#define KPATH_TEST_H
#include <TestCase.h>
#include <TestSuite.h>
class KPathTest : public CppUnit::TestCase {
public:
KPathTest();
virtual ~KPathTest();
void TestSetToAndPath();
void TestLazyAlloc();
void TestLeaf();
void TestReplaceLeaf();
void TestRemoveLeaf();
void TestAdopt();
void TestLockBuffer();
void TestDetachBuffer();
void TestNormalize();
void TestAssign();
void TestEquals();
void TestNotEquals();
static void AddTests(BTestSuite& suite);
};
#endif // KPATH_TEST_H
@@ -4,18 +4,11 @@
*/ */
#include <TestSuite.h>
#include <TestSuiteAddon.h> #include <TestSuiteAddon.h>
#include "KPathTest.h"
const char*
BTestSuite* getTestSuiteName()
getTestSuite()
{ {
BTestSuite* suite = new BTestSuite("KernelFS"); return "KernelFS";
KPathTest::AddTests(*suite);
return suite;
} }