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

Unit tests for the public osal_file operations table. More...

#include "osal/file/osal_file_ops.h"
#include "osal/mem/osal_mem.h"
#include "osal/mem/test/osal_mem_fake_provider.h"
#include "lexleo_cmocka.h"
Include dependency graph for unit_test_osal_file.c:

Go to the source code of this file.

Enumerations

enum  osal_file_open_scenario_t {
  OSAL_FILE_OPEN_SCENARIO_OUT_NULL = 0 , OSAL_FILE_OPEN_SCENARIO_PATHNAME_NULL , OSAL_FILE_OPEN_SCENARIO_PATHNAME_EMPTY , OSAL_FILE_OPEN_SCENARIO_MODE_NULL ,
  OSAL_FILE_OPEN_SCENARIO_MODE_UNSUPPORTED , OSAL_FILE_OPEN_SCENARIO_MEM_OPS_NULL , OSAL_FILE_OPEN_SCENARIO_OOM , OSAL_FILE_OPEN_SCENARIO_OK
}
 Scenarios for osal_file_ops_t::open(). More...
 
enum  osal_file_read_scenario_t {
  OSAL_FILE_READ_SCENARIO_PTR_NULL = 0 , OSAL_FILE_READ_SCENARIO_ST_NULL , OSAL_FILE_READ_SCENARIO_STREAM_NULL , OSAL_FILE_READ_SCENARIO_READ_LESS_THAN_AVAILABLE ,
  OSAL_FILE_READ_SCENARIO_READ_EXACT_AVAILABLE , OSAL_FILE_READ_SCENARIO_READ_MORE_THAN_AVAILABLE , OSAL_FILE_READ_SCENARIO_EMPTY_FILE , OSAL_FILE_READ_SCENARIO_SEQUENTIAL_READS_PARTIAL_THEN_PARTIAL ,
  OSAL_FILE_READ_SCENARIO_READ_AFTER_EOF , OSAL_FILE_READ_SCENARIO_ZERO_SIZE , OSAL_FILE_READ_SCENARIO_ZERO_NMEMB , OSAL_FILE_READ_SCENARIO_READ_LESS_THAN_AVAILABLE_SIZE_GT_1 ,
  OSAL_FILE_READ_SCENARIO_READ_EXACT_AVAILABLE_SIZE_GT_1 , OSAL_FILE_READ_SCENARIO_READ_MORE_THAN_AVAILABLE_SIZE_GT_1
}
 Scenarios for osal_file_ops_t::read(). More...
 
enum  osal_file_write_scenario_t {
  OSAL_FILE_WRITE_SCENARIO_PTR_NULL = 0 , OSAL_FILE_WRITE_SCENARIO_STREAM_NULL , OSAL_FILE_WRITE_SCENARIO_ST_NULL , OSAL_FILE_WRITE_SCENARIO_ZERO_SIZE ,
  OSAL_FILE_WRITE_SCENARIO_ZERO_NMEMB , OSAL_FILE_WRITE_SCENARIO_WRITE_ONE_ELEMENT_OK , OSAL_FILE_WRITE_SCENARIO_WRITE_MULTIPLE_ELEMENTS_SIZE_1_OK , OSAL_FILE_WRITE_SCENARIO_WRITE_MULTIPLE_ELEMENTS_SIZE_GT_1_OK ,
  OSAL_FILE_WRITE_SCENARIO_SEQUENTIAL_WRITES_OK
}
 Scenarios for osal_file_ops_t::write(). More...
 
enum  osal_file_flush_scenario_t { OSAL_FILE_FLUSH_SCENARIO_STREAM_NULL = 0 , OSAL_FILE_FLUSH_SCENARIO_OK }
 Scenarios for osal_file_ops_t::flush(). More...
 
enum  osal_file_close_scenario_t { OSAL_FILE_CLOSE_SCENARIO_STREAM_NULL = 0 , OSAL_FILE_CLOSE_SCENARIO_OK }
 Scenarios for osal_file_ops_t::close(). More...
 

Functions

static void test_osal_file_default_ops (void **state)
 Test osal_file_default_ops().
 

Detailed Description

This file contains unit tests for:

The osal_file_ops_t operations are exercised through the default operations table returned by osal_file_default_ops().

Definition in file unit_test_osal_file.c.

Enumeration Type Documentation

