File: log_api_test.cc

package info (click to toggle)
pistache 0.0.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,420 kB
  • sloc: cpp: 19,169; ansic: 556; sh: 86; makefile: 15
file content (45 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (3)
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
/*
 * SPDX-FileCopyrightText: 2020 Michael Ellison
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <utility>
#include <vector>

#include <pistache/log.h>

#include <gtest/gtest.h>

using namespace Pistache;

// Test that the PISTACHE_LOG_STRING_* macros guard against accessing a null logger.
TEST(logger_test, macros_guard_null_logger)
{
    PISTACHE_STRING_LOGGER_T logger = PISTACHE_NULL_STRING_LOGGER;

    PISTACHE_LOG_STRING_FATAL(logger, "test_message_1_fatal");
    PISTACHE_LOG_STRING_ERROR(logger, "test_message_2_error");
    PISTACHE_LOG_STRING_WARN(logger, "test_message_3_warn");
    PISTACHE_LOG_STRING_INFO(logger, "test_message_4_info");
    PISTACHE_LOG_STRING_DEBUG(logger, "test_message_5_debug");
    PISTACHE_LOG_STRING_TRACE(logger, "test_message_6_trace");

    // Expect no death from accessing the null logger.
}

// Test that the PISTACHE_LOG_STRING_* macros access a default logger.
TEST(logger_test, macros_access_default_logger)
{
    PISTACHE_STRING_LOGGER_T logger = PISTACHE_DEFAULT_STRING_LOGGER;

    PISTACHE_LOG_STRING_FATAL(logger, "test_message_1_fatal");
    PISTACHE_LOG_STRING_ERROR(logger, "test_message_2_error");
    PISTACHE_LOG_STRING_WARN(logger, "test_message_3_warn");
    PISTACHE_LOG_STRING_INFO(logger, "test_message_4_info");
    PISTACHE_LOG_STRING_DEBUG(logger, "test_message_5_debug");
    PISTACHE_LOG_STRING_TRACE(logger, "test_message_6_trace");

    // Expect no death from using the default handler. The only output of the
    // default logger is to stdout, so output cannot be confirmed by gtest.
}