OSDN Git Service

* CreateFile: test_libedittext_lineedit.c
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Mon, 4 May 2015 21:13:12 +0000 (06:13 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Mon, 4 May 2015 21:13:12 +0000 (06:13 +0900)
include/libedittext.h
libedittext/Makefile
libedittext/drd64_libedittext_config.h
libedittext/drd64_libedittext_linectrl.c
libedittext/drd64_libedittext_lineedit.c
libedittext/drd64_libedittext_lineinfo.c
libedittext/drd64_libedittext_system.c
libedittext/test_libedittext.c
libedittext/test_libedittext.h
libedittext/test_libedittext_linectrl.c
libedittext/test_libedittext_lineedit.c [new file with mode: 0644]

index 5cd69e5..e366651 100644 (file)
@@ -70,7 +70,7 @@ LIBEDITTEXT_API_FILE
        #define LIBEDITTEXT_API_LINECTRL        extern
 #endif
 LIBEDITTEXT_API_LINECTRL
-       int LibEditText_AppendLine( int i_tinfoid, Byte *pstr_text, DWord dw_length );
+       int LibEditText_AppendLine( int i_tinfoid, char *pstr_text, DWord dw_length );
 
 
 #ifdef DRD64_SRC_LIBEDITTEXT_LINEEDIT
@@ -79,9 +79,11 @@ LIBEDITTEXT_API_LINECTRL
        #define LIBEDITTEXT_API_LINEEDIT        extern
 #endif
 LIBEDITTEXT_API_LINEEDIT
-       int LibEditText_InsertChar( int i_tinfoid, DWord dw_line, DWord dw_pos, Byte b_char );
-
-
+       int LibEditText_InsertChar_toLine(
+                       int i_tinfoid, DWord dw_line, DWord dw_pos, Byte b_char );
+LIBEDITTEXT_API_LINEEDIT
+       int LibEditText_InsertString_toLine(
+                       int i_tinfoid, DWord dw_line, DWord dw_pos, char *pstr_string );
 
 #endif /* DRD64_HEADER_DRCC_INCLUDE */
 
index 09b9428..c0dde82 100644 (file)
@@ -77,6 +77,7 @@ TEST_OBJS = \
                test_libedittext_file.o \
                test_libedittext_lineinfo.o \
                test_libedittext_linectrl.o \
+               test_libedittext_lineedit.o \
                test_libedittext_system.o
 TEST_HEADER = \
                test_libedittext.h
@@ -133,6 +134,10 @@ test_libedittext_linectrl.o: test_libedittext_linectrl.c $(HEADER) $(TEST_HEADER
        $(CC) -c -o test_libedittext_linectrl.o \
                                $(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
                                test_libedittext_linectrl.c
+test_libedittext_lineedit.o: test_libedittext_lineedit.c $(HEADER) $(TEST_HEADER)
+       $(CC) -c -o test_libedittext_lineedit.o \
+                               $(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
+                               test_libedittext_lineedit.c
 
 $(TEST_TARGET): $(TEST_OBJS) $(OBJS) $(TARGET)
        $(CC) -o $(TEST_TARGET) $(FLAGS_DEBUG) $(OBJS) $(TEST_OBJS) $(TARGET) \
index cec0bc8..0d03e75 100644 (file)
@@ -37,7 +37,7 @@ Comment:
 #ifndef DRD64_HEADER_LIBEDITTEXT_CONFIG
 #define DRD64_HEADER_LIBEDITTEXT_CONFIG
 
-#define DEBUG_TEXTINFO_OUTPUT                                          0x01
+#define DEBUG_TEXTINFO_OUTPUT                                          0x02
        /* Output TextData for Console if this value isn't 0x00 when run test_drcc program.*/
 
 
index 8cc6fa4..b229b04 100644 (file)
@@ -113,7 +113,7 @@ LIBEDITTEXT_API_LINECTRL
 int
        LibEditText_AppendLine(
                int             i_tinfoid,
-               Byte    *pstr_text,
+               char    *pstr_text,
                DWord   dw_length )
 {
        int                                             i_result;
@@ -125,7 +125,7 @@ int
 
        if( NULL == pstr_text ) { return -0x03; }
        
-       i_result        = LibEditText_LineCtrl_AppendLine( p_tinfo, pstr_text, dw_length, 0x00 );
+       i_result        = LibEditText_LineCtrl_AppendLine( p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
        
        return i_result;
 }
index c26e18e..e8ea10b 100644 (file)
@@ -63,7 +63,7 @@ int
        assert( NULL != p_line );
 
        /* Check Line Remain-Length & Swap line-buffer ---*/
-       if( p_line->dw_strlen + dw_srclen > p_line->dw_linelen )        {
+       if( p_line->dw_strlen + dw_srclen + 1 > p_line->dw_linelen )    {
                i_result        = LibEditText_LineInfo_ExpandLineBuffer(
                                                p_tinfo, p_line,
                                                dw_srclen + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE);
@@ -79,7 +79,7 @@ int
        assert( NULL != pb_pos );
 
        if( p_line->dw_strlen > dw_pos )        {
-               dw_length       = p_line->dw_strlen - dw_pos;
+               dw_length       = p_line->dw_strlen - dw_pos + 1;
                memmove( pb_pos + dw_srclen, pb_pos, dw_length ); 
        }
 
@@ -94,7 +94,7 @@ int
 ----------------------------------------------------------------------*/
 LIBEDITTEXT_API_LINEEDIT
 int
-       LibEditText_InsertChar(
+       LibEditText_InsertChar_toLine(
                int             i_tinfoid,
                DWord   dw_line,
                DWord   dw_pos,
@@ -121,4 +121,40 @@ int
 }
 
 
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBEDITTEXT_API_LINEEDIT
+int
+       LibEditText_InsertString_toLine(
+               int             i_tinfoid,
+               DWord   dw_line,
+               DWord   dw_pos,
+               char    *pstr_string )
+{
+       int                                             i_result;
+       int                                             i_len;
+       LibEditText_TextInfo    *p_tinfo;
+       LibEditText_LineInfo    *p_line;
+
+       if( 0 > i_tinfoid )             { return -0x01; }
+       p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+       if( NULL == p_tinfo     )       { return -0x02; }
+
+       /* Check Line in TextBuffer range ---*/
+       if( p_tinfo->dw_maxline <= dw_line )
+               { return -0x03; }
+
+       p_line  = LINFO(p_tinfo, dw_line);
+       if( NULL == p_line )    { return -0x03; }
+
+       i_len   = strnlen( pstr_string , 1024+1 );
+       if( 1025 == i_len )     { return -0x04; }
+
+       i_result        = LibEditText_LineEdit_InsertString(
+                                               p_tinfo, p_line, dw_pos, (Byte *)pstr_string, (DWord)i_len );
+
+       return i_result;
+}
+
+
 /* EOF of drd64_.c ----------------------------------- */
index 3e5b4f1..cea6aca 100644 (file)
@@ -79,42 +79,43 @@ void
        assert( NULL != p_dest );
        assert( NULL != p_src );
 
+       if( p_dest->dw_linelen < p_src->dw_linelen )    { return; }
+
        pb_tmpbuf       = p_tinfo->pb_text
                        + (p_tinfo->dw_bufsize - DRD64_LIBEDITTEXT_DEFAULT_COPYBUFFER);
 
        dw_tmp_linelen          = p_src->dw_linelen;
 
-       /* Copy Src to Tmp ---*/
-       dw_tmp_start            = p_src->dw_start;
-       dw_tmp_strlen           = p_src->dw_strlen;
-
-       /* memcpy */
+       /* Copy Dest to Tmp ---*/
        if( DRD64_LIBEDITTEXT_DEFAULT_COPYBUFFER < dw_tmp_linelen )     {
                LibEditText_LineInfo_MemCopy(pb_tmpbuf,
-                       (p_tinfo->pb_text + p_src->dw_start), dw_tmp_linelen );
+                       (p_tinfo->pb_text + p_dest->dw_start), dw_tmp_linelen );
        }
        else
-               { memcpy( pb_tmpbuf, (p_tinfo->pb_text + p_src->dw_start), dw_tmp_linelen ); }
+               { memcpy( pb_tmpbuf, (p_tinfo->pb_text + p_dest->dw_start), dw_tmp_linelen ); }
        
-       /* Copy Dest to Src ---*/
-       p_src->dw_start         = p_dest->dw_start;
-       p_src->dw_strlen        = p_dest->dw_strlen;
+       dw_tmp_start            = p_dest->dw_start;
+       dw_tmp_strlen           = p_dest->dw_strlen;
 
-       /* memcpy */
-       memcpy( (p_tinfo->pb_text + p_src->dw_start),
-                               (p_tinfo->pb_text + p_dest->dw_start), dw_tmp_linelen );
+       /* Copy Src to Dest ---*/
+       memcpy( (p_tinfo->pb_text + p_dest->dw_start),
+                               (p_tinfo->pb_text + p_src->dw_start), p_src->dw_linelen );
+       memset( (p_tinfo->pb_text + p_dest->dw_start + p_src->dw_linelen),
+                                               0x00, (p_dest->dw_linelen - p_src->dw_linelen) );
 
-       /* Copy Tmp to Dest ---*/
-       p_dest->dw_start        = dw_tmp_start;
-       p_dest->dw_strlen       = dw_tmp_strlen;
+       p_dest->dw_start        = p_src->dw_start;
+       p_dest->dw_strlen       = p_src->dw_strlen;
 
-       /* memcpy */
+       /* Copy Tmp to Dest ---*/
        if( DRD64_LIBEDITTEXT_DEFAULT_COPYBUFFER < dw_tmp_linelen )     {
                LibEditText_LineInfo_MemCopy(
-                       (p_tinfo->pb_text + p_dest->dw_start), pb_tmpbuf, dw_tmp_linelen );
+                       (p_tinfo->pb_text + dw_tmp_start), pb_tmpbuf, dw_tmp_linelen );
        }
        else
-               { memcpy( (p_tinfo->pb_text + p_dest->dw_start), pb_tmpbuf, dw_tmp_linelen ); }
+               { memcpy( (p_tinfo->pb_text + dw_tmp_start), pb_tmpbuf, dw_tmp_linelen ); }
+
+       p_src->dw_start         = dw_tmp_start;
+       p_src->dw_strlen        = dw_tmp_strlen;
 
        return;
 }
@@ -134,15 +135,14 @@ void
        assert( NULL != p_src );
 
        /* Copy Src to Dest ---*/
-       p_dest->dw_start        = p_src->dw_start;
        p_dest->dw_strlen       = p_src->dw_strlen;
 
        /* memcpy */
        memcpy( (p_tinfo->pb_text + p_dest->dw_start),
                                (p_tinfo->pb_text + p_src->dw_start), p_src->dw_linelen );
+       memset( (p_tinfo->pb_text + p_src->dw_start), 0x00, p_src->dw_linelen );
 
        /* Clear Src ---*/
-       p_src->dw_start         = 0;
        p_src->dw_strlen        = 0;
 
        return;
index 771f4c7..36bf957 100644 (file)
@@ -106,13 +106,21 @@ int
        }
        p_tinfo->pb_text                = pb_text;
 
-       pb_attr = (Byte *)realloc( p_tinfo->pb_attr,
+       pb_text += p_tinfo->dw_bufsize;
+       memset( pb_text, 0x00, dw_expandsize );
+
+       if( NULL != p_tinfo->pb_attr )  {
+               pb_attr = (Byte *)realloc( p_tinfo->pb_attr,
                                                (p_tinfo->dw_bufsize + dw_expandsize ) );
-       if( NULL == pb_attr )   {
-               return -0x03;
+               if( NULL == pb_attr )   {
+                       return -0x03;
+               }
+               p_tinfo->pb_attr                = pb_attr;
+
+               pb_attr += p_tinfo->dw_bufsize;
+               memset( pb_attr, 0x00, dw_expandsize );
        }
 
-       p_tinfo->pb_attr                = pb_attr;
        p_tinfo->dw_bufsize             += dw_expandsize;
 
        return 0x00;
index 9638cdf..b4c24b2 100644 (file)
@@ -52,6 +52,7 @@ int
        Test_LibEditText_File();
        Test_LibEditText_LineInfo();
        Test_LibEditText_LineCtrl();
+       Test_LibEditText_LineEdit();
 
        CU_basic_run_tests();
        CU_cleanup_registry();
index 5f5e886..e527a26 100644 (file)
@@ -42,6 +42,14 @@ Comment:
 
 
 /*---------------------------------------------------------------------*/
+#ifdef DRD64_SRC_TEST_LIBEDITTEXT_LINEEDIT
+       #define DRD64_TEST_LIBEDITTEXT_LINEEDIT_EXTERN
+#else
+       #define DRD64_TEST_LIBEDITTEXT_LINEEDIT_EXTERN  extern
+#endif
+DRD64_TEST_LIBEDITTEXT_LINEEDIT_EXTERN int Test_LibEditText_LineEdit( void );
+
+/*---------------------------------------------------------------------*/
 #ifdef DRD64_SRC_TEST_LIBEDITTEXT_LINECTRL
        #define DRD64_TEST_LIBEDITTEXT_LINECTRL_EXTERN
 #else
index 8a9485f..956452b 100644 (file)
@@ -60,7 +60,7 @@ void Test_LibEditText_API_AppendLine_test00_001(void)
 
        for( i_cnt = 1; i_cnt < 65537; i_cnt++ )        {
                i_len   = snprintf( str_testdata, 255, "%6d Dr.deamon64 libeditext testdata---\n", i_cnt);
-               i_result        = LibEditText_AppendLine( i_tinfoid, (Byte *)str_testdata, i_len);
+               i_result        = LibEditText_AppendLine( i_tinfoid, str_testdata, i_len);
                CU_ASSERT( 0x00 == i_result );
        }
 
diff --git a/libedittext/test_libedittext_lineedit.c b/libedittext/test_libedittext_lineedit.c
new file mode 100644 (file)
index 0000000..296f17a
--- /dev/null
@@ -0,0 +1,100 @@
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+                         D r . D e a m o n  6 4
+                        for INTEL64(R), AMD64(R)
+       
+   Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function: 
+Comment: 
+----------------------------------------------------------------------*/
+
+#define DRD64_SRC_TEST_LIBEDITTEXT_LINEEDIT
+#include"test_libedittext.h"
+#include"drd64_libedittext.h"
+
+
+/* LibEditText_InsertChar_toLine (API) ********************************/
+/*--------------------------------------------------------------------*/
+void Test_LibEditText_API_InsertStringChar_toLine_test00_001(void)
+{
+       int     i_result;
+       int             i_tinfoid;
+       int             i_cnt;
+       char    c_tmp;
+
+       i_result        = LibEditText_Init();
+       CU_ASSERT( 0x00 == i_result );
+
+       i_tinfoid       = LibEditText_CreateTextFile( "./testdata", NULL );
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_InsertString_toLine( i_tinfoid, 0, 0, "Line 1: \n" );
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_AppendLine( i_tinfoid, "Line 2: \n", 9);
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_AppendLine( i_tinfoid, "Line 3: \n", 5);
+       CU_ASSERT( 0x00 == i_result );
+
+       for( i_cnt = 0; i_cnt < 100; i_cnt++ )  {
+               c_tmp   = 0x30 + (i_cnt % 10);
+               //i_result      = LibEditText_InsertChar_toLine( i_tinfoid, 1, 7, c_tmp );
+               CU_ASSERT( 0x00 == i_result );
+       }
+
+       i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT );
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_Term();
+       CU_ASSERT( 0x00 == i_result );
+
+       return;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+DRD64_TEST_LIBEDITTEXT_LINEEDIT_EXTERN
+int
+       Test_LibEditText_LineEdit(
+               void )
+{
+       CU_pSuite       pt_edittext;
+
+       pt_edittext     = CU_add_suite( "LibEditText_LineEdit", NULL, NULL );
+
+       CU_add_test( pt_edittext, "EditText_API_InsertStringChar_toLine_test00_001",
+                                       Test_LibEditText_API_InsertStringChar_toLine_test00_001 );
+
+       return 0x00;
+}
+
+
+/* EOF of drd64_.c ----------------------------------- */