@@ -41,17 +41,20 @@ namespace parsertests
4141 TEST_CLASS (parsertests)
4242 {
4343 public:
44-
44+ bool check_value_in_vector (const std::vector<std::wstring>& vec, const std::wstring& value)
45+ {
46+ return std::find (vec.begin (), vec.end (), value) != vec.end ();
47+ }
4548 TEST_METHOD (TEST_CORRECT_TEST_COMMAND)
4649 {
4750 const wchar_t * argv[] = { L" wperf" , L" test" , L" -v" , L" --json" };
4851 int argc = 4 ;
4952 mock_arg_parser parser;
5053 parser.parse (argc, argv);
5154
52- Assert::AreEqual (true , parser.do_verbose .get ());
53- Assert::AreEqual (true , parser.do_json .get ());
54- Assert::IsTrue (COMMAND_CLASS::TEST == parser.command );
55+ Assert::AreEqual (true , parser.do_verbose .is_set ());
56+ Assert::AreEqual (true , parser.do_json .is_set ());
57+ Assert::IsTrue (COMMAND_CLASS::TEST == parser.m_command );
5558 }
5659 TEST_METHOD (TEST_RANDOM_ARGS_REJECTION)
5760 {
@@ -63,16 +66,16 @@ namespace parsertests
6366 }
6467 );
6568 }
66- // Test parsing the ' help' command with no arguments
69+ // Test parsing the " help" command with no arguments
6770 TEST_METHOD (TEST_HELP_COMMAND)
6871 {
6972 const wchar_t * argv[] = { L" wperf" , L" --help" };
7073 int argc = 2 ;
7174 mock_arg_parser parser;
7275 parser.parse (argc, argv);
7376
74- Assert::IsTrue (parser.do_help .get ());
75- Assert::IsTrue (COMMAND_CLASS::HELP == parser.command );
77+ Assert::IsTrue (parser.do_help .is_set ());
78+ Assert::IsTrue (COMMAND_CLASS::HELP == parser.m_command );
7679 }
7780
7881 // Test parsing the 'version' command with no arguments
@@ -83,8 +86,8 @@ namespace parsertests
8386 mock_arg_parser parser;
8487 parser.parse (argc, argv);
8588
86- Assert::IsTrue (parser.do_version .get ());
87- Assert::IsTrue (COMMAND_CLASS::VERSION == parser.command );
89+ Assert::IsTrue (parser.do_version .is_set ());
90+ Assert::IsTrue (COMMAND_CLASS::VERSION == parser.m_command );
8891 }
8992
9093 // Test parsing the 'list' command with no arguments
@@ -95,21 +98,8 @@ namespace parsertests
9598 mock_arg_parser parser;
9699 parser.parse (argc, argv);
97100
98- Assert::IsTrue (parser.do_list .get ());
99- Assert::IsTrue (COMMAND_CLASS::LIST == parser.command );
100- }
101-
102- // Test parsing the 'sample' command with various flags
103- TEST_METHOD (TEST_SAMPLE_COMMAND_WITH_MULTIPLE_CORES)
104- {
105- const wchar_t * argv[] = { L" wperf" , L" sample" , L" --annotate" , L" --timeout" , L" 5s" , L" -c" , L" 0,1,2" };
106- int argc = 7 ;
107- mock_arg_parser parser;
108-
109- Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
110- parser.parse (argc, argv);
111- }
112- );
101+ Assert::IsTrue (parser.do_list .is_set ());
102+ Assert::IsTrue (COMMAND_CLASS::LIST == parser.m_command );
113103 }
114104
115105 // Test parsing the 'record' command with command line separator and arguments
@@ -119,12 +109,9 @@ namespace parsertests
119109 int argc = 5 ;
120110 mock_arg_parser parser;
121111 parser.parse (argc, argv);
122-
123- Assert::IsTrue (parser.do_record .get ());
124- Assert::AreEqual (std::wstring (L" notepad.exe test_arg" ), parser.record_commandline .get ());
125- Assert::AreEqual (std::wstring (L" notepad.exe" ), parser.sample_pe_file .get ());
126- Assert::AreEqual (std::wstring (L" notepad.pdb" ), parser.sample_pdb_file .get ());
127- Assert::IsTrue (COMMAND_CLASS::RECORD == parser.command );
112+ Assert::IsTrue (parser.do_record .is_set ());
113+ Assert::IsTrue (check_value_in_vector (parser.double_dash .get_values (), L" notepad.exe" ));
114+ Assert::IsTrue (COMMAND_CLASS::RECORD == parser.m_command );
128115 }
129116
130117 // Test that missing required arguments cause exceptions
@@ -159,20 +146,9 @@ namespace parsertests
159146 mock_arg_parser parser;
160147 parser.parse (argc, argv);
161148
162- Assert::AreEqual ( 120.0 , parser.count_duration .get ()); // 2 minutes in seconds
149+ Assert::IsTrue ( check_value_in_vector ( parser.count_duration .get_values (), L" 2m " ));
163150 }
164151
165- // Test that invalid timeout format causes exception
166- TEST_METHOD (TEST_INVALID_TIMEOUT_WITH_WRONG_UNIT)
167- {
168- const wchar_t * argv[] = { L" wperf" , L" sample" , L" --timeout" , L" 5x" };
169- int argc = 4 ;
170- mock_arg_parser parser;
171- Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
172- parser.parse (argc, argv);
173- }
174- );
175- }
176152 TEST_METHOD (TEST_INVALID_TIMEOUT_WITH_WRONG_FORMAT)
177153 {
178154 const wchar_t * argv[] = { L" wperf" , L" sample" , L" --timeout" , L" 5.4" , L" ms" };
@@ -192,22 +168,22 @@ namespace parsertests
192168 mock_arg_parser parser;
193169 parser.parse (argc, argv);
194170
195- Assert::IsTrue (parser.do_detect .get ());
196- Assert::IsTrue (COMMAND_CLASS::DETECT == parser.command );
171+ Assert::IsTrue (parser.do_detect .is_set ());
172+ Assert::IsTrue (COMMAND_CLASS::DETECT == parser.m_command );
197173 }
198174
199- // Test parsing multiple flags together
175+ // Test parsing multiple flags tois_sether
200176 TEST_METHOD (TEST_MULTIPLE_FLAGS)
201177 {
202178 const wchar_t * argv[] = { L" wperf" , L" sample" , L" --verbose" , L" -q" , L" --json" };
203179 int argc = 5 ;
204180 mock_arg_parser parser;
205181 parser.parse (argc, argv);
206182
207- Assert::IsTrue (parser.do_verbose .get ());
208- Assert::IsTrue (parser.is_quite .get ());
209- Assert::IsTrue (parser.do_json .get ());
210- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
183+ Assert::IsTrue (parser.do_verbose .is_set ());
184+ Assert::IsTrue (parser.is_quite .is_set ());
185+ Assert::IsTrue (parser.do_json .is_set ());
186+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
211187 }
212188
213189 // Test parsing sample command with symbol argument
@@ -218,8 +194,8 @@ namespace parsertests
218194 mock_arg_parser parser;
219195 parser.parse (argc, argv);
220196
221- Assert::AreEqual ( std::wstring ( L" main " ), parser.symbol_arg .get ( ));
222- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
197+ Assert::IsTrue ( check_value_in_vector ( parser.symbol_arg .get_values (), L" main " ));
198+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
223199 }
224200
225201 // Test parsing sample command with sample display row
@@ -230,8 +206,8 @@ namespace parsertests
230206 mock_arg_parser parser;
231207 parser.parse (argc, argv);
232208
233- Assert::AreEqual (( uint32_t ) 100 , parser.sample_display_row .get ( ));
234- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
209+ Assert::IsTrue ( check_value_in_vector ( parser.sample_display_row .get_values (), L" 100 " ));
210+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
235211 }
236212
237213 // Test parsing sample command with pe_file
@@ -243,10 +219,8 @@ namespace parsertests
243219
244220 parser.parse (argc, argv);
245221
246- Assert::AreEqual (std::wstring (L" C:\\ Program\\ sample.exe" ), parser.sample_pe_file .get ());
247- Assert::AreEqual (std::wstring (L" C:\\ Program\\ sample.pdb" ), parser.sample_pdb_file .get ());
248- Assert::AreEqual (std::wstring (L" C:\\ Program\\ sample.exe" ), parser.sample_image_name .get ());
249- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
222+ Assert::IsTrue (check_value_in_vector (parser.sample_pe_file .get_values (), L" C:\\ Program\\ sample.exe" ));
223+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
250224 }
251225
252226 // Test parsing sample command with pdb_file
@@ -259,8 +233,8 @@ namespace parsertests
259233 // Similarly, adjust or mock check_file_path for testing
260234 parser.parse (argc, argv);
261235
262- Assert::AreEqual ( std::wstring ( L" C:\\ Program\\ sample.pdb" ), parser. sample_pdb_file . get ( ));
263- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
236+ Assert::IsTrue ( check_value_in_vector (parser. sample_pdb_file . get_values (), L" C:\\ Program\\ sample.pdb" ));
237+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
264238 }
265239
266240 // Test parsing sample command with image_name
@@ -271,8 +245,8 @@ namespace parsertests
271245 mock_arg_parser parser;
272246 parser.parse (argc, argv);
273247
274- Assert::AreEqual ( std::wstring ( L" notepad.exe" ), parser. sample_image_name . get ( ));
275- Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.command );
248+ Assert::IsTrue ( check_value_in_vector (parser. sample_image_name . get_values (), L" notepad.exe" ));
249+ Assert::IsTrue (COMMAND_CLASS::SAMPLE == parser.m_command );
276250 }
277251
278252 // Test parsing with --force-lock flag
@@ -283,8 +257,8 @@ namespace parsertests
283257 mock_arg_parser parser;
284258 parser.parse (argc, argv);
285259
286- Assert::IsTrue (parser.do_force_lock .get ());
287- Assert::IsTrue (COMMAND_CLASS::TEST == parser.command );
260+ Assert::IsTrue (parser.do_force_lock .is_set ());
261+ Assert::IsTrue (COMMAND_CLASS::TEST == parser.m_command );
288262 }
289263
290264 // Test parsing the 'stat' command (not fully implemented in the parser)
@@ -296,7 +270,7 @@ namespace parsertests
296270 parser.parse (argc, argv);
297271
298272 // Assuming command is set correctly
299- Assert::IsTrue (COMMAND_CLASS::STAT == parser.command );
273+ Assert::IsTrue (COMMAND_CLASS::STAT == parser.m_command );
300274 }
301275
302276 // Test parsing with unknown flags
@@ -310,5 +284,35 @@ namespace parsertests
310284 }
311285 );
312286 }
287+
288+ // Test parsing with no command
289+ TEST_METHOD (TEST_NO_COMMAND)
290+ {
291+ const wchar_t * argv[] = { L" wperf" , L" --annotate" , L" --json" };
292+ int argc = 3 ;
293+ mock_arg_parser parser;
294+ Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
295+ parser.parse (argc, argv);
296+ }
297+ );
298+ }
299+
300+ // Test complex stat command
301+ TEST_METHOD (TEST_FULL_STAT_COMMAND)
302+ {
303+ const wchar_t * argv[] = { L" wperf" , L" stat" , L" --output" , L" _output_02.json" , L" -e" , L" inst_spec,vfp_spec,ase_spec,dp_spec,ld_spec,st_spec,br_immed_spec,crypto_spec" , L" -c" , L" 0" , L" sleep" , L" 5" };
304+ int argc = 10 ;
305+ mock_arg_parser parser;
306+ parser.parse (argc, argv);
307+ Assert::IsTrue (COMMAND_CLASS::STAT == parser.m_command );
308+ Assert::IsTrue (parser.raw_events .is_set ());
309+ Assert::IsTrue (parser.output_filename .is_set ());
310+ Assert::IsTrue (parser.cores_idx .is_set ());
311+ Assert::IsTrue (parser.count_duration .is_set ());
312+ Assert::IsTrue (check_value_in_vector (parser.count_duration .get_values (), L" 5" ));
313+ Assert::IsTrue (check_value_in_vector (parser.cores_idx .get_values (), L" 0" ));
314+ Assert::IsTrue (check_value_in_vector (parser.output_filename .get_values (), L" _output_02.json" ));
315+ Assert::IsTrue (check_value_in_vector (parser.raw_events .get_values (), L" inst_spec,vfp_spec,ase_spec,dp_spec,ld_spec,st_spec,br_immed_spec,crypto_spec" ));
316+ }
313317 };
314318}
0 commit comments