1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Very simple unit testing framework.
19 */
20
21#ifndef __CUTILS_TEST_H
22#define __CUTILS_TEST_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * Adds a test to the test suite.
30 */
31#define addTest(test) addNamedTest(#test, &test)
32
33/**
34 * Asserts that a condition is true. The test fails if it isn't.
35 */
36#define assertTrue(value, message) assertTrueWithSource(value, __FILE__, __LINE__, message);
37
38/**
39 * Asserts that a condition is false. The test fails if the value is true.
40 */
41#define assertFalse(value, message) assertTrueWithSource(!value, __FILE__, __LINE__, message);
42
43/** Fails a test with the given message. */
44#define fail(message) assertTrueWithSource(0, __FILE__, __LINE__, message);
45
46/**
47 * Asserts that two values are ==.
48 */
49#define assertSame(a, b) assertTrueWithSource(a == b, __FILE__, __LINE__, "Expected same value.");
50
51/**
52 * Asserts that two values are !=.
53 */
54#define assertNotSame(a, b) assertTrueWithSource(a != b, __FILE__, __LINE__,\
55        "Expected different values");
56
57/**
58 * Runs a test suite.
59 */
60void runTests(void);
61
62// Do not call these functions directly. Use macros above instead.
63void addNamedTest(const char* name, void (*test)(void));
64void assertTrueWithSource(int value, const char* file, int line, char* message);
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif /* __CUTILS_TEST_H */
71