MCPcopy Create free account
hub / github.com/acl-dev/acl / test_file_vstream

Function test_file_vstream

unit_test/stdlib/test_vstream.c:7–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "test_stdlib.h"
6
7int test_file_vstream(AUT_LINE *test_line acl_unused, void *arg acl_unused)
8{
9 ACL_VSTREAM *fp = NULL;
10 const char *filename;
11 char buf[1024];
12 int i, n = 4, ret;
13
14#undef RETURN
15#define RETURN(_x_) do { \
16 if (fp) \
17 acl_vstream_fclose(fp); \
18 return (_x_); \
19} while (0)
20
21 AUT_SET_STR(test_line, "filename", filename);
22 fp = acl_vstream_fopen(filename, O_CREAT | O_RDWR | O_TRUNC, 0600, 1024);
23 if (fp == NULL) {
24 printf("fopen file(%s) error(%s)\r\n",
25 filename, acl_last_serror());
26 return (-1);
27 }
28
29 memset(buf, 'X', sizeof(buf));
30 for (i = 0; i < n; i++) {
31 if (acl_vstream_buffed_writen(fp, buf, sizeof(buf)) == ACL_VSTREAM_EOF) {
32 printf("buffed write to file(%s) error(%s)\r\n",
33 filename, acl_last_serror());
34 RETURN (-1);
35 }
36 }
37
38 ret = (int) acl_vstream_fsize(fp);
39 if (ret != (int) sizeof(buf) * n) {
40 printf("%s's fsize return error(%s)\r\n", filename, acl_last_serror());
41 RETURN (-1);
42 }
43 printf("%s's acl_vstream_fsize: %d\r\n", filename, ret);
44
45 i = (int) acl_file_size(filename);
46 printf("%s: fsize=%d before fflush\r\n", filename, i);
47
48#if 1
49 if (acl_vstream_fflush(fp) < 0) {
50 printf("fflush to file(%s) error(%s)\r\n",
51 filename, acl_last_serror());
52 RETURN (-1);
53 }
54 i = (int) acl_file_size(filename);
55 printf("%s: fsize=%d after fflush\r\n", filename, i);
56#endif
57
58 if (acl_vstream_fsync(fp) == ACL_VSTREAM_EOF) {
59 printf("fsync to file(%s) error(%s)\r\n",
60 filename, acl_last_serror());
61 RETURN (-1);
62 }
63 i = (int) acl_file_size(filename);
64 printf("%s: fsize=%d after fsync\r\n", filename, i);

Callers

nothing calls this directly

Calls 7

acl_vstream_fopenFunction · 0.85
acl_last_serrorFunction · 0.85
acl_vstream_fsizeFunction · 0.85
acl_file_sizeFunction · 0.85
acl_vstream_fflushFunction · 0.85
acl_vstream_fsyncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…