/[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.3 - (show annotations)
Sun May 18 06:56:46 2025 UTC (9 months, 4 weeks ago) by sysadm
Branch: MAIN
Changes since 1.2: +9 -15 lines
Content type: text/x-csrc
Update

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 }
87
88 printf("Testing #2\n");
89
90 for (i = 0; i < files_cnt; i++)
91 {
92 if (unload_file_shm(files[i]) < 0)
93 {
94 printf("Unload file %s error\n", files[i]);
95 }
96 }
97
98 for (i = 0; i < files_cnt; i++)
99 {
100 if (load_file_shm(files[i]) < 0)
101 {
102 printf("Load file %s error\n", files[i]);
103 }
104 }
105
106 printf("Testing #3\n");
107
108 for (i = 0; i < files_cnt; i++)
109 {
110 if (i % 2 == 0)
111 {
112 if (unload_file_shm(files[i]) < 0)
113 {
114 printf("Unload file %s error\n", files[i]);
115 }
116 }
117 }
118
119 for (i = 0; i < files_cnt; i++)
120 {
121 if (i % 2 != 0)
122 {
123 if ((p_shm = get_file_shm(files[i], &data_len, &line_total, &p_data, &p_line_offsets)) == NULL)
124 {
125 printf("Get file shm %s error\n", files[i]);
126 }
127 else
128 {
129 printf("File: %s size: %ld lines: %ld\n", files[i], data_len, line_total);
130 }
131 }
132 }
133
134 file_loader_cleanup();
135 file_loader_cleanup();
136
137 log_end();
138
139 return 0;
140 }

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