• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Virtual machine Management Terminal User Interface


Commit MetaInfo

Révisioncc3c31e30a74bc431c4436884fca75e3909999d3 (tree)
l'heure2022-08-15 21:22:44
AuteurKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Message de Log

Tested KeyVal_RegistData(), KeyVal_SearchItem(), KeyVal_RemoveData().

Change Summary

Modification

--- a/src/keyval.c
+++ b/src/keyval.c
@@ -137,12 +137,12 @@ int
137137 // Extend Item Memory ---
138138 if( p_kvinfo->i_allocs == p_kvinfo->i_used ) {
139139 i_allocs = p_kvinfo->i_allocs + KEYVAL_DEFAULT_ALLOCS;
140- p_item = (KeyVal_Item *)realloc( p_kvinfo->p_items, i_allocs );
140+ p_item = (KeyVal_Item *)realloc( p_kvinfo->p_items, sizeof( KeyVal_Item ) * i_allocs );
141141 if( NULL == p_item ) {
142142 return -0x05;
143143 }
144144
145- memset( (p_item + p_kvinfo->i_allocs), 0x00, sizeof( KeyVal_Info ) * KEYVAL_DEFAULT_ALLOCS );
145+ memset( (p_item + p_kvinfo->i_allocs), 0x00, sizeof( KeyVal_Item ) * KEYVAL_DEFAULT_ALLOCS );
146146
147147 p_kvinfo->i_allocs = i_allocs;
148148 p_kvinfo->p_items = p_item;
--- a/src/keyval.h
+++ b/src/keyval.h
@@ -46,12 +46,15 @@ typedef struct {
4646 #define KEYVAL_TYPE_DWORD 0x03
4747 #define KEYVAL_TYPE_STRING 0x04
4848 #define KEYVAL_TYPE_STRPTR 0x05
49+ #define KEYVAL_TYPE_BOOL 0x06
50+ #define KEYVAL_TYPE_BYTE 0x07
4951
5052 union {
5153 int i_val;
5254 DWord dw_val;
5355 char str_val[KEYVAL_MAXLEN_STRVAL];
5456 char *pstr_val;
57+ Byte b_val;
5558 };
5659 } KeyVal_Data;
5760
@@ -65,16 +68,43 @@ typedef struct {
6568 #define IS_KEYVAL_TYPE_DWORD_P(n) (KEYVAL_TYPE_DWORD==((n)->b_type))
6669 #define IS_KEYVAL_TYPE_STRING(n) (KEYVAL_TYPE_STRING==((n).b_type))
6770 #define IS_KEYVAL_TYPE_STRING_P(n) (KEYVAL_TYPE_STRING==((n)->b_type))
68-
69-#define KEYVAL_DATA_INT(n) (n).i_val
70-#define KEYVAL_DATA_INT_P(n) (n)->i_val
71-#define KEYVAL_DATA_DWORD(n) (n).dw_val
72-#define KEYVAL_DATA_DWORD_P(n) (n)->dw_val
73-#define KEYVAL_DATA_STR(n) (n).str_val
74-#define KEYVAL_DATA_STR_P(n) (n)->str_val
71+#define IS_KEYVAL_TYPE_STRPTR(n) (KEYVAL_TYPE_STRPTR==((n).b_type))
72+#define IS_KEYVAL_TYPE_STRPTR_P(n) (KEYVAL_TYPE_STRPTR==((n)->b_type))
73+#define IS_KEYVAL_TYPE_BOOL(n) (KEYVAL_TYPE_BOOL==((n).b_type))
74+#define IS_KEYVAL_TYPE_BOOL_P(n) (KEYVAL_TYPE_BOOL==((n)->b_type))
75+#define IS_KEYVAL_TYPE_BYTE(n) (KEYVAL_TYPE_BYTE==((n).b_type))
76+#define IS_KEYVAL_TYPE_BYTE_P(n) (KEYVAL_TYPE_BYTE==((n)->b_type))
77+
78+#define KEYVAL_DATA_INT(n) (n).i_val
79+#define KEYVAL_DATA_INT_P(n) (n)->i_val
80+#define KEYVAL_DATA_DWORD(n) (n).dw_val
81+#define KEYVAL_DATA_DWORD_P(n) (n)->dw_val
82+#define KEYVAL_DATA_STRING(n) (n).str_val
83+#define KEYVAL_DATA_STRING_P(n) (n)->str_val
84+#define KEYVAL_DATA_STRPTR(n) (n).pstr_val
85+#define KEYVAL_DATA_STRPTR_P(n) (n)->pstr_val
86+#define KEYVAL_DATA_BOOL(n) (n).b_val
87+#define KEYVAL_DATA_BOOL_P(n) (n)->b_val
88+#define KEYVAL_DATA_BYTE(n) (n).b_val
89+#define KEYVAL_DATA_BYTE_P(n) (n)->b_val
90+
91+#define KEYVAL_DATA_ISBOOL(n) (n).b_val
92+#define KEYVAL_DATA_ISBOOL_P(n) (n)->b_val
7593
7694 #define KEYVAL_DATA_SET_INT(n,v) (n).b_type=KEYVAL_TYPE_INT, (n).i_val=(v)
7795 #define KEYVAL_DATA_SET_INT_P(n,v) (n)->b_type=KEYVAL_TYPE_INT, (n)->i_val=(v)
96+#define KEYVAL_DATA_SET_DWORD(n,v) (n).b_type=KEYVAL_TYPE_DWORD, (n).i_val=(v)
97+#define KEYVAL_DATA_SET_DWORD_P(n,v) (n)->b_type=KEYVAL_TYPE_DWORD, (n)->i_val=(v)
98+#define KEYVAL_DATA_SET_STRING(n,v) (n).b_type=KEYVAL_TYPE_STRING, strncpy( (n).str_val, (v), KEYVAL_MAXLEN_STRVAL )
99+#define KEYVAL_DATA_SET_STRING_P(n,v) (n).b_type=KEYVAL_TYPE_STRING, strncpy( (n)->str_val, (v), KEYVAL_MAXLEN_STRVAL )
100+#define KEYVAL_DATA_SET_STRPTR(n,v) (n).b_type=KEYVAL_TYPE_STRPTR, (n).pstr_val=(v)
101+#define KEYVAL_DATA_SET_STRPTR_P(n,v) (n).b_type=KEYVAL_TYPE_STRPTR, (n)->pstr_val=(v)
102+#define KEYVAL_DATA_SET_BOOL_TRUE(n) (n).b_type=KEYVAL_TYPE_BOOL, (n).b_val=0x01
103+#define KEYVAL_DATA_SET_BOOL_P_TRUE(n) (n)->b_type=KEYVAL_TYPE_BOOL, (n)->b_val=0x01
104+#define KEYVAL_DATA_SET_BOOL_FALSE(n) (n).b_type=KEYVAL_TYPE_BOOL, (n).b_val=0x00
105+#define KEYVAL_DATA_SET_BOOL_P_FALSE(n) (n)->b_type=KEYVAL_TYPE_BOOL, (n)->b_val=0x00
106+#define KEYVAL_DATA_SET_BYTE(n,v) (n).b_type=KEYVAL_TYPE_BYTE, (n).b_val=(v)
107+#define KEYVAL_DATA_SET_BYTE_P(n,v) (n)->b_type=KEYVAL_TYPE_BYTE, (n)->b_val=(v)
78108
79109 typedef struct {
80110 DWord dw_keyhash;
--- a/src/test_keyval.c
+++ b/src/test_keyval.c
@@ -659,10 +659,11 @@ void
659659 // for RegistData / SearchItem / RemoveData DataType Variation Test ---
660660
661661 int i_id;
662- int i_err;
662+ int i_err;
663663 KeyVal_Info t_keyval;
664664 KeyVal_Data t_data;
665665 KeyVal_Item *p_item;
666+ char str_temp[256];
666667
667668 i_err = KeyVal_Init( &t_keyval, 0 );
668669 CU_ASSERT( 0x00 == i_err );
@@ -672,23 +673,104 @@ void
672673 CU_ASSERT( NULL != t_keyval.p_items );
673674
674675 // Phase 1 ----
675- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
676- CU_ASSERT( NULL == p_item );
677-
678676 KEYVAL_DATA_SET_INT(t_data, 12345678 );
679677 CU_ASSERT( IS_KEYVAL_TYPE_INT( t_data ));
680- i_id = KeyVal_RegistData( &t_keyval, "test0", &t_data, KEYVAL_NONEID );
681- CU_ASSERT( 0 == i_id );
678+ i_id = KeyVal_RegistData( &t_keyval, "int0", &t_data, KEYVAL_NONEID );
679+ CU_ASSERT( KEYVAL_NONEID < i_id );
682680
683- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
681+ KEYVAL_DATA_SET_DWORD(t_data, 0xdeadbeaf );
682+ CU_ASSERT( IS_KEYVAL_TYPE_DWORD( t_data ));
683+ i_id = KeyVal_RegistData( &t_keyval, "dword0", &t_data, KEYVAL_NONEID );
684+ CU_ASSERT( KEYVAL_NONEID < i_id );
685+
686+ KEYVAL_DATA_SET_STRING(t_data, "deadbeaf" );
687+ CU_ASSERT( IS_KEYVAL_TYPE_STRING( t_data ));
688+ i_id = KeyVal_RegistData( &t_keyval, "string0", &t_data, KEYVAL_NONEID );
689+ CU_ASSERT( KEYVAL_NONEID < i_id );
690+
691+ strncpy( str_temp, "DEADBEAF", 256 );
692+ KEYVAL_DATA_SET_STRPTR(t_data, str_temp );
693+ CU_ASSERT( IS_KEYVAL_TYPE_STRPTR( t_data ));
694+ i_id = KeyVal_RegistData( &t_keyval, "strptr0", &t_data, KEYVAL_NONEID );
695+ CU_ASSERT( KEYVAL_NONEID < i_id );
696+
697+ KEYVAL_DATA_SET_BOOL_TRUE(t_data);
698+ CU_ASSERT( IS_KEYVAL_TYPE_BOOL( t_data ));
699+ i_id = KeyVal_RegistData( &t_keyval, "bool0", &t_data, KEYVAL_NONEID );
700+ CU_ASSERT( KEYVAL_NONEID < i_id );
701+
702+ KEYVAL_DATA_SET_BYTE(t_data, 0xfe);
703+ CU_ASSERT( IS_KEYVAL_TYPE_BYTE( t_data ));
704+ i_id = KeyVal_RegistData( &t_keyval, "byte0", &t_data, KEYVAL_NONEID );
705+ CU_ASSERT( KEYVAL_NONEID < i_id );
706+
707+
708+ p_item = KeyVal_SearchItem( &t_keyval, "int0", KEYVAL_NONEID );
684709 CU_ASSERT( NULL != p_item );
685710 CU_ASSERT( IS_KEYVAL_TYPE_INT( p_item->value ) );
686711 CU_ASSERT( 12345678 == KEYVAL_DATA_INT( p_item->value ) );
687712
688- i_err = KeyVal_RemoveData( &t_keyval, "test0", KEYVAL_NONEID );
713+ p_item = KeyVal_SearchItem( &t_keyval, "dword0", KEYVAL_NONEID );
714+ CU_ASSERT( NULL != p_item );
715+ CU_ASSERT( IS_KEYVAL_TYPE_DWORD( p_item->value ) );
716+ CU_ASSERT( 0xdeadbeaf == KEYVAL_DATA_DWORD( p_item->value ) );
717+
718+ p_item = KeyVal_SearchItem( &t_keyval, "string0", KEYVAL_NONEID );
719+ CU_ASSERT( NULL != p_item );
720+ CU_ASSERT( IS_KEYVAL_TYPE_STRING( p_item->value ) );
721+ CU_ASSERT_STRING_EQUAL( KEYVAL_DATA_STRING( p_item->value ), "deadbeaf" );
722+
723+ p_item = KeyVal_SearchItem( &t_keyval, "strptr0", KEYVAL_NONEID );
724+ CU_ASSERT( NULL != p_item );
725+ CU_ASSERT( IS_KEYVAL_TYPE_STRPTR( p_item->value ) );
726+ CU_ASSERT_STRING_EQUAL( KEYVAL_DATA_STRPTR( p_item->value ), "DEADBEAF" );
727+
728+ p_item = KeyVal_SearchItem( &t_keyval, "bool0", KEYVAL_NONEID );
729+ CU_ASSERT( NULL != p_item );
730+ CU_ASSERT( IS_KEYVAL_TYPE_BOOL( p_item->value ) );
731+ CU_ASSERT( KEYVAL_DATA_ISBOOL( p_item->value ) );
732+
733+ p_item = KeyVal_SearchItem( &t_keyval, "byte0", KEYVAL_NONEID );
734+ CU_ASSERT( NULL != p_item );
735+ CU_ASSERT( IS_KEYVAL_TYPE_BYTE( p_item->value ) );
736+ CU_ASSERT( 0xfe == KEYVAL_DATA_BYTE( p_item->value ) );
737+
738+
739+ i_err = KeyVal_RemoveData( &t_keyval, "int0", KEYVAL_NONEID );
689740 CU_ASSERT( 0x00 == i_err );
690741
691- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
742+ i_err = KeyVal_RemoveData( &t_keyval, "dword0", KEYVAL_NONEID );
743+ CU_ASSERT( 0x00 == i_err );
744+
745+ i_err = KeyVal_RemoveData( &t_keyval, "string0", KEYVAL_NONEID );
746+ CU_ASSERT( 0x00 == i_err );
747+
748+ i_err = KeyVal_RemoveData( &t_keyval, "strptr0", KEYVAL_NONEID );
749+ CU_ASSERT( 0x00 == i_err );
750+
751+ i_err = KeyVal_RemoveData( &t_keyval, "bool0", KEYVAL_NONEID );
752+ CU_ASSERT( 0x00 == i_err );
753+
754+ i_err = KeyVal_RemoveData( &t_keyval, "byte0", KEYVAL_NONEID );
755+ CU_ASSERT( 0x00 == i_err );
756+
757+
758+ p_item = KeyVal_SearchItem( &t_keyval, "int0", KEYVAL_NONEID );
759+ CU_ASSERT( NULL == p_item );
760+
761+ p_item = KeyVal_SearchItem( &t_keyval, "dword0", KEYVAL_NONEID );
762+ CU_ASSERT( NULL == p_item );
763+
764+ p_item = KeyVal_SearchItem( &t_keyval, "string0", KEYVAL_NONEID );
765+ CU_ASSERT( NULL == p_item );
766+
767+ p_item = KeyVal_SearchItem( &t_keyval, "strptr0", KEYVAL_NONEID );
768+ CU_ASSERT( NULL == p_item );
769+
770+ p_item = KeyVal_SearchItem( &t_keyval, "bool0", KEYVAL_NONEID );
771+ CU_ASSERT( NULL == p_item );
772+
773+ p_item = KeyVal_SearchItem( &t_keyval, "byte0", KEYVAL_NONEID );
692774 CU_ASSERT( NULL == p_item );
693775
694776
@@ -709,10 +791,12 @@ void
709791 // for RegistData / SearchItem / RemoveData Item Limit Extension Test ---
710792
711793 int i_id;
712- int i_err;
794+ int i_err;
713795 KeyVal_Info t_keyval;
714796 KeyVal_Data t_data;
715797 KeyVal_Item *p_item;
798+ char str_key[64];
799+ int i_cnt;
716800
717801 i_err = KeyVal_Init( &t_keyval, 0 );
718802 CU_ASSERT( 0x00 == i_err );
@@ -722,24 +806,58 @@ void
722806 CU_ASSERT( NULL != t_keyval.p_items );
723807
724808 // Phase 1 ----
725- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
726- CU_ASSERT( NULL == p_item );
809+ for( i_cnt = 0; i_cnt <(KEYVAL_DEFAULT_ALLOCS * 4); i_cnt++ ) {
810+ snprintf( str_key, 64, "extend%05d", i_cnt );
727811
728- KEYVAL_DATA_SET_INT(t_data, 12345678 );
729- CU_ASSERT( IS_KEYVAL_TYPE_INT( t_data ));
730- i_id = KeyVal_RegistData( &t_keyval, "test0", &t_data, KEYVAL_NONEID );
731- CU_ASSERT( 0 == i_id );
812+ p_item = KeyVal_SearchItem( &t_keyval, str_key, KEYVAL_NONEID );
813+ CU_ASSERT( NULL == p_item );
732814
733- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
734- CU_ASSERT( NULL != p_item );
735- CU_ASSERT( IS_KEYVAL_TYPE_INT( p_item->value ) );
736- CU_ASSERT( 12345678 == KEYVAL_DATA_INT( p_item->value ) );
815+ KEYVAL_DATA_SET_INT(t_data, i_cnt );
816+ CU_ASSERT( IS_KEYVAL_TYPE_INT( t_data ));
817+ i_id = KeyVal_RegistData( &t_keyval, str_key, &t_data, KEYVAL_NONEID );
818+ CU_ASSERT( i_cnt == i_id );
819+ }
737820
738- i_err = KeyVal_RemoveData( &t_keyval, "test0", KEYVAL_NONEID );
739- CU_ASSERT( 0x00 == i_err );
821+ for( i_cnt = 0; i_cnt <(KEYVAL_DEFAULT_ALLOCS * 4); i_cnt++ ) {
822+ snprintf( str_key, 64, "extend%05d", i_cnt );
740823
741- p_item = KeyVal_SearchItem( &t_keyval, "test0", KEYVAL_NONEID );
742- CU_ASSERT( NULL == p_item );
824+ p_item = KeyVal_SearchItem( &t_keyval, str_key, KEYVAL_NONEID );
825+ CU_ASSERT( NULL != p_item );
826+ CU_ASSERT( IS_KEYVAL_TYPE_INT( p_item->value ) );
827+ CU_ASSERT( i_cnt == KEYVAL_DATA_INT( p_item->value ) );
828+ }
829+
830+ for( i_cnt = KEYVAL_DEFAULT_ALLOCS; i_cnt <(KEYVAL_DEFAULT_ALLOCS * 3); i_cnt++ ) {
831+ snprintf( str_key, 64, "extend%05d", i_cnt );
832+
833+ i_err = KeyVal_RemoveData( &t_keyval, str_key, KEYVAL_NONEID );
834+ CU_ASSERT( 0x00 == i_err );
835+
836+ p_item = KeyVal_SearchItem( &t_keyval, str_key, KEYVAL_NONEID );
837+ CU_ASSERT( NULL == p_item );
838+ }
839+
840+ for( i_cnt = KEYVAL_DEFAULT_ALLOCS; i_cnt <(KEYVAL_DEFAULT_ALLOCS * 3); i_cnt++ ) {
841+ snprintf( str_key, 64, "extend%05d", i_cnt );
842+
843+ p_item = KeyVal_SearchItem( &t_keyval, str_key, KEYVAL_NONEID );
844+ CU_ASSERT( NULL == p_item );
845+
846+ KEYVAL_DATA_SET_INT(t_data, i_cnt );
847+ CU_ASSERT( IS_KEYVAL_TYPE_INT( t_data ));
848+ i_id = KeyVal_RegistData( &t_keyval, str_key, &t_data, KEYVAL_NONEID );
849+ CU_ASSERT( i_cnt == i_id );
850+ }
851+
852+ for( i_cnt = (KEYVAL_DEFAULT_ALLOCS * 4) - 1; 0 <= i_cnt; i_cnt-- ) {
853+ snprintf( str_key, 64, "extend%05d", i_cnt );
854+
855+ i_err = KeyVal_RemoveData( &t_keyval, str_key, KEYVAL_NONEID );
856+ CU_ASSERT( 0x00 == i_err );
857+
858+ p_item = KeyVal_SearchItem( &t_keyval, str_key, KEYVAL_NONEID );
859+ CU_ASSERT( NULL == p_item );
860+ }
743861
744862
745863 i_err = KeyVal_Term( &t_keyval );