|
26 | 26 | #include "shellanything/Context.h" |
27 | 27 | #include "PropertyManager.h" |
28 | 28 | #include "rapidassist/process.h" |
| 29 | +#include "rapidassist/filesystem.h" |
| 30 | +#include "rapidassist/testing.h" |
29 | 31 |
|
30 | 32 | namespace shellanything { namespace test |
31 | 33 | { |
@@ -217,6 +219,76 @@ namespace shellanything { namespace test |
217 | 219 | context.UnregisterProperties(); |
218 | 220 | } |
219 | 221 | //-------------------------------------------------------------------------------------------------- |
| 222 | + TEST_F(TestContext, testRegisterPropertiesSingleDirectory) |
| 223 | + { |
| 224 | + PropertyManager & pmgr = PropertyManager::GetInstance(); |
| 225 | + |
| 226 | + Context context; |
| 227 | +#ifdef _WIN32 |
| 228 | + { |
| 229 | + Context::ElementList elements; |
| 230 | + elements.push_back("C:\\" ); |
| 231 | + context.SetElements(elements); |
| 232 | + } |
| 233 | +#else |
| 234 | + //TODO: complete with known path to files |
| 235 | +#endif |
| 236 | + |
| 237 | + ASSERT_FALSE( pmgr.HasProperty("selection.dir.count") ); |
| 238 | + ASSERT_FALSE( pmgr.HasProperty("selection.dir.empty") ); |
| 239 | + |
| 240 | + //act |
| 241 | + context.RegisterProperties(); |
| 242 | + |
| 243 | + //assert |
| 244 | + ASSERT_TRUE( pmgr.HasProperty("selection.dir.count") ); |
| 245 | + ASSERT_TRUE( pmgr.HasProperty("selection.dir.empty") ); |
| 246 | + |
| 247 | + std::string selection_dir_count = pmgr.Expand("${selection.dir.count}"); |
| 248 | + std::string selection_dir_empty = pmgr.Expand("${selection.dir.empty}"); |
| 249 | + |
| 250 | + ASSERT_TRUE(ra::strings::IsNumeric(selection_dir_count.c_str())); |
| 251 | + ASSERT_EQ( std::string("false"), selection_dir_empty); |
| 252 | + |
| 253 | + context.UnregisterProperties(); |
| 254 | + } |
| 255 | + //-------------------------------------------------------------------------------------------------- |
| 256 | + TEST_F(TestContext, testRegisterPropertiesEmptyDirectory) |
| 257 | + { |
| 258 | + PropertyManager & pmgr = PropertyManager::GetInstance(); |
| 259 | + |
| 260 | + //create an empty directory |
| 261 | + std::string temp_dir = ra::filesystem::GetTemporaryDirectory(); |
| 262 | + std::string empty_dir = temp_dir + ra::testing::GetTestQualifiedName(); |
| 263 | + ASSERT_TRUE(ra::filesystem::CreateDirectory(empty_dir.c_str())); |
| 264 | + |
| 265 | + Context context; |
| 266 | + Context::ElementList elements; |
| 267 | + elements.push_back(empty_dir); |
| 268 | + context.SetElements(elements); |
| 269 | + |
| 270 | + ASSERT_FALSE( pmgr.HasProperty("selection.dir.count") ); |
| 271 | + ASSERT_FALSE( pmgr.HasProperty("selection.dir.empty") ); |
| 272 | + |
| 273 | + //act |
| 274 | + context.RegisterProperties(); |
| 275 | + |
| 276 | + //assert |
| 277 | + ASSERT_TRUE( pmgr.HasProperty("selection.dir.count") ); |
| 278 | + ASSERT_TRUE( pmgr.HasProperty("selection.dir.empty") ); |
| 279 | + |
| 280 | + std::string selection_dir_count = pmgr.Expand("${selection.dir.count}"); |
| 281 | + std::string selection_dir_empty = pmgr.Expand("${selection.dir.empty}"); |
| 282 | + |
| 283 | + ASSERT_EQ( std::string("0"), selection_dir_count); |
| 284 | + ASSERT_EQ( std::string("true"), selection_dir_empty); |
| 285 | + |
| 286 | + context.UnregisterProperties(); |
| 287 | + |
| 288 | + //cleanup |
| 289 | + ra::filesystem::DeleteDirectory(empty_dir.c_str()); |
| 290 | + } |
| 291 | + //-------------------------------------------------------------------------------------------------- |
220 | 292 | TEST_F(TestContext, testRegisterPropertiesMultipleFiles) |
221 | 293 | { |
222 | 294 | PropertyManager & pmgr = PropertyManager::GetInstance(); |
|
0 commit comments