1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include "logging_test_utilities.h"
#include "test_logger.h"
#include <aws/common/string.h>
#include <aws/common/uuid.h>
#define TEST_LOGGER_MAX_BUFFER_SIZE 4096
int do_log_test(
struct aws_allocator *allocator,
enum aws_log_level level,
const char *expected_result,
void (*callback)(enum aws_log_level)) {
/* Create and attach a logger for testing*/
struct aws_logger test_logger;
test_logger_init(&test_logger, allocator, level, TEST_LOGGER_MAX_BUFFER_SIZE);
aws_logger_set(&test_logger);
/* Perform logging operations */
(*callback)(level);
/* Pull out what was logged before clean up */
char buffer[TEST_LOGGER_MAX_BUFFER_SIZE];
test_logger_get_contents(&test_logger, buffer, TEST_LOGGER_MAX_BUFFER_SIZE);
/* clean up */
aws_logger_set(NULL);
aws_logger_clean_up(&test_logger);
/* Check the test results last */
ASSERT_SUCCESS(strcmp(buffer, expected_result), "Expected \"%s\" but received \"%s\"", expected_result, buffer);
return AWS_OP_SUCCESS;
}
struct aws_string *aws_string_new_log_writer_test_filename(struct aws_allocator *allocator) {
char filename_array[64];
AWS_ZERO_ARRAY(filename_array);
struct aws_byte_buf filename_buf = aws_byte_buf_from_empty_array(filename_array, sizeof(filename_array));
#ifndef _WIN32
AWS_FATAL_ASSERT(aws_byte_buf_write_from_whole_cursor(&filename_buf, aws_byte_cursor_from_c_str("./")));
#endif
AWS_FATAL_ASSERT(
aws_byte_buf_write_from_whole_cursor(&filename_buf, aws_byte_cursor_from_c_str("aws_log_writer_test_")));
struct aws_uuid uuid;
AWS_FATAL_ASSERT(aws_uuid_init(&uuid) == AWS_OP_SUCCESS);
AWS_FATAL_ASSERT(aws_uuid_to_str(&uuid, &filename_buf) == AWS_OP_SUCCESS);
AWS_FATAL_ASSERT(aws_byte_buf_write_from_whole_cursor(&filename_buf, aws_byte_cursor_from_c_str(".log")));
return aws_string_new_from_array(allocator, filename_buf.buffer, filename_buf.len);
}
|