/[LeafOK_CVS]/lbbs/src/test_file_loader.c
ViewVC logotype

Contents of /lbbs/src/test_file_loader.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sun May 18 08:17:25 2025 UTC (10 months ago) by sysadm
Branch: MAIN
Changes since 1.3: +5 -0 lines
Content type: text/x-csrc
Refine

1 /***************************************************************************
2 file_loader.c - description
3 -------------------
4 Copyright : (C) 2004-2025 by Leaflet
5 Email : leaflet@leafok.com
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17 #include "file_loader.h"
18 #include "log.h"
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <errno.h>
22 #include <sys/shm.h>
23
24 const char *files[] = {
25 "../data/welcome.txt",
26 "../data/copyright.txt",
27 "../data/register.txt",
28 "../data/license.txt",
29 "../data/login_error.txt",
30 "../data/read_help.txt"};
31
32 int files_cnt = 6;
33
34 int main(int argc, char *argv[])
35 {
36 int ret;
37 int i;
38 const void *p_shm;
39 size_t data_len;
40 long line_total;
41 const void *p_data;
42 const long *p_line_offsets;
43
44 if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
45 {
46 printf("Open log error\n");
47 return -1;
48 }
49
50 log_std_redirect(STDOUT_FILENO);
51 log_err_redirect(STDERR_FILENO);
52
53 ret = file_loader_init();
54 if (ret < 0)
55 {
56 printf("file_loader_init() error (%d)\n", ret);
57 return ret;
58 }
59
60 ret = file_loader_init();
61 if (ret == 0)
62 {
63 printf("Rerun file_loader_init() error\n");
64 }
65
66 printf("Testing #1\n");
67
68 for (i = 0; i < files_cnt; i++)
69 {
70 if (load_file_shm(files[i]) < 0)
71 {
72 printf("Load file %s error\n", files[i]);
73 }
74 }
75
76 for (i = 0; i < files_cnt; i++)
77 {
78 if ((p_shm = get_file_shm(files[i], &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
79 {
80 printf("Get file shm %s error\n", files[i]);
81 }
82 else
83 {
84 printf("File: %s size: %ld lines: %ld\n", files[i], data_len, line_total);
85
86 for (int j = 0; j < line_total; j++)
87 {
88 printf("Line %d: %ld ~ %ld\n", j, p_line_offsets[j], p_line_offsets[j + 1]);
89 }
90 }
91 }
92
93 printf("Testing #2\n");
94
95 for (i = 0; i < files_cnt; i++)
96 {
97 if (unload_file_shm(files[i]) < 0)
98 {
99 printf("Unload file %s error\n", files[i]);
100 }
101 }
102
103 for (i = 0; i < files_cnt; i++)
104 {
105 if (load_file_shm(files[i]) < 0)
106 {
107 printf("Load file %s error\n", files[i]);
108 }
109 }
110
111 printf("Testing #3\n");
112
113 for (i = 0; i < files_cnt; i++)
114 {
115 if (i % 2 == 0)
116 {
117 if (unload_file_shm(files[i]) < 0)
118 {
119 printf("Unload file %s error\n", files[i]);
120 }
121 }
122 }
123
124 for (i = 0; i < files_cnt; i++)
125 {
126 if (i % 2 != 0)
127 {
128 if ((p_shm = get_file_shm(files[i], &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
129 {
130 printf("Get file shm %s error\n", files[i]);
131 }
132 else
133 {
134 printf("File: %s size: %ld lines: %ld\n", files[i], data_len, line_total);
135 }
136 }
137 }
138
139 file_loader_cleanup();
140 file_loader_cleanup();
141
142 log_end();
143
144 return 0;
145 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1