1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
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.
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.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_TEST_LIBEDITTEXT_UNDOINFO
38 #include"test_libedittext.h"
39 #include"drd64_libedittext.h"
42 /* LibEditText_UndoInfo_Init/Term *****************************************/
43 /*--------------------------------------------------------------------*/
44 void Test_LibEditText_UndoInfo_SetUndoInfo_test00_001(void)
50 LibEditText_TextInfo *p_tinfo;
52 i_result = LibEditText_Init();
53 CU_ASSERT( 0x00 == i_result );
55 i_tinfoid = LibEditText_CreateTextFile( "../testdata", NULL );
56 CU_ASSERT( 0x00 == i_result );
58 i_curid = LibEditText_AllocCursor( i_tinfoid, 1 );
59 CU_ASSERT( 0x00 <= i_curid );
61 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
62 CU_ASSERT( NULL != p_tinfo );
65 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
66 0, 0, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'A', NULL, 1 );
67 CU_ASSERT( 0x00 == i_result );
69 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
71 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
72 0, 1, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'B', NULL, 1 );
73 CU_ASSERT( 0x00 == i_result );
75 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
77 //p_tinfo->dw_undo_line = 100;
78 //p_tinfo->dw_undo_pos = 257;
80 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
81 100, 257, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'C', NULL, 1 );
82 CU_ASSERT( 0x00 == i_result );
84 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
85 0, 3, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'D', NULL, 1 );
86 CU_ASSERT( 0x00 == i_result );
88 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
90 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
91 0, 1, LIBEDITTEXT_UNDOCMD_INSERTSTRING, 0x00, (Byte *)"koinec", 6 );
92 CU_ASSERT( 0x00 == i_result );
94 //p_tinfo->dw_undo_pos = 50;
96 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
97 0, 50, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
98 CU_ASSERT( 0x00 == i_result );
100 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
101 5, 50, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
102 CU_ASSERT( 0x00 == i_result );
104 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
105 5, 30, LIBEDITTEXT_UNDOCMD_INSERTLINE, 0x00, NULL, 0 );
106 CU_ASSERT( 0x00 == i_result );
108 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
110 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
111 6, 0, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'E', NULL, 1 );
112 CU_ASSERT( 0x00 == i_result );
114 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
115 3, 0, LIBEDITTEXT_UNDOCMD_DELETELINE, 0x00, NULL, 0 );
116 CU_ASSERT( 0x00 == i_result );
118 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
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 );
125 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
127 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
128 3, 5, LIBEDITTEXT_UNDOCMD_INSERTCHAR, 'E', NULL, 1 );
129 CU_ASSERT( 0x00 == i_result );
131 i_result = LibEditText_UndoInfo_SetUndoInfo( p_tinfo,
132 0, 0, LIBEDITTEXT_UNDOCMD_DELETECHAR, 'Z', NULL, 1 );
133 CU_ASSERT( 0x00 == i_result );
135 LibEditText_UndoInfo_CommitUndo( p_tinfo, 0x00 );
138 i_result = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT, "Undo_SetUndoInfo - test 00-001");
139 CU_ASSERT( 0x00 == i_result );
141 i_result = LibEditText_FreeCursor( i_tinfoid, i_curid );
142 CU_ASSERT( 0x00 == i_result );
144 i_result = LibEditText_CloseFile( i_tinfoid );
145 CU_ASSERT( 0x00 == i_result );
147 i_result = LibEditText_Term();
148 CU_ASSERT( 0x00 == i_result );
154 /* LibEditText_UndoInfo_Set/ReadDiffValue *****************************/
155 /*--------------------------------------------------------------------*/
156 void Test_LibEditText_UndoInfo_SetReadDiffValue_test00_001(void)
165 memset( pb_ptr, 0x00, 256 );
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 );
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 );
177 memset( pb_ptr, 0x00, 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 );
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 );
191 memset( pb_ptr, 0x00, 256 );
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 );
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 );
205 memset( pb_ptr, 0x00, 256 );
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 );
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 );
219 memset( pb_ptr, 0x00, 256 );
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 );
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 );
233 memset( pb_ptr, 0x00, 256 );
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 );
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 );
247 memset( pb_ptr, 0x00, 256 );
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 );
253 dw_value = 2147483647;
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 );
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 );
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 );
278 /*----------------------------------------------------------------------
279 ----------------------------------------------------------------------*/
280 DRD64_TEST_LIBEDITTEXT_UNDOINFO_EXTERN
282 Test_LibEditText_Undo(
285 CU_pSuite pt_edittext;
287 pt_edittext = CU_add_suite( "LibEditText_Undo", NULL, NULL );
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 );
299 /* EOF of drd64_.c ----------------------------------- */