merge: iobackend on dev
This commit is contained in:
commit
9923ebc677
3 changed files with 218 additions and 17 deletions
120
tests/unit/io_backend/io_backend.c
Normal file
120
tests/unit/io_backend/io_backend.c
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
#include <criterion/criterion.h>
|
||||
#include <criterion/new/assert.h>
|
||||
#include <io_backend/io_backend.h>
|
||||
#include <stdio.h>
|
||||
|
||||
TestSuite(IO_Backend);
|
||||
|
||||
// IOB Init
|
||||
|
||||
Test(IO_Backend, init_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.iob_mode = IOB_MODE_NULL;
|
||||
.args = NULL;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_stdin)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.iob_mode = IOB_MODE_STDIN;
|
||||
.args = NULL;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
// WARNING: this one could fail because of iob_close in the previous test
|
||||
// Same applies for other tests
|
||||
Test(IO_Backend, init_script)
|
||||
{
|
||||
char *script_name = "script.tmp" struct iob_context ctx = {
|
||||
.iob_mode = IOB_MODE_SCRIPT;
|
||||
.args = script_name;
|
||||
};
|
||||
// Create file
|
||||
FILE *f = fopen(script_name, "w");
|
||||
fclose(f);
|
||||
|
||||
int actual = iob_init(ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
remove(script_name);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_script_not_a_file)
|
||||
{
|
||||
char *script_name = "not_a_file.tmp" struct iob_context ctx = {
|
||||
.iob_mode = IOB_MODE_SCRIPT;
|
||||
.args = script_name;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_script_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.iob_mode = IOB_MODE_SCRIPT;
|
||||
.args = NULL;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = IOB_ERROR_CANNOT_OPEN_FILE;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_cmd)
|
||||
{
|
||||
char *cmd = "iamacommand --yesido" struct iob_context ctx = {
|
||||
.iob_mode = IOB_MODE_CMD;
|
||||
.args = cmd;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = 0;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_cmd_null)
|
||||
{
|
||||
struct iob_context ctx =
|
||||
{
|
||||
.iob_mode = IOB_MODE_CMD;
|
||||
.args = NULL;
|
||||
};
|
||||
int actual = iob_init(ctx);
|
||||
int expected = IOB_ERROR_BAD_ARG;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
}
|
||||
|
||||
Test(IO_Backend, init_already_init)
|
||||
{
|
||||
char *cmd = "iamacommand --yesido" struct iob_context ctx = {
|
||||
.iob_mode = IOB_MODE_CMD;
|
||||
.args = cmd;
|
||||
};
|
||||
iob_init(ctx);
|
||||
int actual = iob_init(ctx);
|
||||
int expected = IOB_ERROR_ALREADY_INITIALIZED;
|
||||
cr_expect(actual == expected, "Expected: %d. Got: %d", expected, actual);
|
||||
iob_close();
|
||||
}
|
||||
|
||||
Test(IO_Backend, close_not_init)
|
||||
{
|
||||
iob_close(); // Shouldn't do anything
|
||||
}
|
||||
|
||||
// IOB Stream
|
||||
// TODO
|
||||
Loading…
Add table
Add a link
Reference in a new issue