### Function

# GLib test_expect_message

since: 2.34

#### Declaration [src]

    void
    g_test_expect_message (
      const gchar* log_domain,
      GLogLevelFlags log_level,
      const gchar* pattern
    )

#### Description [src]

Indicates that a message with the given `log_domain` and `log_level`, with text matching `pattern`, is expected to be logged.

When this message is logged, it will not be printed, and the test case will not abort.

This API may only be used with the old logging API (`g_log()` without `G_LOG_USE_STRUCTURED` defined). It will not work with the structured logging API. See Testing for Messages.

Use `g_test_assert_expected_messages()` to assert that all previously-expected messages have been seen and suppressed.

You can call this multiple times in a row, if multiple messages are expected as a result of a single call. (The messages must appear in the same order as the calls to `g_test_expect_message()`.)

For example:

    // g_main_context_push_thread_default() should fail if the
    // context is already owned by another thread.
    g_test_expect_message (G_LOG_DOMAIN,
                           G_LOG_LEVEL_CRITICAL,
                           "assertion*acquired_context*failed");
    g_main_context_push_thread_default (bad_context);
    g_test_assert_expected_messages ();

Note that you cannot use this to test `g_error()` messages, since `g_error()` intentionally never returns even if the program doesn’t abort; use `g_test_trap_subprocess()` in this case.

If messages at `G_LOG_LEVEL_DEBUG` are emitted, but not explicitly expected via `g_test_expect_message()` then they will be ignored.

Available since: 2.34

#### Parameters

`log_domain`

  Type: `const gchar*`

  The log domain of the message.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`log_level`

  Type: `GLogLevelFlags`

  The log level of the message.

`pattern`

  Type: `const gchar*`

  A glob-style pattern (see `GPatternSpec`).

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.