OSDN Git Service

2019/02/14(Thr) 22:08
[drdeamon64/drdeamon64.git] / libgoblin / test_libgoblin_srcfile.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_TEST_LIBGOBLIN_SRCFILE
38 #include"drd64_libgoblin.h"
39 #include"test_libgoblin.h"
40
41
42 /* SrcFile_DispenseSrcFile() & FreeSrcFile() *****************/
43 /*--------------------------------------------------------------------*/
44 typedef struct  {
45         char    str_filename[128];
46         DWord   dw_hash;
47 } SrcFile_TestData;
48
49 void Test_SrcFile_DispenseFree_test00_003( void )
50 {
51         int             i_cnt;
52         int             i_len;
53         int             i_pos;
54         int             i_result;
55         LibGoblin_SrcFile       *p_srcfile;
56         SrcFile_TestData        *p_test;
57         SrcFile_TestData        *p_now;
58
59         p_test  = (SrcFile_TestData *)malloc( sizeof( SrcFile_TestData ) * 500 );
60         CU_ASSERT( NULL != p_test );
61
62         memset( p_test, 0x00, ( sizeof( SrcFile_TestData ) * 500 ) );
63
64         i_len   = 3;
65         p_now   = p_test;
66         for( i_cnt = 0; i_cnt < 500; i_cnt++, p_now++ ) {
67                 for( i_pos = 0; i_pos < i_len; i_pos++ )        {
68                         p_now->str_filename[i_pos]      = 'a' + (random() % 26);
69                 }
70                 p_now->str_filename[i_pos + 0]  = '.';
71                 p_now->str_filename[i_pos + 1]  = 'c';
72                 p_now->str_filename[i_pos + 2]  = '\0';
73
74                 i_len++;
75                 if( 100 == i_len )      { i_len = 3; }
76
77                 p_now->dw_hash  = Common_CalcDJBhash( p_now->str_filename);
78         }
79
80         i_result        = SrcFile_Init();
81         CU_ASSERT( 0x00 == i_result );
82
83         p_now   = p_test;
84         for( i_cnt = 0; i_cnt < 500; i_cnt++, p_now++ ) {
85                 p_srcfile       = SrcFile_DispenseSrcFile( p_now->str_filename );
86                 CU_ASSERT( NULL != p_srcfile );
87         }
88
89         p_now   = p_test;
90         for( i_cnt = 0; i_cnt < 500; i_cnt++, p_now++ ) {
91                 p_srcfile       = SrcFile_GetSrcFile( i_cnt );
92                 CU_ASSERT( NULL != p_srcfile );
93                 CU_ASSERT( i_cnt == p_srcfile->i_id );
94                 CU_ASSERT( p_now->dw_hash == p_srcfile->dw_hash );
95         }
96
97         for( i_cnt = 500; i_cnt > 0; i_cnt-- )  {
98                 p_srcfile       = SrcFile_GetSrcFile( i_cnt - 1 );
99                 SrcFile_FreeSrcFile( p_srcfile );
100                 CU_ASSERT( -0x01 == p_srcfile->i_id );
101         }
102         
103         i_result        = SrcFile_Term();
104         CU_ASSERT( 0x00 == i_result );
105
106         return;
107 }
108
109
110 /* SrcFile_AllocSrcFile() & FreeSrcFile() *****************/
111 /*--------------------------------------------------------------------*/
112 void Test_SrcFile_AllocFree_test00_002( void )
113 {
114         int             i_cnt;
115         int             i_result;
116         LibGoblin_SrcFile       *p_srcfile;
117
118         i_result        = SrcFile_Init();
119         CU_ASSERT( 0x00 == i_result );
120
121         for( i_cnt = 0; i_cnt < 300; i_cnt++ )  {
122                 p_srcfile       = SrcFile_AllocSrcFile();
123                 CU_ASSERT( NULL != p_srcfile );
124                 CU_ASSERT( i_cnt == p_srcfile->i_id );
125         }
126
127         for( i_cnt = 0; i_cnt < 32; i_cnt ++ )  {
128                 p_srcfile       = NULL;
129                 p_srcfile       = SrcFile_GetSrcFile( (i_cnt * 8) );
130                 CU_ASSERT( NULL != p_srcfile );
131
132                 i_result        = SrcFile_FreeSrcFile( p_srcfile );
133                 CU_ASSERT( 0x00 == i_result );
134         }
135
136         for( i_cnt = 0; i_cnt < 32; i_cnt++ )   {
137                 p_srcfile       = NULL;
138                 p_srcfile       = SrcFile_AllocSrcFile();
139                 CU_ASSERT( NULL != p_srcfile );
140                 CU_ASSERT( (i_cnt * 8) == p_srcfile->i_id );
141         }
142
143         for( i_cnt = 0; i_cnt < 300; i_cnt++ )  {
144                 p_srcfile       = NULL;
145                 p_srcfile       = SrcFile_GetSrcFile( i_cnt );
146                 CU_ASSERT( NULL != p_srcfile );
147
148                 i_result        = SrcFile_FreeSrcFile( p_srcfile );
149                 CU_ASSERT( 0x00 == i_result );
150         }
151
152         p_srcfile       = SrcFile_GetSrcFile( 0 );
153         CU_ASSERT( NULL == p_srcfile );
154
155         i_result        = SrcFile_Term();
156         CU_ASSERT( 0x00 == i_result );
157
158         return;
159 }
160
161
162 /* EOF of drd64_.c ----------------------------------- */
163 /*--------------------------------------------------------------------*/
164 void Test_SrcFile_AllocFree_test00_001( void )
165 {
166         int             i_result;
167         LibGoblin_SrcFile       *p_srcfile;
168
169         i_result        = SrcFile_Init();
170         CU_ASSERT( 0x00 == i_result );
171
172         p_srcfile       = SrcFile_AllocSrcFile();
173         CU_ASSERT( NULL != p_srcfile );
174
175         i_result        = SrcFile_FreeSrcFile( p_srcfile );
176         CU_ASSERT( 0x00 == i_result );
177
178         i_result        = SrcFile_Term();
179         CU_ASSERT( 0x00 == i_result );
180
181         return;
182 }
183
184
185 /* SrcFile_Init() & Term() ****************************************/
186 /*--------------------------------------------------------------------*/
187 void Test_SrcFile_InitTerm_test00_001( void )
188 {
189         int             i_result;
190
191         i_result        = SrcFile_Init();
192         CU_ASSERT( 0x00 == i_result );
193
194         i_result        = SrcFile_Term();
195         CU_ASSERT( 0x00 == i_result );
196
197         return;
198 }
199
200
201 /*----------------------------------------------------------------------
202 ----------------------------------------------------------------------*/
203 DRD64_TEST_LIBGOBLIN_SRCFILE_EXTERN
204 int
205         Test_LibGoblin_SrcFile(
206                 void )
207 {
208         CU_pSuite       pt_goblin;
209
210         pt_goblin       = CU_add_suite( "LibGoblin_SrcFile", NULL, NULL );
211
212         CU_add_test( pt_goblin, "SrcFile_InitTerm_test00_001",
213                                                                  Test_SrcFile_InitTerm_test00_001 );
214         CU_add_test( pt_goblin, "SrcFile_AllocFree_test00_001",
215                                                                  Test_SrcFile_AllocFree_test00_001 );
216         CU_add_test( pt_goblin, "SrcFile_AllocFree_test00_001",
217                                                                  Test_SrcFile_AllocFree_test00_002 );
218         CU_add_test( pt_goblin, "SrcFile_DispenseFree_test00_001",
219                                                                  Test_SrcFile_DispenseFree_test00_003 );
220
221         return 0x00;
222 }
223
224
225 /* EOF of drd64_.c ----------------------------------- */