/[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.2 - (show annotations)
Sat May 17 05:54:42 2025 UTC (10 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +47 -31 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_file_shm;
39
40 if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
41 {
42 printf("Open log error\n");
43 return -1;
44 }
45
46 log_std_redirect(STDOUT_FILENO);
47 log_err_redirect(STDERR_FILENO);
48
49 ret = file_loader_init();
50 if (ret < 0)
51 {
52 printf("file_loader_init() error (%d)\n", ret);
53 return ret;
54 }
55
56 ret = file_loader_init();
57 if (ret == 0)
58 {
59 printf("Rerun file_loader_init() error\n");
60 }
61
62 printf("Testing #1\n");
63
64 for (i = 0; i < files_cnt; i++)
65 {
66 if (load_file_shm(files[i]) < 0)
67 {
68 printf("Load file %s error\n", files[i]);
69 }
70 }
71
72 for (i = 0; i < files_cnt; i++)
73 {
74 if ((p_file_shm = get_file_shm(files[i])) == NULL)
75 {
76 printf("Get file shm %s error\n", files[i]);
77 }
78 else
79 {
80 printf("File: %s size: %ld lines: %ld\n", files[i], *((size_t *)p_file_shm), *((size_t *)(p_file_shm + sizeof(size_t))));
81
82 if (shmdt(p_file_shm) == -1)
83 {
84 log_error("shmdt() error (%d)\n", errno);
85 }
86 }
87 }
88
89 printf("Testing #2\n");
90
91 for (i = 0; i < files_cnt; i++)
92 {
93 if (unload_file_shm(files[i]) < 0)
94 {
95 printf("Unload file %s error\n", files[i]);
96 }
97 }
98
99 for (i = 0; i < files_cnt; i++)
100 {
101 if (load_file_shm(files[i]) < 0)
102 {
103 printf("Load file %s error\n", files[i]);
104 }
105 }
106
107 printf("Testing #3\n");
108
109 for (i = 0; i < files_cnt; i++)
110 {
111 if (i % 2 == 0)
112 {
113 if (unload_file_shm(files[i]) < 0)
114 {
115 printf("Unload file %s error\n", files[i]);
116 }
117 }
118 }
119
120 for (i = 0; i < files_cnt; i++)
121 {
122 if (i % 2 != 0)
123 {
124 if ((p_file_shm = get_file_shm(files[i])) == NULL)
125 {
126 printf("Get file shm %s error\n", files[i]);
127 }
128 else
129 {
130 printf("File: %s size: %ld lines: %ld\n", files[i], *((size_t *)p_file_shm), *((size_t *)(p_file_shm + sizeof(size_t))));
131
132 if (shmdt(p_file_shm) == -1)
133 {
134 log_error("shmdt() error (%d)\n", errno);
135 }
136 }
137 }
138 }
139
140 file_loader_cleanup();
141 file_loader_cleanup();
142
143 log_end();
144
145 return 0;
146 }

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