OSDN Git Service

* [libintel64asm] Create Test Binary File.
[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        = LibBrownie_Init();
50         CU_ASSERT( 0x00 == i_result );
51
52         i_result        = BinaryFile_Init();
53         CU_ASSERT( 0x00 == i_result );
54
55         p_binfile       = BinaryFile_AllocBinaryFile();
56         CU_ASSERT( NULL != p_binfile );
57
58         i_result        = BinaryFile_FreeBinaryFile( p_binfile );
59         CU_ASSERT( 0x00 == i_result );
60
61         i_result        = BinaryFile_Term();
62         CU_ASSERT( 0x00 == i_result );
63
64         LibBrownie_Term();
65
66         return;
67 }
68
69
70 /*--------------------------------------------------------------------*/
71 void Test_BinaryFile_AllocFree_test00_002( void )
72 {
73         int             i_cnt;
74         int             i_result;
75         LibGoblin_BinaryFile    *p_binfile;
76
77         i_result        = LibBrownie_Init();
78         CU_ASSERT( 0x00 == i_result );
79
80         i_result        = BinaryFile_Init();
81         CU_ASSERT( 0x00 == i_result );
82
83
84         for( i_cnt = 0; i_cnt < 128; i_cnt++ )  {
85                 p_binfile       = BinaryFile_AllocBinaryFile();
86                 CU_ASSERT( NULL != p_binfile );
87                 CU_ASSERT( i_cnt == p_binfile->i_id );
88         }
89
90         for( i_cnt = 0; i_cnt < 128; i_cnt += 8 )       {
91                 p_binfile       = NULL;
92                 p_binfile       = BinaryFile_GetBinaryFile( i_cnt );
93                 CU_ASSERT( NULL != p_binfile );
94
95                 i_result        = BinaryFile_FreeBinaryFile( p_binfile );
96                 CU_ASSERT( 0x00 == i_result );
97         }
98
99         for( i_cnt = 0; i_cnt < 16; i_cnt++ )   {
100                 p_binfile       = NULL;
101                 p_binfile       = BinaryFile_AllocBinaryFile();
102                 CU_ASSERT( NULL != p_binfile );
103                 CU_ASSERT( (i_cnt * 8) == p_binfile->i_id );
104         }
105
106         for( i_cnt = 0; i_cnt < 128; i_cnt++ )  {
107                 p_binfile       = NULL;
108                 p_binfile       = BinaryFile_GetBinaryFile( i_cnt );
109                 CU_ASSERT( NULL != p_binfile );
110
111                 i_result        = BinaryFile_FreeBinaryFile( p_binfile );
112                 CU_ASSERT( 0x00 == i_result );
113         }
114
115         p_binfile       = BinaryFile_GetBinaryFile( 0 );
116         CU_ASSERT( NULL == p_binfile );
117
118         i_result        = BinaryFile_Term();
119         CU_ASSERT( 0x00 == i_result );
120
121         LibBrownie_Term();
122
123         return;
124 }
125
126
127 /* BinaryFile_Init() & Term() ****************************************/
128 /*--------------------------------------------------------------------*/
129 void Test_BinaryFile_InitTerm_test00_001( void )
130 {
131         int             i_result;
132
133         i_result        = LibBrownie_Init();
134         CU_ASSERT( 0x00 == i_result );
135
136         i_result        = BinaryFile_Init();
137         CU_ASSERT( 0x00 == i_result );
138
139         i_result        = BinaryFile_Term();
140         CU_ASSERT( 0x00 == i_result );
141
142         LibBrownie_Term();
143
144         return;
145 }
146
147
148 /*----------------------------------------------------------------------
149 ----------------------------------------------------------------------*/
150 DRD64_TEST_LIBGOBLIN_BINARYFILE_EXTERN
151 int
152         Test_LibGoblin_BinaryFile(
153                 void )
154 {
155         CU_pSuite       pt_goblin;
156
157         pt_goblin       = CU_add_suite( "LibGoblin_BinaryFile", NULL, NULL );
158
159         CU_add_test( pt_goblin, "BinaryFile_InitTerm_test00_001",
160                                                                  Test_BinaryFile_InitTerm_test00_001 );
161         CU_add_test( pt_goblin, "BinaryFile_AllocFree_test00_001",
162                                                                  Test_BinaryFile_AllocFree_test00_001 );
163         CU_add_test( pt_goblin, "BinaryFile_AllocFree_test00_002",
164                                                                  Test_BinaryFile_AllocFree_test00_002 );
165
166
167         return 0x00;
168 }
169
170
171 /* EOF of drd64_.c ----------------------------------- */