-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
165 lines (126 loc) · 3.78 KB
/
main.c
File metadata and controls
165 lines (126 loc) · 3.78 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <json-glib/json-gobject.h>
#include "log.h"
#include "test.h"
#include "datetime.h"
#include "ini.h"
#include "md5.h"
#include "netutils.h"
#include "string_utils.h"
void test_ini()
{
ini_t *config = ini_load("config.ini");
const char *name = ini_get(config, "owner", "name");
if (name) {
log_debug("name: %s", name);
}
const char *server = "default";
int port = 80;
ini_sget(config, "database", "server", NULL, &server);
ini_sget(config, "database", "port", "%d", &port);
log_debug("server: %s:%d", server, port);
}
void datetime_test()
{
char szDate[MAX_INPUT];
log_debug("%s", now(szDate, MAX_INPUT));
log_debug("%s", today(szDate, MAX_INPUT));
func1();
char buf[MAX_INPUT];
getcwd(buf,sizeof(buf));
log_debug("current working directory: %s", buf);
log_debug("hour ==> %d", hour());
int nDiffDay = -3;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = -2;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = -1;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = 0;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = 1;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = 2;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
nDiffDay = 3;
log_debug("diffday %d ==> %s", nDiffDay, diffday(szDate, nDiffDay, MAX_INPUT));
}
void test_md5()
{
int ret;
const char *file_path = "config.ini";
char md5_str[MD5_STR_LEN + 1];
const char *test_str = "gchinaran@gmail.com";
// test file md5
ret = Compute_file_md5(file_path, md5_str);
if (0 == ret)
{
log_debug("[file - %s] md5 value ==> %s", file_path, md5_str);
}
// test string md5
Compute_string_md5((unsigned char *)test_str, strlen(test_str), md5_str);
log_debug("[string - %s] md5 value ==> %s", test_str, md5_str);
}
void test_ip_address()
{
char szIP[MAX_INPUT];
int nRet = get_local_ip("en0", szIP, MAX_INPUT);
log_debug("%s", szIP);
}
void uuid_test()
{
gchar* pszUuid = g_uuid_string_random();
log_debug("uuid ==> %s", pszUuid);
g_free(pszUuid);
}
void string_test()
{
gchar szSrc[] = "870b5a59-c840-4164-9b5f-69003f034b50";
gchar szDst[MAX_INPUT];
log_debug("%s", string_replace(szSrc, szDst, MAX_INPUT, "-", ""));
log_debug("%d", is_empty_string(NULL));
log_debug("%d", is_empty_string(""));
log_debug("%d", is_empty_string("123"));
}
void test_json()
{
JsonParser* parser;
JsonNode* root;
GError* error;
parser = json_parser_new ();
error = NULL;
const gchar* test_base_object_data = "{ \"text\" : \"hello, world!\", \"foo\" : null, \"blah\" : 47, \"double\" : 42.47 }";
json_parser_load_from_data(parser, test_base_object_data, -1, &error);
root = json_parser_get_root(parser);
log_debug("%s", test_base_object_data);
JsonReader *reader = json_reader_new (json_parser_get_root(parser));
json_reader_read_member(reader, "text");
const gchar* pszText = json_reader_get_string_value (reader);
log_debug("%s", pszText);
g_object_unref(reader);
g_object_unref(parser);
json_node_free(root);
}
int main()
{
log_debug("Hello World!");
datetime_test();
test_ini();
test_md5();
test_ip_address();
uuid_test();
string_test();
test_json();
log_debug("FXXK");
return 0;
}