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

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

Include dependency graph for unit_test_fs_stream.c:

Go to the source code of this file.

Enumerations

enum  fs_create_stream_scenario_t {
  FS_CREATE_STREAM_SCENARIO_OK = 0 , FS_CREATE_STREAM_SCENARIO_OUT_NULL , FS_CREATE_STREAM_SCENARIO_ARGS_NULL , FS_CREATE_STREAM_SCENARIO_CFG_NULL ,
  FS_CREATE_STREAM_SCENARIO_ENV_NULL , FS_CREATE_STREAM_SCENARIO_PATH_NULL , FS_CREATE_STREAM_SCENARIO_PATH_EMPTY , FS_CREATE_STREAM_SCENARIO_FLAGS_ZERO ,
  FS_CREATE_STREAM_SCENARIO_OOM , FS_CREATE_STREAM_SCENARIO_OPEN_FAIL
}
 Scenarios for fs_stream_create_stream(). More...
 
enum  fs_stream_create_desc_scenario_t {
  FS_STREAM_CREATE_DESC_SCENARIO_OK = 0 , FS_STREAM_CREATE_DESC_SCENARIO_OUT_NULL , FS_STREAM_CREATE_DESC_SCENARIO_KEY_NULL , FS_STREAM_CREATE_DESC_SCENARIO_KEY_EMPTY ,
  FS_STREAM_CREATE_DESC_SCENARIO_CFG_NULL , FS_STREAM_CREATE_DESC_SCENARIO_ENV_NULL , FS_STREAM_CREATE_DESC_SCENARIO_MEM_NULL , FS_STREAM_CREATE_DESC_SCENARIO_OOM
}
 Scenarios for fs_stream_create_desc(). More...
 
enum  fs_stream_desc_ctor_scenario_t {
  FS_STREAM_DESC_CTOR_SCENARIO_OK = 0 , FS_STREAM_DESC_CTOR_SCENARIO_ARGS_NULL , FS_STREAM_DESC_CTOR_SCENARIO_OUT_NULL , FS_STREAM_DESC_CTOR_SCENARIO_PATH_NULL ,
  FS_STREAM_DESC_CTOR_SCENARIO_PATH_EMPTY , FS_STREAM_DESC_CTOR_SCENARIO_FLAGS_ZERO , FS_STREAM_DESC_CTOR_SCENARIO_OOM , FS_STREAM_DESC_CTOR_SCENARIO_OPEN_FAIL
}
 Scenarios for fs_stream_create_desc() descriptor constructor usage. More...
 

Functions

static void test_fs_stream_default_cfg (void **state)
 Test fs_stream_default_cfg().
 
static void test_fs_stream_default_env (void **state)
 Test fs_stream_default_env().
 

Detailed Description

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

Covered surfaces:

Test strategy:

  • direct validation of default CR helper return values
  • parametric scenario-based testing
  • explicit validation of argument checking and output-handle preservation
  • allocator fault injection through fake_memory
  • backend file fault injection through fake_file
  • public stream borrower API checks on successfully created streams

See also:

Definition in file unit_test_fs_stream.c.

Enumeration Type Documentation

◆ fs_create_stream_scenario_t

stream_status_t fs_stream_create_stream( stream_t **out, const fs_stream_args_t *args, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env );

Invalid arguments:

  • out, args, cfg, env must not be NULL.
  • args->path must not be NULL and must not be an empty string.
  • args->flags must not be zero.

Success:

  • Returns STREAM_STATUS_OK.
  • Stores a valid stream in *out.
  • The produced stream is ready for normal runtime use.
  • The produced stream must be destroyed via stream_destroy().

Failure:

  • Returns:
    • STREAM_STATUS_INVALID for invalid arguments
    • STREAM_STATUS_OOM on allocation failure
    • STREAM_STATUS_IO_ERROR when OSAL file operations fail
  • Leaves *out unchanged if out is not NULL.

Doubles:

  • fake_memory
  • fake_file

See also:

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

Enumerator
FS_CREATE_STREAM_SCENARIO_OK 

WHEN fs_stream_create_stream(out, args, cfg, env) is called with valid arguments and OSAL file opening succeeds EXPECT:

  • returns STREAM_STATUS_OK
  • stores a non-NULL stream handle in *out
  • the produced stream is ready for normal runtime use
FS_CREATE_STREAM_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • no stream handle is produced
FS_CREATE_STREAM_SCENARIO_ARGS_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_CFG_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_ENV_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_PATH_NULL 

