utilitiec/tests/Subprocess.test.c

32 lines
743 B
C
Raw Permalink Normal View History

2024-09-22 22:26:33 +02:00
#include "../src/Subprocess/Subprocess.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char read_buffer[128];
void testEcho()
{
Subprocess sub;
sub.in .type = SUBPROCESSREDIRECTIONTYPE_PIPE;
sub.out.type = SUBPROCESSREDIRECTIONTYPE_PIPE;
sub.err.type = SUBPROCESSREDIRECTIONTYPE_PIPE;
char* argv[] = { "echo", "Hello World!", NULL };
assert(EXIT_SUCCESS == Subprocess_Create(&sub, "/usr/bin/echo", argv));
ssize_t read_size = read(sub.out.get.pipefd, read_buffer, 128);
assert(read_size == 13);
assert(strcmp(read_buffer, "Hello World!\n") == 0);
assert(read(sub.out.get.pipefd, read_buffer, 128) == 0);
Subprocess_Destroy(&sub);
}
int main()
{
testEcho();
return 0;
}