Xonotic
test.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _TEST_ASSERT(statement)
 
#define ADD_FAILURE(msg)
 Add a failure, but continue. More...
 
#define ASSERT_EQ(expected, actual)   _TEST_ASSERT(EXPECT_EQ(expected, actual))
 
#define ASSERT_FALSE(condition)   ASSERT_EQ(false, condition)
 
#define ASSERT_GE(val1, val2)   _TEST_ASSERT(EXPECT_GE(val1, val2))
 
#define ASSERT_GT(val1, val2)   _TEST_ASSERT(EXPECT_GT(val1, val2))
 
#define ASSERT_LE(val1, val2)   _TEST_ASSERT(EXPECT_LE(val1, val2))
 
#define ASSERT_LT(val1, val2)   _TEST_ASSERT(EXPECT_LT(val1, val2))
 
#define ASSERT_NE(val1, val2)   _TEST_ASSERT(EXPECT_NE(val1, val2))
 
#define ASSERT_NO_FATAL_FAILURE(statement)   EXPECT_NO_FATAL_FAILURE_(statement, { ++TEST_fatal; return; })
 
#define ASSERT_TRUE(condition)   ASSERT_EQ(true, condition)
 
#define EXPECT_EQ(expected_, actual_)
 
#define EXPECT_FALSE(condition)   EXPECT_EQ(false, condition)
 
#define EXPECT_GE(val1, val2)   EXPECT_TRUE((val1) >= (val2))
 
#define EXPECT_GT(val1, val2)   EXPECT_TRUE((val1) > (val2))
 
#define EXPECT_LE(val1, val2)   EXPECT_TRUE((val1) <= (val2))
 
#define EXPECT_LT(val1, val2)   EXPECT_TRUE((val1) < (val2))
 
#define EXPECT_NE(val1, val2)   EXPECT_TRUE((val1) != (val2))
 
#define EXPECT_NO_FATAL_FAILURE(statement)   EXPECT_NO_FATAL_FAILURE_(statement, { })
 
#define EXPECT_NO_FATAL_FAILURE_(statement, then)
 
#define EXPECT_NO_FATAL_FAILURE__(statement, then)
 
#define EXPECT_TRUE(condition)   EXPECT_EQ(true, condition)
 
#define FAIL(msg)   _TEST_ASSERT(ADD_FAILURE(msg))
 Add a failure and return. More...
 
#define HasFatalFailure()   (TEST_fatal > 0)
 
#define SUCCEED()   (TEST_ok = true)
 Must be present at the end of a test. More...
 
#define TEST(suite, test)
 Use UpperCamelCase for suite and test only. More...
 

Functions

bool RUN_ALL_TESTS ()
 
bool TEST_Run (string test)
 

Variables

int TEST_failed
 
int TEST_fatal
 
bool TEST_ok
 

Macro Definition Documentation

◆ _TEST_ASSERT

#define _TEST_ASSERT (   statement)
Value:
LAMBDA(statement); \
++TEST_fatal; return; \
MACRO_END
#define LAMBDA(...)
Definition: misc.qh:37
int TEST_fatal
Definition: test.qh:73

Definition at line 77 of file test.qh.

◆ ADD_FAILURE

#define ADD_FAILURE (   msg)
Value:
LOG_WARN(msg); \
MACRO_END
#define MACRO_BEGIN
Definition: macro.qh:6
int TEST_failed
Definition: test.qh:75

Add a failure, but continue.

Definition at line 18 of file test.qh.

◆ ASSERT_EQ

#define ASSERT_EQ (   expected,
  actual 
)    _TEST_ASSERT(EXPECT_EQ(expected, actual))

Definition at line 44 of file test.qh.

◆ ASSERT_FALSE

#define ASSERT_FALSE (   condition)    ASSERT_EQ(false, condition)

Definition at line 50 of file test.qh.

◆ ASSERT_GE

#define ASSERT_GE (   val1,
  val2 
)    _TEST_ASSERT(EXPECT_GE(val1, val2))

Definition at line 65 of file test.qh.

◆ ASSERT_GT

#define ASSERT_GT (   val1,
  val2 
)    _TEST_ASSERT(EXPECT_GT(val1, val2))

Definition at line 62 of file test.qh.

◆ ASSERT_LE

#define ASSERT_LE (   val1,
  val2 
)    _TEST_ASSERT(EXPECT_LE(val1, val2))

Definition at line 59 of file test.qh.

◆ ASSERT_LT

#define ASSERT_LT (   val1,
  val2 
)    _TEST_ASSERT(EXPECT_LT(val1, val2))

Definition at line 56 of file test.qh.

◆ ASSERT_NE

#define ASSERT_NE (   val1,
  val2 
)    _TEST_ASSERT(EXPECT_NE(val1, val2))

Definition at line 53 of file test.qh.

◆ ASSERT_NO_FATAL_FAILURE

#define ASSERT_NO_FATAL_FAILURE (   statement)    EXPECT_NO_FATAL_FAILURE_(statement, { ++TEST_fatal; return; })

Definition at line 68 of file test.qh.

◆ ASSERT_TRUE

#define ASSERT_TRUE (   condition)    ASSERT_EQ(true, condition)

Definition at line 47 of file test.qh.

◆ EXPECT_EQ

#define EXPECT_EQ (   expected_,
  actual_ 
)
Value:
MACRO_BEGIN \
int expected = expected_; \
int actual = actual_; \
if ((expected) != (actual)) { \
ADD_FAILURE(sprintf( \
"Value of: " #actual_ "\n" \
" Actual: %d\n" \
"Expected: %d\n", \
actual, expected \
)); \
} \
MACRO_END

Definition at line 32 of file test.qh.