◆ osal_file_close_scenario_t

No doubles.

See contract:

Enumerator
OSAL_FILE_CLOSE_SCENARIO_STREAM_NULL 

WHEN osal_file_ops_t::close() is called with stream == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
OSAL_FILE_CLOSE_SCENARIO_OK 

WHEN osal_file_ops_t::close() is called on a valid open stream EXPECT:

  • returns OSAL_FILE_STATUS_OK

Definition at line 1853 of file unit_test_osal_file.c.

◆ osal_file_flush_scenario_t

No doubles.

See contract:

Enumerator
OSAL_FILE_FLUSH_SCENARIO_STREAM_NULL 

WHEN osal_file_ops_t::flush() is called with stream == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
OSAL_FILE_FLUSH_SCENARIO_OK 

WHEN osal_file_ops_t::flush() is called on a valid writable stream EXPECT:

  • returns OSAL_FILE_STATUS_OK

Definition at line 1637 of file unit_test_osal_file.c.

◆ osal_file_open_scenario_t

Doubles:

  • fake_memory

See contracts:

Enumerator
OSAL_FILE_OPEN_SCENARIO_OUT_NULL 

WHEN osal_file_ops_t::open() is called with out == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_PATHNAME_NULL 

WHEN osal_file_ops_t::open() is called with pathname == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
  • leaves *out unchanged if out != NULL
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_PATHNAME_EMPTY 