WHEN args != NULL but args->path == NULL and out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_PATH_EMPTY 

WHEN args != NULL but args->path is an empty string AND out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_FLAGS_ZERO 

WHEN args != NULL but args->flags == 0 AND out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_CREATE_STREAM_SCENARIO_OOM 

WHEN allocation required by fs_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.
FS_CREATE_STREAM_SCENARIO_OPEN_FAIL 

WHEN fs_stream_create_stream(out, args, cfg, env) is called with valid arguments but OSAL file opening fails EXPECT:

  • returns STREAM_STATUS_IO_ERROR
  • leaves *out unchanged

Notes:

  • This scenario is exercised by configuring fake_file to fail the open operation.

Definition at line 156 of file unit_test_fs_stream.c.

◆ fs_stream_create_desc_scenario_t

stream_status_t fs_stream_create_desc( stream_adapter_desc_t *out, stream_key_t key, const fs_stream_cfg_t *cfg, const fs_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 fs_stream_create_desc().

Enumerator
FS_STREAM_CREATE_DESC_SCENARIO_OK 

WHEN fs_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()
FS_STREAM_CREATE_DESC_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • no descriptor is produced
FS_STREAM_CREATE_DESC_SCENARIO_KEY_NULL 

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

  • returns STREAM_STATUS_INVALID
  • resets *out to an empty descriptor
FS_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
FS_STREAM_CREATE_DESC_SCENARIO_CFG_NULL 

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

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

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

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

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

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

WHEN allocation required by fs_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 627 of file unit_test_fs_stream.c.

◆ fs_stream_desc_ctor_scenario_t

stream_status_t desc.ctor( const void *ud, const fs_stream_args_t *args, stream_t **out );

Invalid arguments:

  • args and out must not be NULL.
  • args->path must not be NULL and must not be an empty string.
  • args->flags must not be zero.

Success:

  • Returns STREAM_STATUS_OK.
  • Stores a valid stream in *out.
  • The produced stream is ready for normal runtime use.
  • The produced stream must be destroyed via stream_destroy().

Failure:

  • Returns:
    • STREAM_STATUS_INVALID for invalid arguments
    • STREAM_STATUS_OOM on allocation failure
    • STREAM_STATUS_IO_ERROR when OSAL file operations fail
  • Leaves *out unchanged if out is not NULL.

Doubles:

  • fake_memory
  • fake_file

See also:

The scenarios below define the test oracle for descriptor constructor usage through fs_stream_create_desc().

Enumerator
FS_STREAM_DESC_CTOR_SCENARIO_OK 

WHEN desc.ctor(ud, args, out) is called with valid arguments and OSAL file opening succeeds EXPECT:

  • returns STREAM_STATUS_OK
  • stores a non-NULL stream handle in *out
  • the produced stream is ready for normal runtime use
FS_STREAM_DESC_CTOR_SCENARIO_ARGS_NULL 

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

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_STREAM_DESC_CTOR_SCENARIO_OUT_NULL 

WHEN out == NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • no stream handle is produced
FS_STREAM_DESC_CTOR_SCENARIO_PATH_NULL 

WHEN args != NULL but args->path == NULL AND out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_STREAM_DESC_CTOR_SCENARIO_PATH_EMPTY 

WHEN args != NULL but args->path is an empty string AND out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_STREAM_DESC_CTOR_SCENARIO_FLAGS_ZERO 

WHEN args != NULL but args->flags == 0 AND out != NULL EXPECT:

  • returns STREAM_STATUS_INVALID
  • leaves *out unchanged
FS_STREAM_DESC_CTOR_SCENARIO_OOM 

WHEN allocation required by desc.ctor() 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.
FS_STREAM_DESC_CTOR_SCENARIO_OPEN_FAIL 

WHEN desc.ctor(ud, args, out) is called with valid arguments but OSAL file opening fails EXPECT:

  • returns STREAM_STATUS_IO_ERROR
  • leaves *out unchanged

Notes:

  • This scenario is exercised by configuring fake_file to fail the open operation.

Definition at line 1014 of file unit_test_fs_stream.c.

Function Documentation

◆ test_fs_stream_default_cfg()

static void test_fs_stream_default_cfg ( void **  state)
static

fs_stream_cfg_t fs_stream_default_cfg(void);

Success:

Failure:

  • None.

See also:

Definition at line 66 of file unit_test_fs_stream.c.

◆ test_fs_stream_default_env()

static void test_fs_stream_default_env ( void **  state)
static