OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Common functions used by tests. | 5 * Common functions used by tests. |
6 */ | 6 */ |
7 | 7 |
8 #include "test_common.h" | 8 #include "test_common.h" |
9 | 9 |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include "cryptolib.h" | 12 #include "cryptolib.h" |
13 #include "file_keys.h" | 13 #include "file_keys.h" |
14 #include "utility.h" | 14 #include "utility.h" |
15 | 15 |
16 /* ANSI Color coding sequences. */ | |
17 #define COL_GREEN "\e[1;32m" | |
18 #define COL_RED "\e[0;31m" | |
19 #define COL_STOP "\e[m" | |
20 | |
21 /* Global test success flag. */ | 16 /* Global test success flag. */ |
22 int gTestSuccess = 1; | 17 int gTestSuccess = 1; |
23 | 18 |
24 int TEST_EQ(int result, int expected_result, char* testname) { | 19 int TEST_EQ(int result, int expected_result, char* testname) { |
25 if (result == expected_result) { | 20 if (result == expected_result) { |
26 fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname); | 21 fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname); |
27 return 1; | 22 return 1; |
28 } | 23 } |
29 else { | 24 else { |
30 fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname); | 25 fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname); |
31 gTestSuccess = 0; | 26 gTestSuccess = 0; |
32 return 0; | 27 return 0; |
33 } | 28 } |
34 } | 29 } |
35 | 30 |
36 int TEST_NEQ(int result, int not_expected_result, char* testname) { | 31 int TEST_NEQ(int result, int not_expected_result, char* testname) { |
37 if (result != not_expected_result) { | 32 if (result != not_expected_result) { |
38 fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname); | 33 fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname); |
39 return 1; | 34 return 1; |
40 } | 35 } |
41 else { | 36 else { |
42 fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname); | 37 fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname); |
43 gTestSuccess = 0; | 38 gTestSuccess = 0; |
44 return 0; | 39 return 0; |
45 } | 40 } |
46 } | 41 } |
OLD | NEW |