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

It covers:


dynamic_buffer_stream_default_cfg() unit tests

See dynamic_buffer_stream_default_cfg() specifications

Functions under test

dynamic_buffer_stream_cfg_t dynamic_buffer_stream_default_cfg(void)
Return the default configuration for the dynamic_buffer_stream adapter.
Configuration type for the dynamic_buffer_stream adapter.

Test doubles

  • none

Tested scenarios

WHEN EXPECT
dynamic_buffer_stream_default_cfg() is called returns a dynamic_buffer_stream_cfg_t such that ret.default_cap > 0

Notes

  • This helper establishes the default configuration invariant for the dynamic_buffer_stream adapter.
  • The exact value of default_cap is not part of the public contract; only its validity (non-zero) is guaranteed.

dynamic_buffer_stream_default_env() unit tests

See dynamic_buffer_stream_default_env() specifications

Functions under test

const osal_mem_ops_t *mem,
const stream_env_t *port_env);
dynamic_buffer_stream_env_t dynamic_buffer_stream_default_env(const osal_mem_ops_t *mem, const stream_env_t *port_env)
Return the default injected environment for the dynamic_buffer_stream adapter.
Injected dependencies for the dynamic_buffer_stream adapter.
Runtime environment for the stream port.
Definition stream_env.h:35

Success

  • ret.mem == mem
  • ret.port_env == *port_env

Failure

  • None

Test doubles

Tested scenarios

WHEN EXPECT
dynamic_buffer_stream_default_env(mem, port_env) is called with valid inputs returns a dynamic_buffer_stream_env_t such that ret.mem == mem and ret.port_env == *port_env

Notes

  • This helper preserves the injected memory dependency and the forwarded stream port environment provided by the caller.

dynamic_buffer_stream_create_stream() unit tests

See dynamic_buffer_stream_create_stream() specifications

Functions under test

stream_t **out,
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)
Create a dynamic_buffer_stream instance directly.
stream_status_t
Public status codes used by the stream port.
Private handle structure for a stream_t.

Test doubles

  • fake memory allocator (fake_memory)

Tested scenarios

WHEN EXPECT
valid inputs returns STREAM_STATUS_OK, stores a non-NULL stream in *out
out == NULL returns STREAM_STATUS_INVALID
cfg == NULL returns STREAM_STATUS_INVALID, *out unchanged
env == NULL returns STREAM_STATUS_INVALID, *out unchanged
allocation fails returns STREAM_STATUS_OOM, *out unchanged

Notes

  • Output pointer preservation is explicitly verified using sentinel values.
  • Successful creation is followed by basic borrower API checks (write, flush).

dynamic_buffer_stream_create_desc() unit tests

See dynamic_buffer_stream_create_desc() specifications

Functions under test

const osal_mem_ops_t *mem);
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)
Build a stream adapter descriptor for the dynamic_buffer_stream adapter.
const char * stream_key_t
Public identifier type for a registered stream adapter.
Public descriptor used to register a concrete stream adapter.

Test doubles

  • fake memory allocator (fake_memory)

Tested scenarios

WHEN EXPECT
valid inputs returns STREAM_STATUS_OK, produces a valid descriptor
out == NULL returns STREAM_STATUS_INVALID
key == NULL returns STREAM_STATUS_INVALID, resets descriptor
key == "" returns STREAM_STATUS_INVALID, resets descriptor
cfg == NULL returns STREAM_STATUS_INVALID, resets descriptor
env == NULL returns STREAM_STATUS_INVALID, resets descriptor
mem == NULL returns STREAM_STATUS_INVALID, resets descriptor
allocation fails returns STREAM_STATUS_OOM, resets descriptor

Notes

  • Descriptor validity includes:
    • non-empty key
    • non-NULL constructor
    • non-NULL user data and destructor
  • Descriptor reset semantics are enforced on failure.

dynamic_buffer_stream_write() unit tests

See:

Functions under test

size_t stream_write(stream_t *s, const void *buf, size_t n, stream_status_t *st);
size_t stream_write(stream_t *s, const void *buf, size_t n, stream_status_t *st)
Write bytes to a stream.
Definition stream.c:38

Tested scenarios

WHEN EXPECT
valid write without growth writes n, appends data, read_pos unchanged
valid write with growth writes n, buffer grows
n == 0 returns 0, no change
buf == NULL && n == 0 returns 0, no change
buf == NULL && n > 0 returns 0, STREAM_STATUS_INVALID
reserve fails returns 0, STREAM_STATUS_OOM, no change
size overflow returns 0, STREAM_STATUS_INVALID, no change

Notes

  • Backend invariants are validated before and after the call.
  • Failure paths ensure strict non-mutation of backend state.

dynamic_buffer_stream_read() unit tests

See:

Functions under test

size_t stream_read(stream_t *s, void *buf, size_t n, stream_status_t *st);
size_t stream_read(stream_t *s, void *buf, size_t n, stream_status_t *st)
Read bytes from a stream.
Definition stream.c:19

Tested scenarios

WHEN EXPECT
read within available data returns n, advances read_pos
read beyond available data returns remaining bytes
n == 0 returns 0, no change
buf == NULL && n == 0 returns 0, no change
buf == NULL && n > 0 returns 0, STREAM_STATUS_INVALID
EOF returns 0, STREAM_STATUS_EOF, no change

Notes

  • Read operations never modify len or buffer content.
  • Only read_pos is advanced on success.

dynamic_buffer_stream_flush() unit tests

See dynamic_buffer_stream_flush() specifications

Functions under test

stream_status_t stream_flush(stream_t *s)
Flush a stream.
Definition stream.c:62

Tested scenarios

WHEN EXPECT
flush is called returns STREAM_STATUS_OK, backend unchanged

Notes

  • This adapter implements flush as a no-op.

dynamic_buffer_stream_close() unit tests

See:

Functions under test

void stream_destroy(stream_t **s)
Destroy a stream handle.
Definition stream.c:98

Tested scenarios

WHEN EXPECT
destroy is called on a valid stream releases backend resources, sets *s to NULL

Notes

  • The private close callback is exercised indirectly via stream_destroy().
  • Memory correctness is validated using fake_memory invariants.