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

It covers:


osal_file_default_ops() unit tests

See osal_file_default_ops() specifications

Functions under test

const osal_file_ops_t * osal_file_default_ops(void)
Return the default OSAL file operations for the active platform.

Test doubles

  • none

Tested scenarios

WHEN EXPECT
osal_file_default_ops() is called returns a non-NULL pointer to an osal_file_ops_t;
ret->open != NULL;
ret->read != NULL;
ret->write != NULL;
ret->flush != NULL;
ret->close != NULL

Notes

  • This helper exposes the default low-level OSAL file operations table for the active platform.
  • The returned table is expected to provide a well-formed set of callable low-level file operations.

osal_file_ops_t::open() unit tests

See osal_file_ops_t::open specifications

Functions under test

OSAL_FILE **out,
const char *pathname,
const char *mode,
const osal_mem_ops_t *mem_ops);
osal_file_status_t
Private representation of an acquired OSAL file handle.

Test doubles

Tested scenarios

WHEN EXPECT
osal_file_ops_t::open() is called with out == NULL returns OSAL_FILE_STATUS_INVALID;
no OSAL_FILE handle is produced
osal_file_ops_t::open() is called with pathname == NULL returns OSAL_FILE_STATUS_INVALID;
leaves *out unchanged if out != NULL;
no OSAL_FILE handle is produced
osal_file_ops_t::open() is called with ‘pathname[0] == ’\0'\ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_INVALID;<br>leaves*outunchanged ifout != NULL;<br>noOSAL_FILEhandle is produced \ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone">osal_file_ops_t::open()is called withmode == NULL\ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_INVALID;<br>leaves*outunchanged ifout != NULL;<br>noOSAL_FILEhandle is produced \ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone">osal_file_ops_t::open()is called with an unsupported mode \ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_INVALID;<br>leaves*outunchanged ifout != NULL;<br>noOSAL_FILEhandle is produced \ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone">osal_file_ops_t::open()is called withmem_ops == NULL\ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_INVALID;<br>leaves*outunchanged ifout != NULL;<br>noOSAL_FILEhandle is produced \ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"> allocation of the OSAL wrapper fails duringosal_file_ops_t::open()\ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_OOM;<br>leaves*outunchanged ifout != NULL;<br>noOSAL_FILEhandle is produced \ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone">osal_file_ops_t::open()is called with valid arguments \ilinebr </td> <td class="markdownTableBodyNone"> returnsOSAL_FILE_STATUS_OK;<br>stores a non-NULLOSAL_FILEhandle in*out`

Notes

  • These tests validate the public acquisition contract of osal_file_ops_t::open().
  • The OOM scenario is exercised through the injected memory operations table and fake_memory fail injection.
  • Success requires a valid pathname, a supported portable mode, and a valid injected memory operations table.
  • Supported portable modes covered by the contract are "rb", "wb", and "ab".

osal_file_ops_t::read() unit tests

See osal_file_ops_t::read specifications

Functions under test

