Convert err_test to C++.
Another easy one. Doesn't actually buy us much. Change-Id: I166ae08e61c69bedea4de0a74ddd4dfc4699577d Reviewed-on: https://boringssl-review.googlesource.com/4129 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
3db1ded2e7
commit
a1283f75f1
@ -44,7 +44,7 @@ add_library(
|
|||||||
add_executable(
|
add_executable(
|
||||||
err_test
|
err_test
|
||||||
|
|
||||||
err_test.c
|
err_test.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(err_test crypto)
|
target_link_libraries(err_test crypto)
|
||||||
|
@ -20,55 +20,52 @@
|
|||||||
#include <openssl/mem.h>
|
#include <openssl/mem.h>
|
||||||
|
|
||||||
|
|
||||||
static int test_overflow(void) {
|
static bool TestOverflow() {
|
||||||
unsigned i;
|
for (unsigned i = 0; i < ERR_NUM_ERRORS*2; i++) {
|
||||||
|
|
||||||
for (i = 0; i < ERR_NUM_ERRORS*2; i++) {
|
|
||||||
ERR_put_error(1, 2, i+1, "test", 1);
|
ERR_put_error(1, 2, i+1, "test", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ERR_NUM_ERRORS - 1; i++) {
|
for (unsigned i = 0; i < ERR_NUM_ERRORS - 1; i++) {
|
||||||
uint32_t err = ERR_get_error();
|
uint32_t err = ERR_get_error();
|
||||||
/* Errors are returned in order they were pushed, with the least recent ones
|
/* Errors are returned in order they were pushed, with the least recent ones
|
||||||
* removed, up to |ERR_NUM_ERRORS - 1| errors. So the errors returned are
|
* removed, up to |ERR_NUM_ERRORS - 1| errors. So the errors returned are
|
||||||
* |ERR_NUM_ERRORS + 2| through |ERR_NUM_ERRORS * 2|, inclusive. */
|
* |ERR_NUM_ERRORS + 2| through |ERR_NUM_ERRORS * 2|, inclusive. */
|
||||||
if (err == 0 || ERR_GET_REASON(err) != i + ERR_NUM_ERRORS + 2) {
|
if (err == 0 || ERR_GET_REASON(err) != i + ERR_NUM_ERRORS + 2) {
|
||||||
fprintf(stderr, "ERR_get_error failed at %u\n", i);
|
fprintf(stderr, "ERR_get_error failed at %u\n", i);
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ERR_get_error() != 0) {
|
if (ERR_get_error() != 0) {
|
||||||
fprintf(stderr, "ERR_get_error more than the expected number of values.\n");
|
fprintf(stderr, "ERR_get_error more than the expected number of values.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_put_error(void) {
|
static bool TestPutError() {
|
||||||
uint32_t peeked_packed_error, packed_error;
|
|
||||||
int peeked_line, line, peeked_flags, flags;
|
|
||||||
const char *peeked_file, *file, *peeked_data, *data;
|
|
||||||
|
|
||||||
if (ERR_get_error() != 0) {
|
if (ERR_get_error() != 0) {
|
||||||
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_put_error(1, 2, 3, "test", 4);
|
ERR_put_error(1, 2, 3, "test", 4);
|
||||||
ERR_add_error_data(1, "testing");
|
ERR_add_error_data(1, "testing");
|
||||||
|
|
||||||
peeked_packed_error = ERR_peek_error_line_data(&peeked_file, &peeked_line,
|
int peeked_line, line, peeked_flags, flags;
|
||||||
&peeked_data, &peeked_flags);
|
const char *peeked_file, *file, *peeked_data, *data;
|
||||||
packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
|
uint32_t peeked_packed_error =
|
||||||
|
ERR_peek_error_line_data(&peeked_file, &peeked_line, &peeked_data,
|
||||||
|
&peeked_flags);
|
||||||
|
uint32_t packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
|
||||||
|
|
||||||
if (peeked_packed_error != packed_error ||
|
if (peeked_packed_error != packed_error ||
|
||||||
peeked_file != file ||
|
peeked_file != file ||
|
||||||
peeked_data != data ||
|
peeked_data != data ||
|
||||||
peeked_flags != flags) {
|
peeked_flags != flags) {
|
||||||
fprintf(stderr, "Bad peeked error data returned.\n");
|
fprintf(stderr, "Bad peeked error data returned.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(file, "test") != 0 ||
|
if (strcmp(file, "test") != 0 ||
|
||||||
@ -79,16 +76,16 @@ static int test_put_error(void) {
|
|||||||
ERR_GET_REASON(packed_error) != 3 ||
|
ERR_GET_REASON(packed_error) != 3 ||
|
||||||
strcmp(data, "testing") != 0) {
|
strcmp(data, "testing") != 0) {
|
||||||
fprintf(stderr, "Bad error data returned.\n");
|
fprintf(stderr, "Bad error data returned.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_clear_error(void) {
|
static bool TestClearError() {
|
||||||
if (ERR_get_error() != 0) {
|
if (ERR_get_error() != 0) {
|
||||||
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_put_error(1, 2, 3, "test", 4);
|
ERR_put_error(1, 2, 3, "test", 4);
|
||||||
@ -96,42 +93,39 @@ static int test_clear_error(void) {
|
|||||||
|
|
||||||
if (ERR_get_error() != 0) {
|
if (ERR_get_error() != 0) {
|
||||||
fprintf(stderr, "Error remained after clearing.\n");
|
fprintf(stderr, "Error remained after clearing.\n");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_print(void) {
|
static bool TestPrint() {
|
||||||
size_t i;
|
|
||||||
char buf[256];
|
|
||||||
uint32_t packed_error;
|
|
||||||
|
|
||||||
ERR_put_error(1, 2, 3, "test", 4);
|
ERR_put_error(1, 2, 3, "test", 4);
|
||||||
ERR_add_error_data(1, "testing");
|
ERR_add_error_data(1, "testing");
|
||||||
packed_error = ERR_get_error();
|
uint32_t packed_error = ERR_get_error();
|
||||||
|
|
||||||
for (i = 0; i <= sizeof(buf); i++) {
|
char buf[256];
|
||||||
|
for (size_t i = 0; i <= sizeof(buf); i++) {
|
||||||
ERR_error_string_n(packed_error, buf, i);
|
ERR_error_string_n(packed_error, buf, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_release(void) {
|
static bool TestRelease() {
|
||||||
ERR_put_error(1, 2, 3, "test", 4);
|
ERR_put_error(1, 2, 3, "test", 4);
|
||||||
ERR_remove_thread_state(NULL);
|
ERR_remove_thread_state(NULL);
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main() {
|
||||||
CRYPTO_library_init();
|
CRYPTO_library_init();
|
||||||
|
|
||||||
if (!test_overflow() ||
|
if (!TestOverflow() ||
|
||||||
!test_put_error() ||
|
!TestPutError() ||
|
||||||
!test_clear_error() ||
|
!TestClearError() ||
|
||||||
!test_print() ||
|
!TestPrint() ||
|
||||||
!test_release()) {
|
!TestRelease()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user