Debian Codegraph @

crt/aws-c-common/tests/logging/logging_test_utilities.h

raw symbols SCIP
1 /* NOLINTNEXTLINE(llvm-header-guard) */
2 #ifndef AWS_COMMON_LOGGING_TEST_UTILITIES_H
3 #define AWS_COMMON_LOGGING_TEST_UTILITIES_H
4
5 /**
6 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7 * SPDX-License-Identifier: Apache-2.0.
8 */
9
10 #include <aws/common/logging.h>
11
12 #include <aws/testing/aws_test_harness.h>
13
14 /**
15 * A staging function for basic logging tests. It
16 * (1) Initializes and globally attaches a test logger
17 * (2) Invokes the supplied callback, which should perform the logging operations under test
18 * (3) Detaches and cleans up the test logger
19 * (4) Checks if what was recorded by the test logger matches what the test expected.
20 */
21 int do_log_test(
22 struct aws_allocator *allocator,
23 enum aws_log_level level,
24 const char *expected_result,
25 void (*callback)(enum aws_log_level));
26
27 /**
28 * A macro capable of defining simple logging tests that follow the do_log_test function pattern
29 */
30 #define TEST_LEVEL_FILTER(log_level, expected, action_fn) \
31 static int s_logging_filter_at_##log_level##_##action_fn(struct aws_allocator *allocator, void *ctx) { \
32 (void)ctx; \
33 return do_log_test(allocator, log_level, expected, action_fn); \
34 } \
35 AWS_TEST_CASE(test_logging_filter_at_##log_level##_##action_fn, s_logging_filter_at_##log_level##_##action_fn);
36
37 /**
38 * A macro that defines a function that invokes all 6 LOGF_<level> variants
39 *
40 * Needs to be a macro and not just a function because the compile-time filtering tests require a private implementation
41 * that is compiled with AWS_STATIC_LOG_LEVEL at the level to be tested. There's no way to shared a single definition
42 * that does so.
43 */
44 #define DECLARE_LOGF_ALL_LEVELS_FUNCTION(fn_name) \
45 static void fn_name(enum aws_log_level level) { \
46 (void)level; \
47 AWS_LOGF_FATAL(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_FATAL); \
48 AWS_LOGF_ERROR(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_ERROR); \
49 AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_WARN); \
50 AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_INFO); \
51 AWS_LOGF_DEBUG(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_DEBUG); \
52 AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_TRACE); \
53 }
54
55 /**
56 * Return new string with format "./aws_log_writer_test_{UUID}.log"
57 * This function cannot fail.
58 */
59 struct aws_string *aws_string_new_log_writer_test_filename(struct aws_allocator *allocator);
60
61 #endif /* AWS_COMMON_LOGGING_TEST_UTILITIES_H */