size_t (*read)(
void *ptr,
size_t size,
size_t nmemb,
OSAL_FILE *stream,

Test doubles

Tested scenarios

WHEN EXPECT
osal_file_ops_t::read() is called with ptr == NULL returns 0;
sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
osal_file_ops_t::read() is called with st == NULL returns 0;
no status is written
osal_file_ops_t::read() is called with stream == NULL returns 0;
sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
osal_file_ops_t::read() is called with valid arguments and the requested element count is smaller than the available file content returns nmemb;
copies the requested elements into ptr;
sets *st to OSAL_FILE_STATUS_OK
osal_file_ops_t::read() is called with valid arguments and the requested element count exactly matches the available file content returns nmemb;
copies the requested elements into ptr;
sets *st to OSAL_FILE_STATUS_OK
osal_file_ops_t::read() is called with valid arguments and the requested element count is greater than the available file content returns a value smaller than nmemb;
copies the available elements into ptr;
sets *st to OSAL_FILE_STATUS_OK
osal_file_ops_t::read() is called with valid arguments and the file is empty returns 0;
sets *st to OSAL_FILE_STATUS_OK
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 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_ops_t::read() is called after end-of-file has already been reached on the same open OSAL_FILE returns 0;
reads no additional data into ptr;
sets *st to OSAL_FILE_STATUS_OK
osal_file_ops_t::read() is called with valid arguments and size == 0 returns 0;
reads no data into ptr;
sets *st to OSAL_FILE_STATUS_OK
osal_file_ops_t::read() is called with valid arguments and nmemb == 0 returns 0;
reads no data into ptr;
sets *st to OSAL_FILE_STATUS_OK
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 returns nmemb;
copies the requested complete elements into ptr;
sets *st to OSAL_FILE_STATUS_OK
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 returns nmemb;
copies the requested complete elements into ptr;
sets *st to OSAL_FILE_STATUS_OK
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 returns a value smaller than nmemb;
copies the available complete elements into ptr;
sets *st to OSAL_FILE_STATUS_OK

Notes

  • These tests validate the public read contract of osal_file_ops_t::read().
  • The initial file content is prepared before the tested read sequence starts.
  • The tested read() calls are exercised through the default operations table returned by osal_file_default_ops().
  • The file preparation path uses the public OSAL file operations table together with the injected memory operations table.
  • These tests exercise deterministic reads on real temporary files rather than backend doubles.
  • The successful short-read scenarios covered here are end-of-file driven cases, not backend failure cases.
  • For size > 1 scenarios, expectations are expressed in complete elements, not bytes.

osal_file_ops_t::write() unit tests

See osal_file_ops_t::write specifications

Functions under test

size_t (*write)(
const void *ptr,
size_t size,
size_t nmemb,
OSAL_FILE *stream,

Test doubles

Tested scenarios

WHEN EXPECT
osal_file_ops_t::write() is called with ptr == NULL returns 0;
sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
osal_file_ops_t::write() is called with stream == NULL returns 0;
sets *st to OSAL_FILE_STATUS_INVALID if st != NULL
osal_file_ops_t::write() is called with st == NULL returns 0;
no status can be stored
osal_file_ops_t::write() is called with size == 0 returns 0;
sets *st to OSAL_FILE_STATUS_OK;
writes no data
osal_file_ops_t::write() is called with nmemb == 0 returns 0;
sets *st to OSAL_FILE_STATUS_OK;
writes no data
osal_file_ops_t::write() is called with nmemb == 1 on a valid writable stream returns 1;
sets *st to OSAL_FILE_STATUS_OK;
writes the requested data
osal_file_ops_t::write() is called with multiple elements of size 1 on a valid writable stream returns nmemb;
sets *st to OSAL_FILE_STATUS_OK;
writes the requested data
osal_file_ops_t::write() is called with multiple elements of size greater than 1 on a valid writable stream returns nmemb;
sets *st to OSAL_FILE_STATUS_OK;
writes the requested data
osal_file_ops_t::write() is called twice successively on the same valid writable stream 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

Notes

  • These tests validate the public write contract of osal_file_ops_t::write().
  • The initial file content is prepared before the tested write sequence starts.
  • The tested write() calls are exercised through the default operations table returned by osal_file_default_ops().
  • The file verification path reopens the temporary file in read mode after the tested write sequence completes.
  • The file preparation and verification steps use the public OSAL file operations table together with the injected memory operations table.
  • These tests exercise deterministic writes on real temporary files rather than backend doubles.
  • For size > 1 scenarios, expectations are expressed in complete elements, not bytes.
  • The sequential scenario validates cumulative effects on the same writable stream across successive write() calls.

osal_file_ops_t::flush() unit tests

See osal_file_ops_t::flush specifications

Functions under test

osal_file_status_t (*flush)(OSAL_FILE *stream);

Test doubles

Tested scenarios

WHEN EXPECT
osal_file_ops_t::flush() is called with stream == NULL returns OSAL_FILE_STATUS_INVALID
osal_file_ops_t::flush() is called on a valid writable stream returns OSAL_FILE_STATUS_OK

Notes

  • These tests validate the public flush contract of osal_file_ops_t::flush().
  • The initial file content is written before the tested flush() call when the scenario uses a valid writable stream.
  • The tested flush() call is exercised through the default operations table returned by osal_file_default_ops().
  • The file preparation path uses the public OSAL file operations table together with the injected memory operations table.
  • These tests exercise deterministic flush calls on real temporary files rather than backend doubles.
  • The current suite validates the observable status contract of flush(); it does not attempt to prove backend-specific buffering effects beyond that public result.

osal_file_ops_t::close() unit tests

See osal_file_ops_t::close specifications

Functions under test

osal_file_status_t (*close)(OSAL_FILE *stream);

Test doubles

Tested scenarios

WHEN EXPECT
osal_file_ops_t::close() is called with stream == NULL returns OSAL_FILE_STATUS_INVALID
osal_file_ops_t::close() is called on a valid open stream returns OSAL_FILE_STATUS_OK

Notes

  • These tests validate the public close contract of osal_file_ops_t::close().
  • The tested close() call is exercised through the default operations table returned by osal_file_default_ops().
  • The stream under test is acquired during fixture setup through osal_file_ops_t::open().
  • The fixture teardown closes the stream only if it was not already consumed by the tested close() call.
  • The setup and teardown paths use the public OSAL file operations table together with the injected memory operations table.
  • These tests exercise deterministic close calls on real temporary files rather than backend doubles.
  • The current suite validates the observable status contract of close(); it does not attempt to prove backend-specific close failure mappings beyond that public result.