-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
101 lines (73 loc) · 2.14 KB
/
client.c
File metadata and controls
101 lines (73 loc) · 2.14 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include "CuTest.h"
char message[] = "1Non exisnant folder";
char message2[] = "2/home/travis";
char message3[] = "3";
char buf[1024];
int sock;
void should_throw_error_msg (CuTest* testContext) {
memset(buf, 0, sizeof buf);
send(sock, message, sizeof(message), 0);
recv(sock, buf, sizeof(buf), 0);
CuAssertStrEquals(testContext, "There is no file or directory:\nNon exisnant folder", buf);
}
void should_get_files_number (CuTest* testContext) {
memset(buf, 0, sizeof buf);
send(sock, message2, sizeof(message2), 0);
recv(sock, buf, sizeof(buf), 0);
CuAssertStrEquals(testContext, "Files in directory:\n/home/travis\n18", buf);
}
void should_get_system_info (CuTest* testContext) {
memset(buf, 0, sizeof buf);
send(sock, message3, sizeof(message3), 0);
recv(sock, buf, sizeof(buf), 0);
CuAssertStrEquals(testContext, "System name:\nLinux", buf);
}
CuSuite* test_suite() {
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, should_throw_error_msg);
SUITE_ADD_TEST(suite, should_get_files_number);
SUITE_ADD_TEST(suite, should_get_system_info);
return suite;
}
int all_tests()
{
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
CuSuiteAddSuite(suite, test_suite());
CuSuiteRun(suite);
CuSuiteSummary(suite, output);
CuSuiteDetails(suite, output);
printf("%s\n", output->buffer);
CuStringDelete(output);
CuSuiteDelete(suite);
return suite->failCount;
}
int main()
{
struct sockaddr_in addr;
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock < 0)
{
perror("socket");
exit(1);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(3425); // или любой другой порт...
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
perror("connect");
exit(2);
}
// send(sock, message, sizeof(message), 0);
//recv(sock, buf, sizeof(message), 0);
// printf(buf);
int status = 1;
status = all_tests();
close(sock);
return status;
}