LexLeo 0.0.0-dev+f8e5087-dirty
Technical documentation
Loading...
Searching...
No Matches
unit_test_logger.c File Reference

Unit tests implementation for the logger port. More...

Include dependency graph for unit_test_logger.c:

Go to the source code of this file.

Enumerations

enum  logger_lifecycle_scenario_t {
  LOGGER_LIFECYCLE_SCENARIO_OK = 0 , LOGGER_LIFECYCLE_SCENARIO_OUT_NULL , LOGGER_LIFECYCLE_SCENARIO_VTBL_NULL , LOGGER_LIFECYCLE_SCENARIO_VTBL_LOG_NULL ,
  LOGGER_LIFECYCLE_SCENARIO_VTBL_DESTROY_NULL , LOGGER_LIFECYCLE_SCENARIO_BACKEND_NULL , LOGGER_LIFECYCLE_SCENARIO_ENV_NULL , LOGGER_LIFECYCLE_SCENARIO_ENV_MEM_NULL ,
  LOGGER_LIFECYCLE_SCENARIO_OOM , LOGGER_LIFECYCLE_SCENARIO_DESTROY_IDEMPOTENT
}
 Scenarios for logger_create() / logger_destroy(). More...
 
enum  logger_log_scenario_t { LOGGER_LOG_SCENARIO_L_NULL , LOGGER_LOG_SCENARIO_MESSAGE_NULL , LOGGER_LOG_SCENARIO_FORWARD_IO_ERROR_OK }
 Scenarios for logger_log(). More...
 

Functions

static void test_logger_default_env (void **state)
 Test logger_default_env().
 

Detailed Description

This file implements the unit-level validation of the logger port contracts.

Covered surfaces:

See also:

Definition in file unit_test_logger.c.

Enumeration Type Documentation

◆ logger_lifecycle_scenario_t

logger_status_t logger_create( logger_t **out, const logger_vtbl_t *vtbl, void *backend, const logger_env_t *env );

void logger_destroy(logger_t **l);

Invalid arguments:

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

Success:

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 is NULL or *l is NULL.
  • Otherwise, it releases the logger_t object and sets *l to NULL.

Doubles:

  • fake_memory

See also:

The scenarios below define the test oracle for logger_create() and logger_destroy().

Enumerator
LOGGER_LIFECYCLE_SCENARIO_OK 

WHEN logger_create(out, vtbl, backend, env) is called with valid arguments EXPECT:

  • returns LOGGER_STATUS_OK
  • stores a non-NULL logger handle in *out
  • the produced handle is eligible for destruction by logger_destroy()
LOGGER_LIFECYCLE_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • no logger handle is produced
LOGGER_LIFECYCLE_SCENARIO_VTBL_NULL 

WHEN vtbl == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged
LOGGER_LIFECYCLE_SCENARIO_VTBL_LOG_NULL 

WHEN vtbl != NULL but vtbl->log == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged

Notes:

  • The logger port requires a well-formed vtbl at creation time.
LOGGER_LIFECYCLE_SCENARIO_VTBL_DESTROY_NULL 

WHEN vtbl != NULL but vtbl->destroy == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged

Notes:

  • The logger port requires a well-formed vtbl at creation time.
LOGGER_LIFECYCLE_SCENARIO_BACKEND_NULL 

WHEN backend == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged
LOGGER_LIFECYCLE_SCENARIO_ENV_NULL 

WHEN env == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged
LOGGER_LIFECYCLE_SCENARIO_ENV_MEM_NULL 

WHEN env != NULL but env->mem == NULL and out != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
  • leaves *out unchanged
LOGGER_LIFECYCLE_SCENARIO_OOM 

WHEN allocation of the logger handle fails (allocator reports OOM) EXPECT:

  • returns LOGGER_STATUS_OOM
  • leaves *out unchanged

Notes:

  • This scenario is exercised by configuring fake_memory to fail the allocation performed by logger_create().
LOGGER_LIFECYCLE_SCENARIO_DESTROY_IDEMPOTENT 

WHEN logger_create() succeeds and logger_destroy() is called twice EXPECT:

  • 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:

Definition at line 163 of file unit_test_logger.c.

◆ logger_log_scenario_t

logger_status_t logger_log(logger_t *l, const char *message);

Precondition:

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

Doubles:

  • fake_logger_backend_t
  • fake_logger_vtbl

See also:

The scenarios below define the test oracle for logger_log().

Enumerator
LOGGER_LOG_SCENARIO_L_NULL 

WHEN l == NULL and message != NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
LOGGER_LOG_SCENARIO_MESSAGE_NULL 

WHEN l != NULL and message == NULL EXPECT:

  • returns LOGGER_STATUS_INVALID
LOGGER_LOG_SCENARIO_FORWARD_IO_ERROR_OK 

WHEN l != NULL and message != NULL AND fake_logger_backend is configured as:

  • log_ret = LOGGER_STATUS_IO_ERROR EXPECT:

calls fake_logger_vtbl.log(fake_logger_backend, message) exactly once

  • does not call fake_logger_vtbl.destroy
  • returns LOGGER_STATUS_IO_ERROR

Definition at line 600 of file unit_test_logger.c.

Function Documentation

◆ test_logger_default_env()

static void test_logger_default_env ( void **  state)
static