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