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

Annotation of /lbbs/src/test_file_loader.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri May 16 12:22:35 2025 UTC (10 months ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Add file_loader

1 sysadm 1.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    
22     const char *files[] = {
23     "../data/welcome.txt",
24     "../data/copyright.txt",
25     "../data/register.txt",
26     "../data/license.txt",
27     "../data/login_error.txt"};
28    
29     int files_cnt = 5;
30    
31     int main(int argc, char *argv[])
32     {
33     int ret;
34     int file_loader_pool_size = 2;
35     int i;
36     const FILE_MMAP *p_file_mmap;
37    
38     if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
39     {
40     printf("Open log error\n");
41     return -1;
42     }
43    
44     log_std_redirect(STDOUT_FILENO);
45     log_err_redirect(STDERR_FILENO);
46    
47     ret = file_loader_init(file_loader_pool_size);
48     if (ret < 0)
49     {
50     printf("file_loader_init() error (%d)\n", ret);
51     return ret;
52     }
53    
54     ret = file_loader_init(file_loader_pool_size);
55     if (ret == 0)
56     {
57     printf("Rerun file_loader_init() error\n");
58     }
59    
60     printf("Testing #1\n");
61    
62     for (i = 0; i < file_loader_pool_size; i++)
63     {
64     if (load_file_mmap(files[i]) < 0)
65     {
66     printf("Load file %s error\n", files[i]);
67     }
68     }
69    
70     for (i = 0; i < file_loader_pool_size; i++)
71     {
72     if ((p_file_mmap = get_file_mmap(files[i])) == NULL)
73     {
74     printf("Get file mmap %s error\n", files[i]);
75     }
76     else
77     {
78     printf("File: %s size: ", files[i]);
79     printf("size: %ld lines: %ld\n", p_file_mmap->size, p_file_mmap->line_total);
80     }
81     }
82    
83     for (i = 0; i < file_loader_pool_size; i++)
84     {
85     if (unload_file_mmap(files[i]) < 0)
86     {
87     printf("Unload file %s error\n", files[i]);
88     }
89     }
90    
91     printf("Testing #2\n");
92    
93     for (i = 0; i < files_cnt; i++)
94     {
95     if (i >= file_loader_pool_size)
96     {
97     if (unload_file_mmap(files[i - file_loader_pool_size]) < 0)
98     {
99     printf("Unload file %s error\n", files[i]);
100     }
101     }
102    
103     if (load_file_mmap(files[i]) < 0)
104     {
105     printf("Load file %s error\n", files[i]);
106     }
107     }
108    
109     printf("Testing #3\n");
110    
111     for (i = 0; i < files_cnt; i++)
112     {
113     if ((p_file_mmap = get_file_mmap(files[i])) == NULL)
114     {
115     printf("Get file mmap %s error\n", files[i]);
116     }
117     else
118     {
119     printf("File: %s size: ", files[i]);
120     printf("size: %ld lines: %ld\n", p_file_mmap->size, p_file_mmap->line_total);
121     }
122     }
123    
124     file_loader_cleanup();
125     file_loader_cleanup();
126    
127     log_end();
128    
129     return 0;
130     }

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