summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks/KernelTest.fwrk/headers/TestCase.h
blob: 0a6208a851ef6adddac7c1a4724d9f4c09fd9046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel

#ifndef HEADERS_TESTCASE_H
#define HEADERS_TESTCASE_H

#include <KernelTest.fwrk/headers/SourceLocation.h>

/// ================================================================================
/// @brief Kernel Test Framework main header.
/// @file TestCase.h
/// ================================================================================

#define KT_RUN_TEST(OBJECT)   \
  {                           \
    KTTestCase##OBJECT obj{}; \
    obj.Run();                \
  }

#define KT_MUST_PASS(MSG, LEFT_COND, RIGHT_COND) \
  if (LEFT_COND != RIGHT_COND) {                 \
    MUST_PASS(NO);                               \
  }

#define KT_DECL_TEST(NAME, FN)                         \
  class KTTestCase##NAME final {                       \
   public:                                             \
    KTTestCase##NAME()  = default;                     \
    ~KTTestCase##NAME() = default;                     \
    LIBSYS_COPY_DELETE(KTTestCase##NAME);              \
    Void        Run();                                 \
    const Char* ToString();                            \
  };                                                   \
  inline Void KTTestCase##NAME::Run() {                \
    auto ret = FN() == YES;                            \
    if (!ret) {                                        \
      PrintOut(nullptr, "[KERNEL-TEST] TEST FAILED!"); \
      KT_MUST_PASS(ret, ret, true);                    \
    }                                                  \
  }                                                    \
  inline const 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;
});

#endif