diff options
author | Mattes D <github@xoft.cz> | 2019-01-24 09:48:30 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-08-05 21:42:54 +0200 |
commit | f48ac9f0c3fae1e5ea04768183e07823879a7d79 (patch) | |
tree | ddb7b405100ce3486136f85ac97c409ab600b373 /tests | |
parent | BlockTypeRegistry: Initial skeleton (diff) | |
download | cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.gz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.bz2 cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.lz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.xz cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.tar.zst cuberite-f48ac9f0c3fae1e5ea04768183e07823879a7d79.zip |
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BlockTypeRegistry/BlockTypeRegistryTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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<cBlockHandler> handler(new cBlockHandler(0x12345678)); + std::map<AString, AString> hints = {{hint1, hint1Value}}; + std::map<AString, BlockInfo::HintCallback> 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(); |