|
| 1 | +/* |
| 2 | + * Copyright 2020 New Relic Corporation. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | +#include "tlib_php.h" |
| 6 | +#include "tlib_main.h" |
| 7 | + |
| 8 | +#include "php_agent.h" |
| 9 | +#include "php_call.h" |
| 10 | +#include "php_globals.h" |
| 11 | +#include "php_error.h" |
| 12 | + |
| 13 | +tlib_parallel_info_t parallel_info |
| 14 | + = {.suggested_nthreads = -1, .state_size = 0}; |
| 15 | + |
| 16 | +static void test_error_get_priority() { |
| 17 | + /* |
| 18 | + * Test : Unknown type. |
| 19 | + */ |
| 20 | + tlib_pass_if_int_equal("Unknown error type", 20, |
| 21 | + nr_php_error_get_priority(-1)); |
| 22 | + tlib_pass_if_int_equal("Unknown error type", 20, |
| 23 | + nr_php_error_get_priority(3)); |
| 24 | + |
| 25 | + /* |
| 26 | + * Test : Normal operation. |
| 27 | + */ |
| 28 | + |
| 29 | + tlib_pass_if_int_equal("Known error type", 0, |
| 30 | + nr_php_error_get_priority(E_NOTICE)); |
| 31 | + tlib_pass_if_int_equal("Known error type", 0, |
| 32 | + nr_php_error_get_priority(E_USER_NOTICE)); |
| 33 | + tlib_pass_if_int_equal("Known error type", 10, |
| 34 | + nr_php_error_get_priority(E_STRICT)); |
| 35 | + tlib_pass_if_int_equal("Known error type", 30, |
| 36 | + nr_php_error_get_priority(E_USER_DEPRECATED)); |
| 37 | + tlib_pass_if_int_equal("Known error type", 30, |
| 38 | + nr_php_error_get_priority(E_DEPRECATED)); |
| 39 | + tlib_pass_if_int_equal("Known error type", 40, |
| 40 | + nr_php_error_get_priority(E_USER_WARNING)); |
| 41 | + tlib_pass_if_int_equal("Known error type", 40, |
| 42 | + nr_php_error_get_priority(E_WARNING)); |
| 43 | + tlib_pass_if_int_equal("Known error type", 40, |
| 44 | + nr_php_error_get_priority(E_CORE_WARNING)); |
| 45 | + tlib_pass_if_int_equal("Known error type", 40, |
| 46 | + nr_php_error_get_priority(E_COMPILE_WARNING)); |
| 47 | + tlib_pass_if_int_equal("Known error type", 50, |
| 48 | + nr_php_error_get_priority(E_RECOVERABLE_ERROR)); |
| 49 | + tlib_pass_if_int_equal("Known error type", 50, |
| 50 | + nr_php_error_get_priority(E_ERROR)); |
| 51 | + tlib_pass_if_int_equal("Known error type", 50, |
| 52 | + nr_php_error_get_priority(E_USER_ERROR)); |
| 53 | + tlib_pass_if_int_equal("Known error type", 50, |
| 54 | + nr_php_error_get_priority(E_CORE_ERROR)); |
| 55 | + tlib_pass_if_int_equal("Known error type", 50, |
| 56 | + nr_php_error_get_priority(E_COMPILE_ERROR)); |
| 57 | + tlib_pass_if_int_equal("Known error type", 50, |
| 58 | + nr_php_error_get_priority(E_PARSE)); |
| 59 | +} |
| 60 | + |
| 61 | +static void test_get_error_type_string() { |
| 62 | + /* |
| 63 | + * Test : Unknown type. |
| 64 | + */ |
| 65 | + tlib_pass_if_str_equal("Unknown error type", "Error", |
| 66 | + nr_php_error_get_type_string(-1)); |
| 67 | + tlib_pass_if_str_equal("Unknown error type", "Error", |
| 68 | + nr_php_error_get_type_string(3)); |
| 69 | + |
| 70 | + /* |
| 71 | + * Test : Normal operation. |
| 72 | + */ |
| 73 | + |
| 74 | + tlib_pass_if_str_equal("Known error type", "E_NOTICE", |
| 75 | + nr_php_error_get_type_string(E_NOTICE)); |
| 76 | + tlib_pass_if_str_equal("Known error type", "E_USER_NOTICE", |
| 77 | + nr_php_error_get_type_string(E_USER_NOTICE)); |
| 78 | + tlib_pass_if_str_equal("Known error type", "E_STRICT", |
| 79 | + nr_php_error_get_type_string(E_STRICT)); |
| 80 | + tlib_pass_if_str_equal("Known error type", "E_USER_NOTICE", |
| 81 | + nr_php_error_get_type_string(E_USER_NOTICE)); |
| 82 | + tlib_pass_if_str_equal("Known error type", "E_USER_DEPRECATED", |
| 83 | + nr_php_error_get_type_string(E_USER_DEPRECATED)); |
| 84 | + tlib_pass_if_str_equal("Known error type", "E_DEPRECATED", |
| 85 | + nr_php_error_get_type_string(E_DEPRECATED)); |
| 86 | + tlib_pass_if_str_equal("Known error type", "E_USER_WARNING", |
| 87 | + nr_php_error_get_type_string(E_USER_WARNING)); |
| 88 | + tlib_pass_if_str_equal("Known error type", "E_WARNING", |
| 89 | + nr_php_error_get_type_string(E_WARNING)); |
| 90 | + tlib_pass_if_str_equal("Known error type", "E_CORE_WARNING", |
| 91 | + nr_php_error_get_type_string(E_CORE_WARNING)); |
| 92 | + tlib_pass_if_str_equal("Known error type", "E_COMPILE_WARNING", |
| 93 | + nr_php_error_get_type_string(E_COMPILE_WARNING)); |
| 94 | + tlib_pass_if_str_equal("Known error type", "E_RECOVERABLE_ERROR", |
| 95 | + nr_php_error_get_type_string(E_RECOVERABLE_ERROR)); |
| 96 | + tlib_pass_if_str_equal("Known error type", "E_ERROR", |
| 97 | + nr_php_error_get_type_string(E_ERROR)); |
| 98 | + tlib_pass_if_str_equal("Known error type", "E_USER_ERROR", |
| 99 | + nr_php_error_get_type_string(E_USER_ERROR)); |
| 100 | + tlib_pass_if_str_equal("Known error type", "E_CORE_ERROR", |
| 101 | + nr_php_error_get_type_string(E_CORE_ERROR)); |
| 102 | + tlib_pass_if_str_equal("Known error type", "E_COMPILE_ERROR", |
| 103 | + nr_php_error_get_type_string(E_COMPILE_ERROR)); |
| 104 | + tlib_pass_if_str_equal("Known error type", "E_PARSE", |
| 105 | + nr_php_error_get_type_string(E_PARSE)); |
| 106 | +} |
| 107 | + |
| 108 | +void test_main(void* p NRUNUSED) { |
| 109 | + tlib_php_engine_create("" PTSRMLS_CC); |
| 110 | + |
| 111 | + test_error_get_priority(); |
| 112 | + test_get_error_type_string(); |
| 113 | + |
| 114 | + tlib_php_engine_destroy(TSRMLS_C); |
| 115 | +} |
0 commit comments