summaryrefslogtreecommitdiffstats
path: root/storage/maria/libmarias3/docs/contributors/test_cases.rst
blob: f6796f04f39f0ec1779ddd0a0a5ee3cd7c313c30 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
Writing Test Cases
==================

libMariaS3 uses DDM4's YATL library to create unit tests, this provides macros to test if the outcomes are as expected.

Adding a Test Case
------------------

Test cases are basic C applications in the ``tests/`` directory.  To add a test case to the suite.  To add a test edit the ``include.am`` and add the following (replacing *mytest* with whatever the test is called):

.. code-block:: makefile

   t_mytest_SOURCES= tests/mytest.c
   t_mytest_LDADD= src/libmarias3.la
   check_PROGRAMS+= t/mytest
   noinst_PROGRAMS+= t/mytest


Using YATL
----------

YATL is needed to make sure conditions within the test program are met.  To include it in your test application, add the following:

.. code-block:: c

   #include <yatl/lite.h>

A test skip can be added if certain conditions aren't met:

.. code-block:: c

   SKIP_IF_(!is_connected, "Cannot connected to a database server")

There are many types of assert provided as can be seen in the next section, they can be used as follows:

.. code-block:: c

   ASSERT_EQ_(3, column, "Column count unexpected)
   ASSERT_FALSE_(false_condition, "False condition is not false")
   ASSERT_STREQ_("test", some_data, "Unexpected data")

YATL Library
------------

Parameter Definitions
^^^^^^^^^^^^^^^^^^^^^

.. c:type:: __expression

   An expression typically used in an ``if`` statement.

.. c:type:: __expected

   An expected variable or expression

.. c:type:: __actual

   The actual variable or expression

.. c:type:: __expected_str

   The expected string

.. c:type:: __actual_str

   The actual string to compare with

.. c:type:: __length

   The length of a string for comparison

Function Definitions
^^^^^^^^^^^^^^^^^^^^

.. c:macro:: SKIP_IF(__expression)

   Skips the test if the expression is true

.. c:macro:: SKIP_IF_(__expression, ...)

   Skips the test if the expression is true and uses a printf style format message

.. c:macro:: ASSERT_TRUE(__expression)

   Make sure the expression is true, test will fail if it is false

.. c:macro:: ASSERT_FALSE(__expression)

   Make sure the expression is false, test will fail if it is true

.. c:macro:: ASSERT_FALSE_(__expression, ...)

   Make sure the expression is false and use a printf style format message to fail if it is true.

.. c:macro:: ASSERT_NULL_(__expression, ...)

   Make sure the expression is :c:type:`NULL` and use a printf style format message to fail if it isn't.

.. c:macro:: ASSERT_NOT_NULL(__expression)

   Make sure the expression is not :c:type:`NULL`, test will fail if it is :c:type:`NULL`.

.. c:macro:: ASSERT_NOT_NULL_(__expression, ...)

   Make sure the expression is not :c:type:`NULL` and use a printf style format message to fail if it is.

.. c:macro:: ASSERT_TRUE_(__expression, ...)

   Make sure the expression is ``true`` and use a printf style format message to fail if it is not.

.. c:macro:: ASSERT_EQ(__expected, __actual)

   Make sure that one condition or variable matches another one.

   .. note::
      Not suitable for string matching

.. c:macro:: ASSERT_EQ_(__expected, __actual, ...)

   Make sure that one condition or variable matches another one and use a printf style format message to fail if the do not match.

   .. note::
      Not suitable for string matching

.. c:macro:: ASSERT_NEQ(__expected, __actual)

   Make sure that one condition or variable does not match another one.

   .. note::
      Not suitable for string matching

.. c:macro:: ASSERT_NEQ_(__expected, __actual, ...)

   Make sure that one condition or variable does not match another one and use a printf style format message to fail if they do match.

   .. note::
      Not suitable for string matching

.. c:macro:: ASSERT_STREQ(__expected_str, __actual_str)

   Compare one ``NUL`` terminated string with another one and fail if they do not match.

.. c:macro:: ASSERT_STREQ_(__expected_str, __actual_str, ...)

   Compare one ``NUL`` terminated string with another one and use a printf style format message to fail if they do not match.

.. c:macro:: ASSERT_STREQL_(__expected_str, __actual_str, __length, ...)

   Compare a string of :c:type:`__length` to another one and use a printf style format message to fail if they do not match.

   .. note::
      This is designed for use with non-NUL-terminated strings.

.. c:macro:: ASSERT_STRNE(__expected_str, __actual_str)

   Compare one ``NUL`` terminated string with another one and fail if they match.

.. c:macro:: ASSERT_STRNE_(__expected_str, __actual_str, ...)

   Compare one ``NUL`` terminated string with another one and use a printf style format message to fail if they match.