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
|
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Common functions used by tests.
*/
#include "test_common.h"
#include <stdio.h>
#include "cryptolib.h"
#include "file_keys.h"
#include "utility.h"
/* Global test success flag. */
int gTestSuccess = 1;
int TEST_EQ(int result, int expected_result, char* testname) {
if (result == expected_result) {
fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname);
return 1;
}
else {
fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname);
fprintf(stderr, " Expected: %d, got: %d\n", expected_result, result);
gTestSuccess = 0;
return 0;
}
}
int TEST_NEQ(int result, int not_expected_result, char* testname) {
if (result != not_expected_result) {
fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname);
return 1;
}
else {
fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname);
fprintf(stderr, " Didn't expect %d, but got it.\n", not_expected_result);
gTestSuccess = 0;
return 0;
}
}
int TEST_PTR_EQ(const void* result, const void* expected_result,
char* testname) {
if (result == expected_result) {
fprintf(stderr, "%s Test " COL_GREEN "PASSED\n" COL_STOP, testname);
return 1;
}
else {
fprintf(stderr, "%s Test " COL_RED "FAILED\n" COL_STOP, testname);
fprintf(stderr, " Expected: 0x%lx, got: 0x%lx\n", (long)expected_result,
(long)result);
gTestSuccess = 0;
return 0;
}
}
|