From f48ac9f0c3fae1e5ea04768183e07823879a7d79 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 24 Jan 2019 09:48:30 +0100 Subject: BlockTypeRegistry: Added hint manipulation --- tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests') diff --git a/tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp b/tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp index c2d8717e5..3479e55d7 100644 --- a/tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp +++ b/tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp @@ -64,6 +64,42 @@ static void testSimpleReg() +/** Tests setting and removing a BlockType hint. */ +static void testHintSetRemove() +{ + LOGD("Testing hint addition and removal..."); + + // Register the block type: + BlockTypeRegistry reg; + AString blockTypeName("test:block1"); + AString pluginName("testPlugin"); + AString hint1("testHint1"); + AString hint1Value("value1"); + AString hint2("testHint2"); + AString hint2Value("value2"); + std::shared_ptr handler(new cBlockHandler(0x12345678)); + std::map hints = {{hint1, hint1Value}}; + std::map hintCallbacks; + reg.registerBlockType(pluginName, blockTypeName, handler, hints, hintCallbacks); + + // Modify the hints: + auto blockInfo = reg.blockInfo(blockTypeName); + reg.setBlockTypeHint(blockTypeName, hint2, hint2Value); + TEST_EQUAL(blockInfo->hintValue(hint2, BlockState()), hint2Value); // Was created successfully + reg.setBlockTypeHint(blockTypeName, hint1, "testValue2"); + TEST_EQUAL(blockInfo->hintValue(hint1, BlockState()), "testValue2"); // Was updated successfully + reg.removeBlockTypeHint(blockTypeName, hint2); + TEST_EQUAL(blockInfo->hintValue(hint2, BlockState()), ""); // Was removed successfully + + // Test the error reporting: + TEST_THROWS(reg.setBlockTypeHint("nonexistent", "hint", "value"), BlockTypeRegistry::NotRegisteredException); + reg.removeBlockTypeHint(blockTypeName, "nonexistent"); // Should fail silently +} + + + + + /** Tests that the plugin-based information is used correctly for registration. Registers two different block types with two different plugins, then tries to re-register them from a different plugin. Finally removes the registration through removeAllByPlugin() and checks its success. */ @@ -190,6 +226,7 @@ static void testThreadLocking() static void testBlockTypeRegistry() { testSimpleReg(); + testHintSetRemove(); testPlugins(); testHintCallbacks(); testThreadLocking(); -- cgit v1.2.3