/* NOLINTNEXTLINE(llvm-header-guard) */ #ifndef AWS_COMMON_LOGGING_TEST_UTILITIES_H #define AWS_COMMON_LOGGING_TEST_UTILITIES_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include #include /** * A staging function for basic logging tests. It * (1) Initializes and globally attaches a test logger * (2) Invokes the supplied callback, which should perform the logging operations under test * (3) Detaches and cleans up the test logger * (4) Checks if what was recorded by the test logger matches what the test expected. */ int do_log_test( struct aws_allocator *allocator, enum aws_log_level level, const char *expected_result, void (*callback)(enum aws_log_level)); /** * A macro capable of defining simple logging tests that follow the do_log_test function pattern */ #define TEST_LEVEL_FILTER(log_level, expected, action_fn) \ static int s_logging_filter_at_##log_level##_##action_fn(struct aws_allocator *allocator, void *ctx) { \ (void)ctx; \ return do_log_test(allocator, log_level, expected, action_fn); \ } \ AWS_TEST_CASE(test_logging_filter_at_##log_level##_##action_fn, s_logging_filter_at_##log_level##_##action_fn); /** * A macro that defines a function that invokes all 6 LOGF_ variants * * Needs to be a macro and not just a function because the compile-time filtering tests require a private implementation * that is compiled with AWS_STATIC_LOG_LEVEL at the level to be tested. There's no way to shared a single definition * that does so. */ #define DECLARE_LOGF_ALL_LEVELS_FUNCTION(fn_name) \ static void fn_name(enum aws_log_level level) { \ (void)level; \ AWS_LOGF_FATAL(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_FATAL); \ AWS_LOGF_ERROR(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_ERROR); \ AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_WARN); \ AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_INFO); \ AWS_LOGF_DEBUG(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_DEBUG); \ AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_TRACE); \ } /** * Return new string with format "./aws_log_writer_test_{UUID}.log" * This function cannot fail. */ struct aws_string *aws_string_new_log_writer_test_filename(struct aws_allocator *allocator); #endif /* AWS_COMMON_LOGGING_TEST_UTILITIES_H */