rework inout test to use pipes for emulating files
This commit is contained in:
+14
-8
@@ -31,22 +31,28 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define pipe(fds) _pipe(fds,4096, 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
static void test_inout(enum enum_format format) {
|
static void test_inout(enum enum_format format) {
|
||||||
const unsigned char buf[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
const unsigned char buf[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||||
unsigned char buf2[sizeof(buf)];
|
unsigned char buf2[sizeof(buf)];
|
||||||
char filename[] = "/tmp/pivtool_test_XXXXXX";
|
int pipefd[2];
|
||||||
int fd = mkstemp(filename);
|
FILE *tmp1, *tmp2;
|
||||||
FILE *tmp = fdopen(fd, "r+");
|
|
||||||
|
|
||||||
dump_data(buf, sizeof(buf), tmp, false, format);
|
assert(pipe(pipefd) == 0);
|
||||||
rewind(tmp);
|
tmp1 = fdopen(pipefd[1], "w");
|
||||||
read_data(buf2, sizeof(buf2), tmp, format);
|
dump_data(buf, sizeof(buf), tmp1, false, format);
|
||||||
|
fclose(tmp1);
|
||||||
|
tmp2 = fdopen(pipefd[0], "r");
|
||||||
|
read_data(buf2, sizeof(buf2), tmp2, format);
|
||||||
assert(memcmp(buf, buf2, sizeof(buf)) == 0);
|
assert(memcmp(buf, buf2, sizeof(buf)) == 0);
|
||||||
fclose(tmp);
|
fclose(tmp2);
|
||||||
remove(filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user