WHEN osal_file_ops_t::open() is called with ‘pathname[0] == ’\0' EXPECT:

  • returnsOSAL_FILE_STATUS_INVALID
  • leaves*outunchanged ifout != NULL
  • noOSAL_FILE` handle is produced

OSAL_FILE_OPEN_SCENARIO_MODE_NULL 

WHEN osal_file_ops_t::open() is called with mode == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
  • leaves *out unchanged if out != NULL
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_MODE_UNSUPPORTED 

WHEN osal_file_ops_t::open() is called with an unsupported mode EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
  • leaves *out unchanged if out != NULL
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_MEM_OPS_NULL 

WHEN osal_file_ops_t::open() is called with mem_ops == NULL EXPECT:

  • returns OSAL_FILE_STATUS_INVALID
  • leaves *out unchanged if out != NULL
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_OOM 

WHEN allocation of the OSAL wrapper fails during osal_file_ops_t::open() EXPECT:

  • returns OSAL_FILE_STATUS_OOM
  • leaves *out unchanged if out != NULL
  • no OSAL_FILE handle is produced
OSAL_FILE_OPEN_SCENARIO_OK 

WHEN osal_file_ops_t::open() is called with valid arguments EXPECT:

  • returns OSAL_FILE_STATUS_OK
  • stores a non-NULL OSAL_FILE handle in *out

Definition at line 61 of file unit_test_osal_file.c.

◆ osal_file_read_scenario_t

No doubles.

See contract:

Enumerator
OSAL_FILE_READ_SCENARIO_PTR_NULL 

WHEN osal_file_ops_t::read() is called with ptr == NULL EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
OSAL_FILE_READ_SCENARIO_ST_NULL 

WHEN osal_file_ops_t::read() is called with st == NULL EXPECT:

  • returns 0
  • no status is written
OSAL_FILE_READ_SCENARIO_STREAM_NULL 

WHEN osal_file_ops_t::read() is called with stream == NULL EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
OSAL_FILE_READ_SCENARIO_READ_LESS_THAN_AVAILABLE 

WHEN osal_file_ops_t::read() is called with valid arguments and the requested element count is smaller than the available file content EXPECT:

  • returns nmemb
  • copies the requested elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_EXACT_AVAILABLE 

WHEN osal_file_ops_t::read() is called with valid arguments and the requested element count exactly matches the available file content EXPECT:

  • returns nmemb
  • copies the requested elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_MORE_THAN_AVAILABLE 

WHEN osal_file_ops_t::read() is called with valid arguments and the requested element count is greater than the available file content EXPECT:

  • returns a value smaller than nmemb
  • copies the available elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_EMPTY_FILE 

WHEN osal_file_ops_t::read() is called with valid arguments and the file is empty EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_SEQUENTIAL_READS_PARTIAL_THEN_PARTIAL 

WHEN osal_file_ops_t::read() is called multiple times on the same open OSAL_FILE, first with a request smaller than the available file content, then again with another request smaller than the remaining file content EXPECT:

  • the first call returns the requested element count
  • the second call returns the requested element count
  • each call copies the expected data from the current file position into ptr
  • each call sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_AFTER_EOF 

WHEN osal_file_ops_t::read() is called after end-of-file has already been reached on the same open OSAL_FILE EXPECT:

  • returns 0
  • reads no additional data into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_ZERO_SIZE 

WHEN osal_file_ops_t::read() is called with valid arguments and size == 0 EXPECT:

  • returns 0
  • reads no data into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_ZERO_NMEMB 

WHEN osal_file_ops_t::read() is called with valid arguments and nmemb == 0 EXPECT:

  • returns 0
  • reads no data into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_LESS_THAN_AVAILABLE_SIZE_GT_1 

WHEN osal_file_ops_t::read() is called with valid arguments, size > 1, and the requested element count is smaller than the number of complete elements available in the file EXPECT:

  • returns nmemb
  • copies the requested complete elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_EXACT_AVAILABLE_SIZE_GT_1 

WHEN osal_file_ops_t::read() is called with valid arguments, size > 1, and the requested element count exactly matches the number of complete elements available in the file EXPECT:

  • returns nmemb
  • copies the requested complete elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK
OSAL_FILE_READ_SCENARIO_READ_MORE_THAN_AVAILABLE_SIZE_GT_1 

WHEN osal_file_ops_t::read() is called with valid arguments, size > 1, and the requested element count is greater than the number of complete elements available in the file EXPECT:

  • returns a value smaller than nmemb
  • copies the available complete elements into ptr
  • sets *st to OSAL_FILE_STATUS_OK

Definition at line 442 of file unit_test_osal_file.c.

◆ osal_file_write_scenario_t

No doubles.

See contract:

Enumerator
OSAL_FILE_WRITE_SCENARIO_PTR_NULL 

WHEN osal_file_ops_t::write() is called with ptr == NULL EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
OSAL_FILE_WRITE_SCENARIO_STREAM_NULL 

WHEN osal_file_ops_t::write() is called with stream == NULL EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
OSAL_FILE_WRITE_SCENARIO_ST_NULL 

WHEN osal_file_ops_t::write() is called with st == NULL EXPECT:

  • returns 0
  • no status can be stored
OSAL_FILE_WRITE_SCENARIO_ZERO_SIZE 

WHEN osal_file_ops_t::write() is called with size == 0 EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_OK
  • writes no data
OSAL_FILE_WRITE_SCENARIO_ZERO_NMEMB 

WHEN osal_file_ops_t::write() is called with nmemb == 0 EXPECT:

  • returns 0
  • sets *st to OSAL_FILE_STATUS_OK
  • writes no data
OSAL_FILE_WRITE_SCENARIO_WRITE_ONE_ELEMENT_OK 

WHEN osal_file_ops_t::write() is called with nmemb == 1 on a valid writable stream EXPECT:

  • returns 1
  • sets *st to OSAL_FILE_STATUS_OK
  • writes the requested data
OSAL_FILE_WRITE_SCENARIO_WRITE_MULTIPLE_ELEMENTS_SIZE_1_OK 

WHEN osal_file_ops_t::write() is called with multiple elements of size 1 on a valid writable stream EXPECT:

  • returns nmemb
  • sets *st to OSAL_FILE_STATUS_OK
  • writes the requested data
OSAL_FILE_WRITE_SCENARIO_WRITE_MULTIPLE_ELEMENTS_SIZE_GT_1_OK 

WHEN osal_file_ops_t::write() is called with multiple elements of size greater than 1 on a valid writable stream EXPECT:

  • returns nmemb
  • sets *st to OSAL_FILE_STATUS_OK
  • writes the requested data
OSAL_FILE_WRITE_SCENARIO_SEQUENTIAL_WRITES_OK 

WHEN osal_file_ops_t::write() is called twice successively on the same valid writable stream EXPECT:

  • each call returns its requested element count
  • each call sets *st to OSAL_FILE_STATUS_OK
  • the final file content reflects both writes in order

Definition at line 1096 of file unit_test_osal_file.c.

Function Documentation

◆ test_osal_file_default_ops()

static void test_osal_file_default_ops ( void **  state)
static