OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / libedittext / test_libedittext_undoinfo.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_LIBEDITTEXT_UNDOINFO
38 #include"test_libedittext.h"
39 #include"drd64_libedittext.h"
40
41
42 /* LibEditText_UndoInfo_Init/Term *****************************************/
43 /*--------------------------------------------------------------------*/
44 void Test_LibEditText_UndoInfo_SetUndoInfo_test00_001(void)
45 {
46         
47         int     i_result;
48         int             i_tinfoid;
49         int             i_curid;
50         LibEditText_TextInfo    *p_tinfo;
51
52         i_result        = LibEditText_Init();
53         CU_ASSERT( 0x00 == i_result );
54
55         i_tinfoid       = LibEditText_CreateTextFile( "../testdata", NULL );
56         CU_ASSERT( 0x00 == i_result );
57
58         i_curid = LibEditText_AllocCursor( i_tinfoid, 1 );
59         CU_ASSERT( 0x00 <= i_curid );
60
61         p_tinfo         = LibEditText_System_GetTextInfo( i_tinfoid );
62         CU_ASSERT( NULL != p_tinfo );
63
64
65         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
66                                                 0, 0, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'A', NULL, 1 );
67         CU_ASSERT( 0x00 == i_result );
68
69         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
70
71         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
72                                                 0, 1, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'B', NULL, 1 );
73         CU_ASSERT( 0x00 == i_result );
74
75         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
76
77         //p_tinfo->dw_undo_line = 100;
78         //p_tinfo->dw_undo_pos  = 257;
79
80         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
81                                                 100, 257, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'C', NULL, 1 );
82         CU_ASSERT( 0x00 == i_result );
83
84         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
85                                                 0, 3, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'D', NULL, 1 );
86         CU_ASSERT( 0x00 == i_result );
87
88         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
89
90         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
91                                                 0, 1, LIBEDITTEXT_UNDOCMD_INSERTSTRING, 0x00, (Byte *)"koinec", 6 );
92         CU_ASSERT( 0x00 == i_result );
93
94         //p_tinfo->dw_undo_pos  = 50;
95
96         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
97                                                 0, 50, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
98         CU_ASSERT( 0x00 == i_result );
99
100         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
101                                                 5, 50, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
102         CU_ASSERT( 0x00 == i_result );
103
104         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
105                                                 5, 30, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
106         CU_ASSERT( 0x00 == i_result );
107
108         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
109
110         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
111                                                 6, 0, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'E', NULL, 1 );
112         CU_ASSERT( 0x00 == i_result );
113
114         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
115                                                 3, 0, LIBEDITTEXT_UNDOCMD_DELETELINE, 0x00, NULL, 0 );
116         CU_ASSERT( 0x00 == i_result );
117
118         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
119
120         //p_tinfo->dw_undo_pos  = 1000;
121         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
122                                                 3, 100, LIBEDITTEXT_UNDOCMD_DELETESTRING, 0x00, (Byte *)"koinec", 6 );
123         CU_ASSERT( 0x00 == i_result );
124
125         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
126
127         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
128                                                 3, 5, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'E', NULL, 1 );
129         CU_ASSERT( 0x00 == i_result );
130
131         i_result        = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
132                                                 0, 0, LIBEDITTEXT_UNDOCMD_DELETECHAR, 'Z', NULL, 1 );
133         CU_ASSERT( 0x00 == i_result );
134
135         LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
136
137
138         i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT, "Undo_SetUndoInfo - test 00-001");
139         CU_ASSERT( 0x00 == i_result );
140
141         i_result        = LibEditText_FreeCursor( i_tinfoid, i_curid );
142         CU_ASSERT( 0x00 == i_result );
143
144         i_result        = LibEditText_CloseFile( i_tinfoid );
145         CU_ASSERT( 0x00 == i_result );
146         
147         i_result        = LibEditText_Term();
148         CU_ASSERT( 0x00 == i_result );
149
150         return;
151 }
152
153
154 /* LibEditText_UndoInfo_Set/ReadDiffValue *****************************/
155 /*--------------------------------------------------------------------*/
156 void Test_LibEditText_UndoInfo_SetReadDiffValue_test00_001(void)
157 {
158         Byte    b_data[256];
159         Byte    b_flag;
160         Byte    *pb_ptr;
161         DWord   dw_value;
162         
163         // 0 ---
164         pb_ptr  = b_data;
165         memset( pb_ptr, 0x00, 256 );
166         dw_value        = 123;
167         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 123, dw_value );
168         CU_ASSERT( 0x00 == b_flag );
169         CU_ASSERT( pb_ptr == (Byte *)b_data );
170
171         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, 0x00, 0x00 );
172         CU_ASSERT( pb_ptr == (Byte *)b_data );
173         CU_ASSERT( 123 == dw_value );
174
175         // +1 ---
176         pb_ptr  = b_data;
177         memset( pb_ptr, 0x00, 256 );
178         dw_value        = 256;
179         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 257, dw_value );
180         CU_ASSERT( 0x01 == b_flag );
181         CU_ASSERT( pb_ptr - 1 == (Byte *)b_data );
182
183         dw_value        = 257;
184         pb_ptr  = b_data;
185         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
186         CU_ASSERT( pb_ptr - 1 == (Byte *)b_data );
187         CU_ASSERT( dw_value == 256 );
188
189         // -127 ---
190         pb_ptr  = b_data;
191         memset( pb_ptr, 0x00, 256 );
192         dw_value        = 127;
193         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 0, dw_value );
194         CU_ASSERT( 0x01 == b_flag );
195         CU_ASSERT( pb_ptr - 1 == (Byte *)b_data );
196
197         dw_value        = 0;
198         pb_ptr  = b_data;
199         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
200         CU_ASSERT( pb_ptr - 1 == (Byte *)b_data );
201         CU_ASSERT( dw_value == 127 );
202
203         // -128 ---
204         pb_ptr  = b_data;
205         memset( pb_ptr, 0x00, 256 );
206         dw_value        = 128;
207         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 0, dw_value );
208         CU_ASSERT( 0x02 == b_flag );
209         CU_ASSERT( pb_ptr - 2 == (Byte *)b_data );
210
211         dw_value        = 0;
212         pb_ptr  = b_data;
213         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
214         CU_ASSERT( pb_ptr - 2 == (Byte *)b_data );
215         CU_ASSERT( dw_value == 128 );
216
217         // +32767 ---
218         pb_ptr  = b_data;
219         memset( pb_ptr, 0x00, 256 );
220         dw_value        = 0;
221         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 32767, dw_value );
222         CU_ASSERT( 0x02 == b_flag );
223         CU_ASSERT( pb_ptr - 2 == (Byte *)b_data );
224
225         dw_value        = 32767;
226         pb_ptr  = b_data;
227         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
228         CU_ASSERT( pb_ptr - 2 == (Byte *)b_data );
229         CU_ASSERT( dw_value == 0 );
230
231         // -32768 ---
232         pb_ptr  = b_data;
233         memset( pb_ptr, 0x00, 256 );
234         dw_value        = 32768;
235         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 0, dw_value );
236         CU_ASSERT( 0x03 == b_flag );
237         CU_ASSERT( pb_ptr - 4 == (Byte *)b_data );
238
239         dw_value        = 0;
240         pb_ptr  = b_data;
241         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
242         CU_ASSERT( pb_ptr - 4 == (Byte *)b_data );
243         CU_ASSERT( dw_value == 32768 );
244
245         // +2147483647 ---
246         pb_ptr  = b_data;
247         memset( pb_ptr, 0x00, 256 );
248         dw_value        = 0;
249         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 2147483647, dw_value );
250         CU_ASSERT( 0x03 == b_flag );
251         CU_ASSERT( pb_ptr - 4 == (Byte *)b_data );
252
253         dw_value        = 2147483647;
254         pb_ptr  = b_data;
255         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
256         CU_ASSERT( pb_ptr - 4 == (Byte *)b_data );
257         CU_ASSERT( dw_value == 0 );
258
259         // -2147483648 ---
260         pb_ptr  = b_data;
261         memset( pb_ptr, 0x00, 256 );
262         dw_value        = 2147483650;
263         b_flag  = LibEditText_UndoInfo_SetDiffValue( &pb_ptr, 2, dw_value );
264         CU_ASSERT( 0x01 == b_flag );
265         CU_ASSERT( 0x80 == b_data[0] );
266         CU_ASSERT( pb_ptr - 9 == (Byte *)b_data );
267
268         dw_value        = 2;
269         pb_ptr  = b_data;
270         pb_ptr  = LibEditText_UndoInfo_ReadDiffValue( &dw_value, pb_ptr, b_flag, 0x00 );
271         CU_ASSERT( pb_ptr - 9 == (Byte *)b_data );
272         CU_ASSERT( dw_value == 2147483650 );
273
274         return;
275 }
276
277
278 /*----------------------------------------------------------------------
279 ----------------------------------------------------------------------*/
280 DRD64_TEST_LIBEDITTEXT_UNDOINFO_EXTERN
281 int
282         Test_LibEditText_Undo(
283                 void )
284 {
285         CU_pSuite       pt_edittext;
286
287         pt_edittext     = CU_add_suite( "LibEditText_Undo", NULL, NULL );
288
289         CU_add_test( pt_edittext, "EditText_UndoInfo_SetReadDiffValue_test00_001",
290                                           Test_LibEditText_UndoInfo_SetReadDiffValue_test00_001 );
291         CU_add_test( pt_edittext, "EditText_UndoInfo_SetUndoInfo_test00_001",
292                                          Test_LibEditText_UndoInfo_SetUndoInfo_test00_001 );
293
294
295         return 0x00;
296 }
297
298
299 /* EOF of drd64_.c ----------------------------------- */