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

Unit tests implementation for the dynamic_buffer_stream adapter. More...

Include dependency graph for unit_test_dynamic_buffer_stream.c:

Go to the source code of this file.

Enumerations

enum  dynamic_buffer_stream_create_stream_scenario_t {
  DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OK = 0 , DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OUT_NULL , DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_CFG_NULL , DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_ENV_NULL ,
  DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OOM
}
 Scenarios for dynamic_buffer_stream_create_stream(). More...
 
enum  dynamic_buffer_stream_create_desc_scenario_t {
  DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OK = 0 , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OUT_NULL , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_KEY_NULL , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_KEY_EMPTY ,
  DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_CFG_NULL , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_ENV_NULL , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_MEM_NULL , DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OOM
}
 Scenarios for dynamic_buffer_stream_create_desc(). More...
 
enum  dynamic_buffer_stream_write_scenario_t {
  DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_OK_NO_GROW = 0 , DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_ZERO_LEN , DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_BUF_NULL_ZERO_LEN , DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_OK_GROW ,
  DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_BUF_NULL_NONZERO , DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_RESERVE_OOM , DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_SIZE_OVERFLOW
}
 Scenarios for dynamic_buffer_stream_write(). More...
 
enum  dynamic_buffer_stream_read_scenario_t {
  DYNAMIC_BUFFER_STREAM_READ_SCENARIO_OK_EXACT = 0 , DYNAMIC_BUFFER_STREAM_READ_SCENARIO_OK_CLAMP_TO_AVAILABLE , DYNAMIC_BUFFER_STREAM_READ_SCENARIO_ZERO_LEN , DYNAMIC_BUFFER_STREAM_READ_SCENARIO_BUF_NULL_ZERO_LEN ,
  DYNAMIC_BUFFER_STREAM_READ_SCENARIO_BUF_NULL_NONZERO , DYNAMIC_BUFFER_STREAM_READ_SCENARIO_EOF
}
 Scenarios for dynamic_buffer_stream_read(). More...
 

Functions

static void test_dynamic_buffer_stream_default_cfg (void **state)
 Test dynamic_buffer_stream_default_cfg().
 
static void test_dynamic_buffer_stream_default_env (void **state)
 Test dynamic_buffer_stream_default_env().
 
static void test_dynamic_buffer_stream_flush (void **state)
 Test dynamic_buffer_stream_flush().
 
static void test_dynamic_buffer_stream_close (void **state)
 Test dynamic_buffer_stream_close().
 

Detailed Description

This file implements unit-level validation of the dynamic_buffer_stream adapter contracts.

Covered surfaces:

Test strategy:

  • direct validation of default CR helper return values
  • parametric scenario-based testing where meaningful
  • explicit validation of argument checking and output-handle preservation
  • allocator fault injection through fake_memory
  • borrower-facing stream API checks on successfully created streams
  • adapter-specific runtime checks for buffer growth, read/write behavior, flush no-op behavior, and destruction/close behavior

See also:

Definition in file unit_test_dynamic_buffer_stream.c.

Enumeration Type Documentation

◆ dynamic_buffer_stream_create_desc_scenario_t

stream_status_t dynamic_buffer_stream_create_desc( stream_adapter_desc_t *out, stream_key_t key, const dynamic_buffer_stream_cfg_t *cfg, const dynamic_buffer_stream_env_t *env, const osal_mem_ops_t *mem );

Invalid arguments:

  • out, key, cfg, env, mem must not be NULL.
  • key must not be an empty string.

Success:

  • Returns STREAM_STATUS_OK.
  • Stores a valid adapter descriptor in *out.
  • The produced descriptor must later be released via out->ud_dtor().

Failure:

  • Returns:
    • STREAM_STATUS_INVALID for invalid arguments
    • STREAM_STATUS_OOM on allocation failure
  • If out is not NULL, resets *out to an empty descriptor.

Doubles:

  • fake_memory

See also:

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

Enumerator
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OK 

WHEN dynamic_buffer_stream_create_desc(out, key, cfg, env, mem) is called with valid arguments EXPECT:

  • returns STREAM_STATUS_OK
  • stores a valid adapter descriptor in *out
  • the produced descriptor is eligible for later destruction via out->ud_dtor()
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • no descriptor is produced
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_KEY_NULL 

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

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_KEY_EMPTY 

