|
25 | 25 | #include "TestObjectFactory.h" |
26 | 26 | #include "shellanything/ConfigManager.h" |
27 | 27 | #include "shellanything/Context.h" |
| 28 | +#include "shellanything/ActionExecute.h" |
28 | 29 | #include "shellanything/ActionFile.h" |
29 | 30 | #include "shellanything/ActionPrompt.h" |
30 | 31 | #include "shellanything/ActionMessage.h" |
@@ -74,6 +75,23 @@ namespace shellanything { namespace test |
74 | 75 | return NULL; |
75 | 76 | } |
76 | 77 | //-------------------------------------------------------------------------------------------------- |
| 78 | + ActionExecute * GetFirstActionExecute(Menu * m) |
| 79 | + { |
| 80 | + if (!m) |
| 81 | + return NULL; |
| 82 | + |
| 83 | + Action::ActionPtrList actions = m->GetActions(); |
| 84 | + for(size_t i=0; i<actions.size(); i++) |
| 85 | + { |
| 86 | + Action * action = actions[i]; |
| 87 | + ActionExecute * action_execute = dynamic_cast<ActionExecute *>(action); |
| 88 | + if (action_execute) |
| 89 | + return action_execute; |
| 90 | + } |
| 91 | + |
| 92 | + return NULL; |
| 93 | + } |
| 94 | + //-------------------------------------------------------------------------------------------------- |
77 | 95 | ActionFile * GetFirstActionFile(Menu * m) |
78 | 96 | { |
79 | 97 | if (!m) |
@@ -283,6 +301,74 @@ namespace shellanything { namespace test |
283 | 301 | ASSERT_TRUE( ra::filesystem::DeleteFile(template_target_path.c_str()) ) << "Failed deleting file '" << template_target_path << "'."; |
284 | 302 | } |
285 | 303 | //-------------------------------------------------------------------------------------------------- |
| 304 | + TEST_F(TestObjectFactory, testParseActionExecute) |
| 305 | + { |
| 306 | + ConfigManager & cmgr = ConfigManager::GetInstance(); |
| 307 | + |
| 308 | + static const std::string path_separator = ra::filesystem::GetPathSeparatorStr(); |
| 309 | + |
| 310 | + //copy test template file to a temporary subdirectory to allow editing the file during the test |
| 311 | + std::string test_name = ra::testing::GetTestQualifiedName(); |
| 312 | + std::string template_source_path = std::string("test_files") + path_separator + test_name + ".xml"; |
| 313 | + std::string template_target_path = std::string("test_files") + path_separator + test_name + path_separator + "tmp.xml"; |
| 314 | + |
| 315 | + //make sure the target directory exists |
| 316 | + std::string template_target_dir = ra::filesystem::GetParentPath(template_target_path); |
| 317 | + ASSERT_TRUE( ra::filesystem::CreateDirectory(template_target_dir.c_str()) ) << "Failed creating directory '" << template_target_dir << "'."; |
| 318 | + |
| 319 | + //copy the file |
| 320 | + ASSERT_TRUE( ra::filesystem::CopyFile(template_source_path, template_target_path) ) << "Failed copying file '" << template_source_path << "' to file '" << template_target_path << "'."; |
| 321 | + |
| 322 | + //wait to make sure that the next files not dated the same date as this copy |
| 323 | + ra::timing::Millisleep(1500); |
| 324 | + |
| 325 | + //setup ConfigManager to read files from template_target_dir |
| 326 | + cmgr.ClearSearchPath(); |
| 327 | + cmgr.AddSearchPath(template_target_dir); |
| 328 | + cmgr.Refresh(); |
| 329 | + |
| 330 | + //ASSERT the file is loaded |
| 331 | + Configuration::ConfigurationPtrList configs = cmgr.GetConfigurations(); |
| 332 | + ASSERT_EQ( 1, configs.size() ); |
| 333 | + |
| 334 | + //ASSERT all menus are available |
| 335 | + Menu::MenuPtrList menus = cmgr.GetConfigurations()[0]->GetMenus(); |
| 336 | + ASSERT_EQ( 4, menus.size() ); |
| 337 | + |
| 338 | + //assert all menus have a file element as the first action |
| 339 | + ActionExecute * exec00 = GetFirstActionExecute(menus[00]); |
| 340 | + ActionExecute * exec01 = GetFirstActionExecute(menus[01]); |
| 341 | + ActionExecute * exec02 = GetFirstActionExecute(menus[02]); |
| 342 | + ActionExecute * exec03 = GetFirstActionExecute(menus[03]); |
| 343 | + |
| 344 | + ASSERT_TRUE( exec00 != NULL ); |
| 345 | + ASSERT_TRUE( exec01 != NULL ); |
| 346 | + ASSERT_TRUE( exec02 != NULL ); |
| 347 | + ASSERT_TRUE( exec03 != NULL ); |
| 348 | + |
| 349 | + //assert menu00 attributes |
| 350 | + ASSERT_EQ("C:\\Windows\\System32\\calc.exe", exec00->GetPath()); |
| 351 | + |
| 352 | + //assert menu01 attributes |
| 353 | + //<exec path="C:\Windows\notepad.exe" basedir="C:\Program Files\7-Zip" arguments="License.txt" /> |
| 354 | + ASSERT_EQ("C:\\Windows\\notepad.exe", exec01->GetPath()); |
| 355 | + ASSERT_EQ("C:\\Program Files\\7-Zip", exec01->GetBaseDir()); |
| 356 | + ASSERT_EQ("License.txt", exec01->GetArguments()); |
| 357 | + |
| 358 | + //assert menu02 attributes |
| 359 | + //<exec path="C:\Windows\notepad.exe" arguments="C:\Windows\System32\drivers\etc\hosts" verb="runas" /> |
| 360 | + ASSERT_EQ("C:\\Windows\\notepad.exe", exec02->GetPath()); |
| 361 | + ASSERT_EQ("C:\\Windows\\System32\\drivers\\etc\\hosts", exec02->GetArguments()); |
| 362 | + ASSERT_EQ("runas", exec02->GetVerb()); |
| 363 | + |
| 364 | + //assert menu03 attributes |
| 365 | + //<!-- missing path attribute --> <exec arguments="C:\Windows\System32\drivers\etc\hosts" verb="runas" /> |
| 366 | + ASSERT_EQ("", exec03->GetPath()); |
| 367 | + |
| 368 | + //cleanup |
| 369 | + ASSERT_TRUE( ra::filesystem::DeleteFile(template_target_path.c_str()) ) << "Failed deleting file '" << template_target_path << "'."; |
| 370 | + } |
| 371 | + //-------------------------------------------------------------------------------------------------- |
286 | 372 | TEST_F(TestObjectFactory, testParseActionFile) |
287 | 373 | { |
288 | 374 | ConfigManager & cmgr = ConfigManager::GetInstance(); |
|
0 commit comments