OSDN Git Service

2019/04/09(Tue) 20:00
[drdeamon64/drdeamon64.git] / libgoblin / test_libgoblin_binaryfile.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_BINARYFILE
38 #include"drd64_libgoblin.h"
39 #include"test_libgoblin.h"
40
41
42 /* BinaryFile_AllocBinaryFile() & FreeBinaryFile() *****************/
43 /*--------------------------------------------------------------------*/
44 void Test_BinaryFile_AllocFree_test00_001( void )
45 {
46         int             i_result;
47         LibGoblin_BinaryFile    *p_binfile;
48
49         i_result        = BinaryFile_Init();
50         CU_ASSERT( 0x00 == i_result );
51
52         p_binfile       = BinaryFile_AllocBinaryFile();
53         CU_ASSERT( NULL != p_binfile );
54
55         i_result        = BinaryFile_FreeBinaryFile( p_binfile );
56         CU_ASSERT( 0x00 == i_result );
57
58         i_result        = BinaryFile_Term();
59         CU_ASSERT( 0x00 == i_result );
60
61         return;
62 }
63
64
65 /*--------------------------------------------------------------------*/
66 void Test_BinaryFile_AllocFree_test00_002( void )
67 {
68         int             i_cnt;
69         int             i_result;
70         LibGoblin_BinaryFile    *p_binfile;
71
72         i_result        = BinaryFile_Init();
73         CU_ASSERT( 0x00 == i_result );
74
75
76         for( i_cnt = 0; i_cnt < 128; i_cnt++ )  {
77                 p_binfile       = BinaryFile_AllocBinaryFile();
78                 CU_ASSERT( NULL != p_binfile );
79                 CU_ASSERT( i_cnt == p_binfile->i_id );
80         }
81
82         for( i_cnt = 0; i_cnt < 128; i_cnt += 8 )       {
83                 p_binfile       = NULL;
84                 p_binfile       = BinaryFile_GetBinaryFile( i_cnt );
85                 CU_ASSERT( NULL != p_binfile );
86
87                 i_result        = BinaryFile_FreeBinaryFile( p_binfile );
88                 CU_ASSERT( 0x00 == i_result );
89         }
90
91         for( i_cnt = 0; i_cnt < 16; i_cnt++ )   {
92                 p_binfile       = NULL;
93                 p_binfile       = BinaryFile_AllocBinaryFile();
94                 CU_ASSERT( NULL != p_binfile );
95                 CU_ASSERT( (i_cnt * 8) == p_binfile->i_id );
96         }
97
98         for( i_cnt = 0; i_cnt < 128; i_cnt++ )  {
99                 p_binfile       = NULL;
100                 p_binfile       = BinaryFile_GetBinaryFile( i_cnt );
101                 CU_ASSERT( NULL != p_binfile );
102
103                 i_result        = BinaryFile_FreeBinaryFile( p_binfile );
104                 CU_ASSERT( 0x00 == i_result );
105         }
106
107         p_binfile       = BinaryFile_GetBinaryFile( 0 );
108         CU_ASSERT( NULL == p_binfile );
109
110         i_result        = BinaryFile_Term();
111         CU_ASSERT( 0x00 == i_result );
112
113         return;
114 }
115
116
117 /* BinaryFile_Init() & Term() ****************************************/
118 /*--------------------------------------------------------------------*/
119 void Test_BinaryFile_InitTerm_test00_001( void )
120 {
121         int             i_result;
122
123         i_result        = BinaryFile_Init();
124         CU_ASSERT( 0x00 == i_result );
125
126         i_result        = BinaryFile_Term();
127         CU_ASSERT( 0x00 == i_result );
128
129         return;
130 }
131
132
133 /*----------------------------------------------------------------------
134 ----------------------------------------------------------------------*/
135 DRD64_TEST_LIBGOBLIN_BINARYFILE_EXTERN
136 int
137         Test_LibGoblin_BinaryFile(
138                 void )
139 {
140         CU_pSuite       pt_goblin;
141
142         pt_goblin       = CU_add_suite( "LibGoblin_BinaryFile", NULL, NULL );
143
144         CU_add_test( pt_goblin, "BinaryFile_InitTerm_test00_001",
145                                                                  Test_BinaryFile_InitTerm_test00_001 );
146         CU_add_test( pt_goblin, "BinaryFile_AllocFree_test00_001",
147                                                                  Test_BinaryFile_AllocFree_test00_001 );
148         CU_add_test( pt_goblin, "BinaryFile_AllocFree_test00_002",
149                                                                  Test_BinaryFile_AllocFree_test00_002 );
150
151
152         return 0x00;
153 }
154
155
156 /* EOF of drd64_.c ----------------------------------- */