WHEN key is an empty string and out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_CFG_NULL 

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

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_ENV_NULL 

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

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_MEM_NULL 

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

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
DYNAMIC_BUFFER_STREAM_CREATE_DESC_SCENARIO_OOM 

WHEN allocation required by dynamic_buffer_stream_create_desc() fails EXPECT:

  • returns STREAM_STATUS_OOM
  • resets *out to an empty descriptor

Notes:

  • This scenario is exercised by configuring fake_memory to fail the allocation performed during descriptor construction.

Definition at line 495 of file unit_test_dynamic_buffer_stream.c.

◆ dynamic_buffer_stream_create_stream_scenario_t

stream_status_t dynamic_buffer_stream_create_stream( stream_t **out, const dynamic_buffer_stream_cfg_t *cfg, const dynamic_buffer_stream_env_t *env);

Doubles:

  • fake_memory

Isolation:

  • the public stream port wrapper is not doubled

See also:

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

Enumerator
DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OK 

WHEN dynamic_buffer_stream_create_stream(out, cfg, env) is called with valid arguments EXPECT:

  • returns STREAM_STATUS_OK
  • stores a non-NULL stream handle in *out
DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns STREAM_STATUS_INVALID
DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_CFG_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_ENV_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
DYNAMIC_BUFFER_STREAM_CREATE_STREAM_SCENARIO_OOM 

WHEN allocation required by dynamic_buffer_stream_create_stream() fails EXPECT:

  • returns STREAM_STATUS_OOM
  • leaves *out unchanged

Notes:

  • This scenario is exercised by configuring fake_memory to fail the allocation performed during stream creation.

Definition at line 149 of file unit_test_dynamic_buffer_stream.c.

◆ dynamic_buffer_stream_read_scenario_t

static size_t dynamic_buffer_stream_read( void *backend, void *buf, size_t n, stream_status_t *st );

This private callback is exercised through the public stream_read() API on streams created by dynamic_buffer_stream_create_stream().

Invalid arguments:

  • buf == NULL && n > 0

Success:

  • Returns the number of bytes read.
  • Copies read bytes from the backend buffer into buf.
  • Advances read_pos by the number of bytes returned.
  • Leaves len unchanged.
  • Sets *st to STREAM_STATUS_OK when st != NULL.

Failure:

  • Returns:
    • STREAM_STATUS_INVALID for invalid arguments
    • STREAM_STATUS_EOF when no unread byte remains
  • Leaves the backend unchanged on failure paths covered here.

Doubles:

  • none

Isolation:

  • the callback is not called directly
  • behavior is exercised through the public stream port wrapper

See also:

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

Enumerator
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_OK_EXACT 

WHEN stream_read(s, buf, n, &st) is called with valid arguments AND st != NULL AND 0 < n <= dbuf->len - dbuf->read_pos EXPECT:

  • returns n
  • *st == STREAM_STATUS_OK
  • exactly n bytes are copied from the backend buffer starting at dbuf->read_pos
  • dbuf->read_pos is advanced by n
  • dbuf->len is unchanged
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_OK_CLAMP_TO_AVAILABLE 

WHEN stream_read(s, buf, n, &st) is called with valid arguments AND st != NULL AND n > dbuf->len - dbuf->read_pos EXPECT:

  • returns dbuf->len - dbuf->read_pos
  • *st == STREAM_STATUS_OK
  • all unread bytes are copied from the backend buffer
  • dbuf->read_pos is advanced to dbuf->len
  • dbuf->len is unchanged
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_ZERO_LEN 

WHEN stream_read(s, buf, 0, &st) is called AND buf != NULL AND st != NULL EXPECT:

  • returns 0
  • *st == STREAM_STATUS_OK
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_BUF_NULL_ZERO_LEN 

WHEN stream_read(s, NULL, 0, &st) is called AND st != NULL EXPECT:

  • returns 0
  • *st == STREAM_STATUS_OK
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_BUF_NULL_NONZERO 

WHEN stream_read(s, NULL, n, &st) is called with n > 0 AND st != NULL EXPECT:

  • returns 0
  • *st == STREAM_STATUS_INVALID
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_READ_SCENARIO_EOF 

WHEN stream_read(s, buf, n, &st) is called with valid arguments AND st != NULL AND dbuf->read_pos >= dbuf->len EXPECT:

  • returns 0
  • *st == STREAM_STATUS_EOF
  • backend is left unchanged

