aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_disk.c
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-06-15 20:11:51 +0000
committerNils Durner <durner@gnunet.org>2009-06-15 20:11:51 +0000
commit1088905b5a89a24706d2c1877d289589e3f3c222 (patch)
tree38ec7cdc1b80502aa950c68ebefe1e3f42efa14b /src/util/test_disk.c
parent7e3df72d6b8a32b15b02110b54c77f77e28928a2 (diff)
downloadgnunet-1088905b5a89a24706d2c1877d289589e3f3c222.tar.gz
gnunet-1088905b5a89a24706d2c1877d289589e3f3c222.zip
more complete DISK API
Diffstat (limited to 'src/util/test_disk.c')
-rw-r--r--src/util/test_disk.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 0d385afa7..e305889d8 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -36,13 +36,12 @@ testReadWrite ()
36 char tmp[100 + 1]; 36 char tmp[100 + 1];
37 int ret; 37 int ret;
38 38
39 if (GNUNET_OK != 39 if (GNUNET_OK != GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (
40 GNUNET_DISK_file_write (".testfile", TESTSTRING, strlen (TESTSTRING), 40 TESTSTRING), GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE))
41 "644"))
42 return 1; 41 return 1;
43 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) 42 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
44 return 1; 43 return 1;
45 ret = GNUNET_DISK_file_read (".testfile", sizeof (tmp) - 1, tmp); 44 ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
46 if (ret < 0) 45 if (ret < 0)
47 { 46 {
48 fprintf (stderr, 47 fprintf (stderr,
@@ -59,7 +58,7 @@ testReadWrite ()
59 } 58 }
60 GNUNET_DISK_file_copy (".testfile", ".testfile2"); 59 GNUNET_DISK_file_copy (".testfile", ".testfile2");
61 memset (tmp, 0, sizeof (tmp)); 60 memset (tmp, 0, sizeof (tmp));
62 ret = GNUNET_DISK_file_read (".testfile2", sizeof (tmp) - 1, tmp); 61 ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
63 if (ret < 0) 62 if (ret < 0)
64 { 63 {
65 fprintf (stderr, 64 fprintf (stderr,
@@ -86,15 +85,16 @@ testReadWrite ()
86static int 85static int
87testOpenClose () 86testOpenClose ()
88{ 87{
89 int fd; 88 struct GNUNET_IO_Handle *fh;
90 unsigned long long size; 89 unsigned long long size;
91 long avail; 90 long avail;
92 91
93 fd = GNUNET_DISK_file_open (".testfile", 92 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE
94 O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); 93 | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ
95 GNUNET_assert (-1 != fd); 94 | GNUNET_DISK_PERM_USER_WRITE);
96 GNUNET_break (5 == WRITE (fd, "Hello", 5)); 95 GNUNET_assert (GNUNET_NO == GNUNET_IO_handle_invalid (fh));
97 GNUNET_DISK_file_close (".testfile", fd); 96 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5));
97 GNUNET_DISK_file_close (&fh);
98 GNUNET_break (GNUNET_OK == 98 GNUNET_break (GNUNET_OK ==
99 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO)); 99 GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO));
100 if (size != 5) 100 if (size != 5)
@@ -105,18 +105,19 @@ testOpenClose ()
105 GNUNET_log_skip (1); 105 GNUNET_log_skip (1);
106 avail = GNUNET_DISK_get_blocks_available (".testfile"); 106 avail = GNUNET_DISK_get_blocks_available (".testfile");
107 GNUNET_log_skip (0); 107 GNUNET_log_skip (0);
108 fd = GNUNET_DISK_file_open (".testfile", 108 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE
109 O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); 109 | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_WRITE
110 GNUNET_assert (-1 != fd); 110 | GNUNET_DISK_PERM_USER_READ);
111 GNUNET_assert (GNUNET_NO == GNUNET_IO_handle_invalid (fh));
111 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && 112 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
112 (avail != -1)) 113 (avail != -1))
113 if (16 != WRITE (fd, "HelloWorld123456", 16)) 114 if (16 != GNUNET_DISK_file_write (fh, "HelloWorld123456", 16))
114 { 115 {
115 GNUNET_DISK_file_close (".testfile", fd); 116 GNUNET_DISK_file_close (&fh);
116 GNUNET_break (0 == UNLINK (".testfile")); 117 GNUNET_break (0 == UNLINK (".testfile"));
117 return 1; 118 return 1;
118 } 119 }
119 GNUNET_DISK_file_close (".testfile", fd); 120 GNUNET_DISK_file_close (&fh);
120 GNUNET_break (0 == UNLINK (".testfile")); 121 GNUNET_break (0 == UNLINK (".testfile"));
121 122
122 return 0; 123 return 0;