summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks/KernelTest.fwrk
diff options
context:
space:
mode:
Diffstat (limited to 'public/frameworks/KernelTest.fwrk')
-rw-r--r--public/frameworks/KernelTest.fwrk/headers/Foundation.h16
-rw-r--r--public/frameworks/KernelTest.fwrk/headers/KernelTest.h31
-rw-r--r--public/frameworks/KernelTest.fwrk/headers/SourceLocation.h36
-rw-r--r--public/frameworks/KernelTest.fwrk/headers/TestCase.h56
-rw-r--r--public/frameworks/KernelTest.fwrk/src/CSymbols.cc21
-rw-r--r--public/frameworks/KernelTest.fwrk/src/UnitTests.cc17
6 files changed, 129 insertions, 48 deletions
diff --git a/public/frameworks/KernelTest.fwrk/headers/Foundation.h b/public/frameworks/KernelTest.fwrk/headers/Foundation.h
new file mode 100644
index 00000000..4329af6b
--- /dev/null
+++ b/public/frameworks/KernelTest.fwrk/headers/Foundation.h
@@ -0,0 +1,16 @@
+/* ========================================
+
+ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#pragma once
+
+#include <KernelKit/DebugOutput.h>
+#include <NeKit/KernelPanic.h>
+
+#define KT_TEST_VERSION_BCD (0x0001)
+#define KT_TEST_VERSION "dev-nekernel-test"
+
+#define KT_TEST_SUCCESS (kErrorSuccess)
+#define KT_TEST_FAILURE (kErrorSuccess + 1)
diff --git a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h
deleted file mode 100644
index 7b25c8a4..00000000
--- a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* ========================================
-
- Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#pragma once
-
-#include <NeKit/KernelPanic.h>
-
-/// @brief Kernel Test Framework.
-/// @file KernelTest.h
-
-#define KT_TEST_VERSION_BCD (0x0002)
-#define KT_TEST_VERSION "v0.0.2-kerneltest"
-
-#define KT_TEST_FAILURE (1)
-
-#define KT_TEST_SUCCESS (0)
-
-#define KT_DECL_TEST(NAME, FN) \
- class KT_##NAME final { \
- public: \
- Kernel::Void Run(); \
- const Kernel::Char* ToString(); \
- }; \
- inline Kernel::Void KT_##NAME::Run() { MUST_PASS(FN() == true); } \
- inline const Kernel::Char* KT_##NAME::ToString() { return #FN; }
-
-KT_DECL_TEST(ALWAYS_BREAK, []() -> bool { return false; });
-KT_DECL_TEST(ALWAYS_GOOD, []() -> bool { return true; }); \ No newline at end of file
diff --git a/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h b/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h
new file mode 100644
index 00000000..6507864b
--- /dev/null
+++ b/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h
@@ -0,0 +1,36 @@
+/* ========================================
+
+ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#pragma once
+
+#include <CoreFoundation.fwrk/headers/Object.h>
+#include <CoreFoundation.fwrk/headers/String.h>
+#include <KernelTest.fwrk/headers/Foundation.h>
+
+class KTSourceLocation;
+
+/// ================================================================================
+/// @brief SourceLocation class for Kernel Test Framework.
+/// ================================================================================
+class KTSourceLocation final CF_OBJECT {
+ public:
+ explicit KTSourceLocation() = delete;
+ ~KTSourceLocation() override = default;
+
+ LIBSYS_COPY_DELETE(KTSourceLocation);
+
+ public:
+ KTSourceLocation(const Char*, const SInt32 = 0UL);
+
+ CF::CFString File();
+ SInt32 Line();
+
+ CF::CFString operator()();
+
+ private:
+ CF::CFString mFile{4096};
+ SInt32 mLine{0U};
+}; \ No newline at end of file
diff --git a/public/frameworks/KernelTest.fwrk/headers/TestCase.h b/public/frameworks/KernelTest.fwrk/headers/TestCase.h
new file mode 100644
index 00000000..c040ca0f
--- /dev/null
+++ b/public/frameworks/KernelTest.fwrk/headers/TestCase.h
@@ -0,0 +1,56 @@
+/* ========================================
+
+ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#pragma once
+
+#include <KernelTest.fwrk/headers/SourceLocation.h>
+
+/// ================================================================================
+/// @brief Kernel Test Framework main header.
+/// @file TestCase.h
+/// ================================================================================
+
+#define KT_RUN_TEST(OBJECT) {KTTestCase##OBJECT{}.Run();}
+
+#define KT_MUST_PASS(MSG, LEFT_COND, RIGHT_COND) \
+ if (LEFT_COND != RIGHT_COND) { \
+ (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] BREAK: LEFT_COND: " << #LEFT_COND \
+ << " RIGHT_COND: " << #RIGHT_COND << Kernel::kendl); \
+ (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] BREAK: MSG: " << MSG << Kernel::kendl); \
+ MUST_PASS(NO); \
+ } else { \
+ (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] PASS: MSG: " << MSG << Kernel::kendl); \
+ }
+
+#define KT_DECL_TEST(NAME, FN) \
+ class KTTestCase##NAME final { \
+ public: \
+ explicit KTTestCase##NAME() = default; \
+ ~KTTestCase##NAME() = default; \
+ LIBSYS_COPY_DELETE(KTTestCase##NAME); \
+ Kernel::Void Run(); \
+ const Kernel::Char* ToString(); \
+ }; \
+ inline Kernel::Void KTTestCase##NAME::Run() { \
+ auto ret = FN() == YES; \
+ if (!ret) { \
+ Kernel::kout << "[KERNEL-TEST] TEST FAILED!" << Kernel::kendl; \
+ MUST_PASS(ret); \
+ } \
+ } \
+ inline const Kernel::Char* KTTestCase##NAME::ToString() { \
+ return #FN; \
+ }
+
+KT_DECL_TEST(AlwaysBreak, []() -> bool {
+ KT_MUST_PASS("AlwaysBreak", YES, NO);
+ return NO;
+});
+
+KT_DECL_TEST(AlwaysPass, []() -> bool {
+ KT_MUST_PASS("AlwaysPass", YES, YES);
+ return YES;
+}); \ No newline at end of file
diff --git a/public/frameworks/KernelTest.fwrk/src/CSymbols.cc b/public/frameworks/KernelTest.fwrk/src/CSymbols.cc
new file mode 100644
index 00000000..575525f0
--- /dev/null
+++ b/public/frameworks/KernelTest.fwrk/src/CSymbols.cc
@@ -0,0 +1,21 @@
+/* ========================================
+
+ Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#include <public/frameworks/KernelTest.fwrk/headers/TestCase.h>
+
+/// ================================================================================
+/// @brief Function to run breaking test.
+/// ================================================================================
+EXTERN_C Kernel::Void KT_TestBreak() {
+ KT_RUN_TEST(AlwaysBreak);
+}
+
+/// ================================================================================
+/// @brief Function to run passing test.
+/// ================================================================================
+EXTERN_C Kernel::Void KT_TestPass() {
+ KT_RUN_TEST(AlwaysPass);
+} \ No newline at end of file
diff --git a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc
deleted file mode 100644
index ab6effa9..00000000
--- a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-/* ========================================
-
- Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#include <public/frameworks/KernelTest.fwrk/headers/KernelTest.h>
-
-EXTERN_C Kernel::Void KT_TestBreak() {
- KT_ALWAYS_BREAK brk;
- brk.Run();
-}
-
-EXTERN_C Kernel::Void KT_TestGood() {
- KT_ALWAYS_GOOD good;
- good.Run();
-} \ No newline at end of file