Definition at line 1417 of file unit_test_dynamic_buffer_stream.c.

◆ dynamic_buffer_stream_write_scenario_t

static size_t dynamic_buffer_stream_write( void *backend, const void *buf, size_t n, stream_status_t *st );

This private callback is exercised through the public stream_write() API on streams created by dynamic_buffer_stream_create_stream().

Invalid arguments:

  • backend == NULL
  • buf == NULL && n > 0

Success:

  • Returns the number of bytes written.
  • Appends written bytes to the end of the dynamic buffer.
  • Leaves read_pos unchanged.
  • Sets *st to STREAM_STATUS_OK when st != NULL.

Failure:

  • Returns:
    • STREAM_STATUS_INVALID for invalid arguments
    • STREAM_STATUS_OOM on growth / reserve failure
  • Leaves the backend unchanged on failure paths covered here.

Doubles:

  • fake_memory

Isolation:

  • the callback is not called directly
  • behavior is exercised through the public stream port wrapper

See also:

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

Enumerator
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_OK_NO_GROW 

WHEN stream_write(s, buf, n, &st) is called with valid arguments AND st != NULL AND enough existing capacity EXPECT:

  • returns n
  • st == STREAM_STATUS_OK
  • bytes are appended to the backend buffer
  • read_pos is unchanged
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_ZERO_LEN 

WHEN stream_write(s, buf, 0, &st) is called AND buf != NULL AND st != NULL EXPECT:

  • returns 0
  • *st == STREAM_STATUS_OK
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_BUF_NULL_ZERO_LEN 

WHEN stream_write(s, NULL, 0, &st) is called AND st != NULL EXPECT:

  • returns 0
  • *st == STREAM_STATUS_OK
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_OK_GROW 

WHEN stream_write(s, buf, n, &st) is called with valid arguments AND st != NULL AND buffer growth is required EXPECT:

  • returns n
  • st == STREAM_STATUS_OK
  • bytes are appended to the backend buffer
  • read_pos is unchanged
  • cap grows to accommodate the requested write
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_BUF_NULL_NONZERO 

WHEN stream_write(s, NULL, n, &st) is called with n > 0 AND st != NULL EXPECT:

  • returns 0
  • st == STREAM_STATUS_INVALID
  • backend is left unchanged
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_RESERVE_OOM 

WHEN stream_write(s, buf, n, &st) is called with valid arguments AND st != NULL AND allocation required by reserve during write fails EXPECT:

  • returns 0
  • st == STREAM_STATUS_OOM
  • backend is left unchanged

Notes:

  • This scenario is exercised by configuring fake_memory to fail the allocation performed during growth / reserve.
DYNAMIC_BUFFER_STREAM_WRITE_SCENARIO_SIZE_OVERFLOW 

WHEN stream_write(s, buf, n, &st) is called with valid arguments AND st != NULL AND the requested growth is invalid because n > SIZE_MAX - dbuf->len EXPECT:

  • returns 0
  • st == STREAM_STATUS_INVALID
  • backend is left unchanged

Notes:

  • This scenario requires direct fixture seeding of backend internals.
  • It is still executed through the public stream_write() wrapper.

Definition at line 899 of file unit_test_dynamic_buffer_stream.c.

Function Documentation

◆ test_dynamic_buffer_stream_close()

static void test_dynamic_buffer_stream_close ( void **  state)
static

static void dynamic_buffer_stream_close(void *backend);

Success:

  • backend-owned resources are released during stream_destroy()
  • the public stream handle is destroyed and set to NULL

Failure:

  • None.

Doubles:

  • fake_memory

See also:

Definition at line 1946 of file unit_test_dynamic_buffer_stream.c.

◆ test_dynamic_buffer_stream_default_cfg()

static void test_dynamic_buffer_stream_default_cfg ( void **  state)
static

◆ test_dynamic_buffer_stream_default_env()

static void test_dynamic_buffer_stream_default_env ( void **  state)
static

◆ test_dynamic_buffer_stream_flush()

static void test_dynamic_buffer_stream_flush ( void **  state)
static

static stream_status_t dynamic_buffer_stream_flush(void *backend);

Success:

  • returns STREAM_STATUS_OK
  • leaves the backend unchanged

Failure:

  • None.

Doubles:

  • none

See also:

Definition at line 1868 of file unit_test_dynamic_buffer_stream.c.