-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_buffer.c
More file actions
53 lines (48 loc) · 1.1 KB
/
Copy pathtest_buffer.c
File metadata and controls
53 lines (48 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
int test_it(const char *test_value)
{
char buf[1024];
int fd = open("/dev/buffer-device", O_RDWR);
write(fd, test_value, strlen(test_value));
close(fd);
fd = open("/dev/buffer-device", O_RDWR);
read(fd, buf, sizeof(buf));
close(fd);
int result = strcmp(test_value, buf);
if (result == 0)
{
printf("%s <=> %s\n", test_value, buf);
}
else
{
printf("%s <> %s\n Lengths: %lu %lu\n", test_value, buf,
strlen(test_value), strlen(buf));
}
return result;
}
int main()
{
int test_result = 0;
//test_result |= test_it("One");
//test_result |= test_it("Two");
//test_result |= test_it("Three");
//test_result |= test_it("");
char long_string[1000];
memset(long_string, 'r', 999);
test_result |= test_it(long_string);
if (test_result == 0)
{
printf("Test passed\n");
}
else
{
printf("Something wrong\n");
}
return 0;
}