• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

*NIX用コマンドライン手順書自動作成ツール開発


コミットメタ情報

リビジョンf0ffeff0a7c41462b31bbc841db0289a7a71f173 (tree)
日時2016-09-03 21:59:32
作者Koine Yuusuke(koinec) <koinec@user...>
コミッターKoine Yuusuke(koinec)

ログメッセージ

* AddTest for test_cmdline.c

変更サマリ

差分

--- a/cmdline.c
+++ b/cmdline.c
@@ -39,6 +39,8 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3939 static char *gpstr_cmdline = NULL;
4040 static char *gpstr_end = NULL;
4141 static int gi_cmdlinelen = 0;
42+static int gi_maxlen = 0;
43+
4244
4345 /*===========================================================================*/
4446 PROCEDURE_CMDLINE_EXTERN
@@ -54,6 +56,9 @@ int
5456 { return -0x01; }
5557
5658 memset( gpstr_cmdline, 0x00, (i_maxlen + 8) );
59+ gpstr_end = gpstr_cmdline;
60+ gi_maxlen = i_maxlen;
61+ gi_cmdlinelen = 0;
5762
5863 return 0x00;
5964 }
@@ -108,17 +113,43 @@ int
108113 char *pstr_src,
109114 int i_len )
110115 {
116+ int i_result = 0;
117+ int i_remain;
111118 char *pstr_now;
112119
113- if( 0 >= i_len ) { goto goto_CmdLine_AddCmdLineString_post; }
120+ if( NULL == pstr_src ) {
121+ i_result = -0x01;
122+ goto goto_CmdLine_AddCmdLineString_post;
123+ }
124+
125+ if( 0 >= i_len ) {
126+ i_result = -0x02;
127+ goto goto_CmdLine_AddCmdLineString_post;
128+ }
129+ if( gi_cmdlinelen >= gi_maxlen ) {
130+ i_result = -0x03;
131+ goto goto_CmdLine_AddCmdLineString_post;
132+ }
114133
115- for( pstr_now = pstr_src; 0 < i_len; i_len-- ) {
134+ if(( NULL == gpstr_cmdline ) || ( NULL == gpstr_end )) {
135+ i_result = -0x04;
136+ goto goto_CmdLine_AddCmdLineString_post;
137+ }
138+
139+
140+ i_remain = gi_maxlen - gi_cmdlinelen;
141+ if( i_remain < i_len ) { i_len = i_remain; }
142+
143+ pstr_now = pstr_src;
144+ for( ; (( 0 < i_len ) && ( '\0' != *pstr_now )); i_len-- ) {
116145 *gpstr_end++ = *pstr_now++;
117146 gi_cmdlinelen++;
147+ i_result++;
118148 }
149+ *gpstr_end = '\0';
119150
120151 goto_CmdLine_AddCmdLineString_post:
121- return 0x00;
152+ return i_result;
122153 }
123154
124155
--- a/test_cmdline.c
+++ b/test_cmdline.c
@@ -39,8 +39,116 @@ PrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcEdUrEpRoCeDuRePrOcE*/
3939
4040
4141 /*===========================================================================*/
42-void Test_CmdLine_aa(void)
42+void Test_CmdLine_InitTerm_test00_001(void)
4343 {
44+ int i_err;
45+
46+ i_err = CmdLine_Init( 100 );
47+ CU_ASSERT( 0x00 == i_err );
48+
49+ i_err = CmdLine_Term();
50+ CU_ASSERT( 0x00 == i_err );
51+
52+ return;
53+}
54+
55+
56+/*===========================================================================*/
57+void Test_CmdLine_AddCmdLineString_test00_001(void)
58+{
59+ int i_err;
60+ int i_len;
61+ char str_src[256];
62+ const char *pcstr_temp;
63+ const char *pcstr_dest;
64+
65+ i_err = CmdLine_Init( 512 );
66+ CU_ASSERT( 0x00 == i_err );
67+
68+ strncpy( str_src, "procedure command test string.", 256 );
69+ i_err = CmdLine_AddCmdLineString( str_src, 30 );
70+ CU_ASSERT( 30 == i_err );
71+
72+ strncpy( str_src, "procedure command test string.", 256 );
73+ i_err = CmdLine_AddCmdLineString( str_src, 30 );
74+ CU_ASSERT( 30 == i_err );
75+
76+ pcstr_temp = CmdLine_GetCmdLineString( NULL );
77+ CU_ASSERT( NULL != pcstr_temp );
78+
79+ pcstr_dest = CmdLine_GetCmdLineString( &i_len );
80+ CU_ASSERT( NULL != pcstr_dest );
81+ CU_ASSERT( pcstr_temp == pcstr_dest );
82+ CU_ASSERT( 60 == i_len );
83+
84+ CU_ASSERT_NSTRING_EQUAL( pcstr_dest,
85+ "procedure command test string.procedure command test string.", 61 );
86+
87+ CmdLine_ClearCmdLineString();
88+
89+ i_len = 0;
90+ pcstr_dest = NULL;
91+ pcstr_dest = CmdLine_GetCmdLineString( &i_len );
92+ CU_ASSERT( NULL != pcstr_dest );
93+ CU_ASSERT( 0 == i_len );
94+
95+ i_err = CmdLine_Term();
96+ CU_ASSERT( 0x00 == i_err );
97+
98+ return;
99+}
100+
101+/*----------------------------------------------------------------------------*/
102+void Test_CmdLine_AddCmdLineString_test01_001(void)
103+{
104+ int i_err;
105+ char str_src[256];
106+ const char *pcstr_temp;
107+
108+ strncpy( str_src, "procedure command test string.", 256 );
109+ i_err = CmdLine_AddCmdLineString( str_src, 30 );
110+ CU_ASSERT( 0x00 != i_err );
111+
112+ pcstr_temp = CmdLine_GetCmdLineString( NULL );
113+ CU_ASSERT( NULL == pcstr_temp );
114+
115+ CmdLine_ClearCmdLineString();
116+
117+ return;
118+}
119+
120+/*----------------------------------------------------------------------------*/
121+void Test_CmdLine_AddCmdLineString_test01_002(void)
122+{
123+ int i_err;
124+ int i_len;
125+ int i_cnt;
126+ char str_src[2] = { 'a', 0x00 };
127+ const char *pcstr_dest;
128+
129+ i_err = CmdLine_Init( 256 );
130+ CU_ASSERT( 0x00 == i_err );
131+
132+ for( i_cnt = 0; i_cnt < 256; i_cnt++ ) {
133+ i_err = CmdLine_AddCmdLineString( str_src, 2 );
134+ CU_ASSERT( 1 == i_err );
135+ }
136+
137+ i_err = CmdLine_AddCmdLineString( str_src, 2 );
138+ CU_ASSERT( 0 > i_err );
139+
140+ i_err = CmdLine_AddCmdLineString( str_src, 2 );
141+ CU_ASSERT( 0 > i_err );
142+
143+ pcstr_dest = CmdLine_GetCmdLineString( &i_len );
144+ CU_ASSERT( NULL != pcstr_dest );
145+ CU_ASSERT( 256 == i_len );
146+
147+ CmdLine_ClearCmdLineString();
148+
149+ i_err = CmdLine_Term();
150+ CU_ASSERT( 0x00 == i_err );
151+
44152 return;
45153 }
46154
@@ -54,8 +162,15 @@ int
54162
55163 pt_test = CU_add_suite( "CmdLine", NULL, NULL );
56164
57- CU_add_test( pt_test, "CmdLine_test00_001",
58- Test_CmdLine_aa );
165+ CU_add_test( pt_test, "CmdLine_InitTerm_test00_001",
166+ Test_CmdLine_InitTerm_test00_001 );
167+
168+ CU_add_test( pt_test, "CmdLine_AddCmdLineString_test00_001",
169+ Test_CmdLine_AddCmdLineString_test00_001 );
170+ CU_add_test( pt_test, "CmdLine_AddCmdLineString_test01_001",
171+ Test_CmdLine_AddCmdLineString_test01_001 );
172+ CU_add_test( pt_test, "CmdLine_AddCmdLineString_test01_002",
173+ Test_CmdLine_AddCmdLineString_test01_002 );
59174
60175 return 0x00;
61176 }
--- a/test_procedure.c
+++ b/test_procedure.c
@@ -45,6 +45,7 @@ int
4545 {
4646 CU_initialize_registry();
4747
48+ Test_CmdLine();
4849
4950 CU_basic_run_tests();
5051 CU_cleanup_registry();