Referenced by TEST().

◆ EXPECT_FALSE

#define EXPECT_FALSE (   condition)    EXPECT_EQ(false, condition)

Definition at line 49 of file test.qh.

◆ EXPECT_GE

#define EXPECT_GE (   val1,
  val2 
)    EXPECT_TRUE((val1) >= (val2))

Definition at line 64 of file test.qh.

◆ EXPECT_GT

#define EXPECT_GT (   val1,
  val2 
)    EXPECT_TRUE((val1) > (val2))

Definition at line 61 of file test.qh.

Referenced by TEST().

◆ EXPECT_LE

#define EXPECT_LE (   val1,
  val2 
)    EXPECT_TRUE((val1) <= (val2))

Definition at line 58 of file test.qh.

◆ EXPECT_LT

#define EXPECT_LT (   val1,
  val2 
)    EXPECT_TRUE((val1) < (val2))

Definition at line 55 of file test.qh.

◆ EXPECT_NE

#define EXPECT_NE (   val1,
  val2 
)    EXPECT_TRUE((val1) != (val2))

Definition at line 52 of file test.qh.

Referenced by MX_Messages_(), MX_Sync_(), TEST(), and test_weapons_hurt().

◆ EXPECT_NO_FATAL_FAILURE

#define EXPECT_NO_FATAL_FAILURE (   statement)    EXPECT_NO_FATAL_FAILURE_(statement, { })

Definition at line 67 of file test.qh.

◆ EXPECT_NO_FATAL_FAILURE_

#define EXPECT_NO_FATAL_FAILURE_ (   statement,
  then 
)
Value:
LOG_WARNF( \
" Actual: %d fatal failures\n" \
"Expected: no fatal failures\n", \
TEST_fatal - TEST_prevfatal \
); \
LAMBDA(then); \
})
int TEST_fatal
Definition: test.qh:73
#define EXPECT_NO_FATAL_FAILURE__(statement, then)
Definition: test.qh:83

Definition at line 91 of file test.qh.

◆ EXPECT_NO_FATAL_FAILURE__

#define EXPECT_NO_FATAL_FAILURE__ (   statement,
  then 
)
Value:
MACRO_BEGIN \
int TEST_prevfatal = TEST_fatal; \
LAMBDA(statement); \
if (TEST_fatal != TEST_prevfatal) \
LAMBDA(then); \
MACRO_END
int TEST_fatal
Definition: test.qh:73

Definition at line 83 of file test.qh.

◆ EXPECT_TRUE

#define EXPECT_TRUE (   condition)    EXPECT_EQ(true, condition)

Definition at line 46 of file test.qh.

◆ FAIL

#define FAIL (   msg)    _TEST_ASSERT(ADD_FAILURE(msg))

Add a failure and return.

Definition at line 24 of file test.qh.

◆ HasFatalFailure

#define HasFatalFailure ( )    (TEST_fatal > 0)

Definition at line 26 of file test.qh.

◆ SUCCEED

#define SUCCEED ( )    (TEST_ok = true)

Must be present at the end of a test.

Definition at line 15 of file test.qh.

Referenced by TEST().

◆ TEST

#define TEST (   suite,
  test 
)
Value:
void _TEST_##suite##_##test(); \
ACCUMULATE int TEST_RunAll_accumulated(int f) { \
if (!TEST_Run(#suite "_" #test)) ++f; \
return = f; \
} \
void _TEST_##suite##_##test()
bool TEST_Run(string test)
Definition: test.qc:19
int TEST_RunAll_accumulated(int init)

Use UpperCamelCase for suite and test only.

Definition at line 6 of file test.qh.

Function Documentation

◆ RUN_ALL_TESTS()

bool RUN_ALL_TESTS ( )

Definition at line 4 of file test.qc.

References LOG_INFO, LOG_INFOF, and TEST_RunAll_accumulated().

Referenced by GenericCommand_runtest().

5 {
6  int f = TEST_RunAll_accumulated(0);
7  if (f)
8  {
9  LOG_INFOF("%d tests failed", f);
10  return true;
11  }
12  else
13  {
14  LOG_INFO("All tests OK");
15  return false;
16  }
17 }
int TEST_RunAll_accumulated(int init)
#define LOG_INFOF(...)
Definition: log.qh:71
#define LOG_INFO(...)
Definition: log.qh:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TEST_Run()

bool TEST_Run ( string  test)

Definition at line 19 of file test.qc.

References callfunction(), isfunction(), LOG_INFOF, strcat(), TEST_failed, TEST_fatal, and TEST_ok.

Referenced by GenericCommand_runtest().

20 {
21  LOG_INFOF("%s: testing...", s);
22  TEST_failed = 0;
23  TEST_fatal = 0;
24  TEST_ok = false;
25  string fn = strcat("_TEST_", s);
26  if (isfunction(fn)) callfunction(fn);
27  if (TEST_failed > 0)
28  {
29  LOG_INFOF("%s: %d items failed.", s, TEST_failed);
30  return false;
31  }
32  else if (!TEST_ok)
33  {
34  LOG_INFOF("%s: did not complete.", s);
35  return false;
36  }
37  return true;
38 }
#define LOG_INFOF(...)
Definition: log.qh:71
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int TEST_failed
Definition: test.qh:75
int TEST_fatal
Definition: test.qh:73
bool TEST_ok
Definition: test.qh:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ TEST_failed

int TEST_failed

Definition at line 75 of file test.qh.

Referenced by TEST_Run().

◆ TEST_fatal

int TEST_fatal

Definition at line 73 of file test.qh.

Referenced by TEST_Run().

◆ TEST_ok

bool TEST_ok

Definition at line 74 of file test.qh.

Referenced by TEST_Run().