LexLeo 0.0.0-dev+f8e5087-dirty
Technical documentation
Loading...
Searching...
No Matches
logger unit tests

It covers:


logger_default_env() unit tests

See logger_default_env() specifications

Functions under test

logger_env_t logger_default_env(const osal_mem_ops_t *mem_ops)
Build a default logger_env_t from injected memory operations.
Definition logger.c:22
Runtime environment for the logger port.
Definition logger_env.h:34

Success

  • env.mem == mem_ops.

Failure

  • None.

Test doubles

Tested scenarios

WHEN EXPECT
logger_default_env(mem_ops) is called with a valid mem_ops pointer returns a logger_env_t such that env.mem == mem_ops

Notes

  • This helper preserves the allocator dependency provided by the caller.

logger_create() / logger_destroy() unit tests

See:

Functions under test

logger_t **out,
const logger_vtbl_t *vtbl,
void *backend,
const logger_env_t *env);
logger_status_t logger_create(logger_t **out, const logger_vtbl_t *vtbl, void *backend, const logger_env_t *env)
Create a generic logger handle from adapter-provided backend bindings.
Definition logger.c:27
void logger_destroy(logger_t **l)
Destroy a logger handle.
Definition logger.c:57
logger_status_t
Private handle structure for a logger_t.
Adapter dispatch table bound to a logger_t instance.

Invalid arguments

  • out, vtbl, env must not be NULL.
  • backend must not be NULL.
  • vtbl->log, vtbl->destroy must not be NULL.
  • env->mem must not be NULL.

Success

  • Returns LOGGER_STATUS_OK.
  • Stores a valid logger handle in *out.
  • The produced handle must be destroyed via logger_destroy().

Failure

  • Returns:
    • LOGGER_STATUS_INVALID for invalid arguments
    • LOGGER_STATUS_OOM on allocation failure
  • Leaves *out unchanged if out is not NULL.

Lifecycle

  • logger_destroy() does nothing if l == NULL or *l == NULL.
  • Otherwise, it releases the logger object and sets *l to NULL.

Test doubles

  • fake_memory

Tested scenarios

WHEN EXPECT
logger_create(out, vtbl, backend, env) is called with valid arguments returns LOGGER_STATUS_OK;
stores a non-NULL logger handle in *out;
the produced handle is eligible for destruction by logger_destroy()
out == NULL returns LOGGER_STATUS_INVALID;
no logger handle is produced
vtbl == NULL and out != NULL returns LOGGER_STATUS_INVALID;
leaves *out unchanged
vtbl != NULL but vtbl->destroy == NULL and out != NULL returns LOGGER_STATUS_INVALID;
leaves *out unchanged
backend == NULL and out != NULL returns LOGGER_STATUS_INVALID;
leaves *out unchanged
env == NULL and out != NULL returns LOGGER_STATUS_INVALID;
leaves *out unchanged
env != NULL but env->mem == NULL and out != NULL returns LOGGER_STATUS_INVALID;
leaves *out unchanged
allocation of the logger handle fails returns LOGGER_STATUS_OOM;
leaves *out unchanged
logger_create() succeeds and logger_destroy() is called twice first logger_destroy(&l) releases the handle and sets l to NULL;
second logger_destroy(&l) is a no-op and keeps l as NULL

Notes

  • These tests validate the public lifecycle contract of the logger port.
  • The invalid-argument and OOM scenarios verify the output-handle preservation guarantee.
  • The idempotent destruction scenario validates the best-effort no-op behavior of logger_destroy() when called on an already-destroyed handle.

logger_log() unit tests

See:

Functions under test

logger_status_t logger_log(logger_t *l, const char *message);
logger_status_t logger_log(logger_t *l, const char *message)
Emit a log message through a logger.
Definition logger.c:77

Precondition

  • If l != NULL, l has been created by logger_create() with fake_logger_vtbl and fake_logger_backend_t.

Invalid arguments

  • l must not be NULL.
  • message must not be NULL.

Success

  • Delegates the log operation to the adapter-facing log callback stored in the logger handle.
  • Returns the value produced by the underlying log callback.

Failure

  • If l == NULL, returns LOGGER_STATUS_INVALID.
  • If message == NULL, returns LOGGER_STATUS_INVALID.

Test doubles

  • fake_logger_backend_t
  • fake_logger_vtbl

Tested scenarios

WHEN EXPECT
l == NULL and message != NULL returns LOGGER_STATUS_INVALID
l != NULL and message == NULL returns LOGGER_STATUS_INVALID
l != NULL and message != NULL and fake_logger_backend.log_ret == LOGGER_STATUS_IO_ERROR calls fake_logger_vtbl.log(fake_logger_backend, message) exactly once;
does not call fake_logger_vtbl.destroy;
returns LOGGER_STATUS_IO_ERROR

Notes

  • These tests validate the borrower-facing runtime contract of the logger port.
  • The forwarding scenario verifies that logger_log() delegates to the bound adapter callback and propagates its returned status unchanged.