summaryrefslogtreecommitdiffstats
path: root/src/crypto/err/err_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/err/err_test.cc')
-rw-r--r--src/crypto/err/err_test.cc46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/crypto/err/err_test.cc b/src/crypto/err/err_test.cc
index 98dfb85..d691355 100644
--- a/src/crypto/err/err_test.cc
+++ b/src/crypto/err/err_test.cc
@@ -22,7 +22,7 @@
static bool TestOverflow() {
for (unsigned i = 0; i < ERR_NUM_ERRORS*2; i++) {
- ERR_put_error(1, 2, i+1, "test", 1);
+ ERR_put_error(1, 0 /* unused */, i+1, "test", 1);
}
for (unsigned i = 0; i < ERR_NUM_ERRORS - 1; i++) {
@@ -30,7 +30,7 @@ static bool TestOverflow() {
/* 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
* |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 || ((unsigned)ERR_GET_REASON(err)) != i + ERR_NUM_ERRORS + 2) {
fprintf(stderr, "ERR_get_error failed at %u\n", i);
return false;
}
@@ -50,7 +50,7 @@ static bool TestPutError() {
return false;
}
- ERR_put_error(1, 2, 3, "test", 4);
+ ERR_put_error(1, 0 /* unused */, 2, "test", 4);
ERR_add_error_data(1, "testing");
int peeked_line, line, peeked_flags, flags;
@@ -72,8 +72,7 @@ static bool TestPutError() {
line != 4 ||
(flags & ERR_FLAG_STRING) == 0 ||
ERR_GET_LIB(packed_error) != 1 ||
- ERR_GET_FUNC(packed_error) != 2 ||
- ERR_GET_REASON(packed_error) != 3 ||
+ ERR_GET_REASON(packed_error) != 2 ||
strcmp(data, "testing") != 0) {
fprintf(stderr, "Bad error data returned.\n");
return false;
@@ -88,7 +87,7 @@ static bool TestClearError() {
return false;
}
- ERR_put_error(1, 2, 3, "test", 4);
+ ERR_put_error(1, 0 /* unused */, 2, "test", 4);
ERR_clear_error();
if (ERR_get_error() != 0) {
@@ -100,7 +99,7 @@ static bool TestClearError() {
}
static bool TestPrint() {
- ERR_put_error(1, 2, 3, "test", 4);
+ ERR_put_error(1, 0 /* unused */, 2, "test", 4);
ERR_add_error_data(1, "testing");
uint32_t packed_error = ERR_get_error();
@@ -113,11 +112,39 @@ static bool TestPrint() {
}
static bool TestRelease() {
- ERR_put_error(1, 2, 3, "test", 4);
+ ERR_put_error(1, 0 /* unused */, 2, "test", 4);
ERR_remove_thread_state(NULL);
return true;
}
+static bool HasSuffix(const char *str, const char *suffix) {
+ size_t suffix_len = strlen(suffix);
+ size_t str_len = strlen(str);
+ if (str_len < suffix_len) {
+ return false;
+ }
+ return strcmp(str + str_len - suffix_len, suffix) == 0;
+}
+
+static bool TestPutMacro() {
+ int expected_line = __LINE__ + 1;
+ OPENSSL_PUT_ERROR(USER, ERR_R_INTERNAL_ERROR);
+
+ int line;
+ const char *file;
+ uint32_t error = ERR_get_error_line(&file, &line);
+
+ if (!HasSuffix(file, "err_test.cc") ||
+ line != expected_line ||
+ ERR_GET_LIB(error) != ERR_LIB_USER ||
+ ERR_GET_REASON(error) != ERR_R_INTERNAL_ERROR) {
+ fprintf(stderr, "Bad error data returned.\n");
+ return false;
+ }
+
+ return true;
+}
+
int main() {
CRYPTO_library_init();
@@ -125,7 +152,8 @@ int main() {
!TestPutError() ||
!TestClearError() ||
!TestPrint() ||
- !TestRelease()) {
+ !TestRelease() ||
+ !TestPutMacro()) {
return 1;
}