Skip to content

Commit

Permalink
make sure we can register two plugins with the same resourceId but wi…
Browse files Browse the repository at this point in the history
…th different location

(the same plugin is installed in two different places)
  • Loading branch information
RomanPudashkin committed Jul 4, 2023
1 parent 8e1faa4 commit aec4811
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp
Expand Up @@ -187,7 +187,14 @@ mu::Ret KnownAudioPluginsRegister::registerPlugin(const AudioPluginInfo& info)
return false;
}

m_pluginInfoMap[info.meta.id] = info;
auto it = m_pluginInfoMap.find(info.meta.id);
if (it != m_pluginInfoMap.end()) {
IF_ASSERT_FAILED(it->second.path != info.path) {
return false;
}
}

m_pluginInfoMap.emplace(info.meta.id, info);
m_pluginPaths.insert(info.path);

Ret ret = writePluginsInfo();
Expand All @@ -204,10 +211,13 @@ mu::Ret KnownAudioPluginsRegister::unregisterPlugin(const AudioResourceId& resou
return make_ok();
}

AudioPluginInfo info = m_pluginInfoMap[resourceId];
for (const auto& pair : m_pluginInfoMap) {
if (pair.first == resourceId) {
mu::remove(m_pluginPaths, pair.second.path);
}
}

mu::remove(m_pluginInfoMap, resourceId);
mu::remove(m_pluginPaths, info.path);
m_pluginInfoMap.erase(resourceId);

Ret ret = writePluginsInfo();
return ret;
Expand Down
Expand Up @@ -51,7 +51,7 @@ class KnownAudioPluginsRegister : public IKnownAudioPluginsRegister
Ret writePluginsInfo();

bool m_loaded = false;
std::map<AudioResourceId, AudioPluginInfo> m_pluginInfoMap;
std::multimap<AudioResourceId, AudioPluginInfo> m_pluginInfoMap;
std::set<io::path_t> m_pluginPaths;
};
}
Expand Down
17 changes: 16 additions & 1 deletion src/framework/audio/tests/knownaudiopluginsregistertest.cpp
Expand Up @@ -212,13 +212,28 @@ TEST_F(Audio_KnownAudioPluginsRegisterTest, PluginInfoList)
// [THEN] The plugin successfully registered
EXPECT_TRUE(ret);

// [GIVEN] Same plugin (with the same resourceId) is installed in a different location
AudioPluginInfo duplicatedPluginInfo = newPluginInfo;
duplicatedPluginInfo.path = "/another/path/to/new/plugin/plugin.vst";
expectedPluginInfoList.push_back(duplicatedPluginInfo);

// [THEN] All the plugins will be written to the file
expectedNewPluginsData = pluginInfoListToJson(expectedPluginInfoList);
EXPECT_CALL(*m_fileSystem, writeFile(m_knownAudioPluginsFilePath, expectedNewPluginsData))
.WillOnce(Return(mu::make_ok()));

// [WHEN] Register it
ret = m_knownPlugins->registerPlugin(duplicatedPluginInfo);

// [THEN] The duplicated plugin successfully registered
EXPECT_TRUE(ret);

actualPluginInfoList = m_knownPlugins->pluginInfoList();
EXPECT_EQ(expectedPluginInfoList.size(), actualPluginInfoList.size());
for (const AudioPluginInfo& actualInfo : actualPluginInfoList) {
EXPECT_TRUE(mu::contains(expectedPluginInfoList, actualInfo));
EXPECT_TRUE(m_knownPlugins->exists(actualInfo.path));
EXPECT_TRUE(m_knownPlugins->exists(actualInfo.meta.id));
EXPECT_EQ(actualInfo.path, m_knownPlugins->pluginPath(actualInfo.meta.id));
}

// [GIVEN] We want to unregister the first plugin in the list
Expand Down
6 changes: 6 additions & 0 deletions src/framework/global/containers.h
Expand Up @@ -216,6 +216,12 @@ inline bool contains(const std::map<K, V>& m, const K& k)
return m.find(k) != m.cend();
}

template<typename K, typename V>
inline bool contains(const std::multimap<K, V>& m, const K& k)
{
return m.find(k) != m.cend();
}

template<typename K, typename V>
inline bool contains(const std::unordered_map<K, V>& m, const K& k)
{
Expand Down

0 comments on commit aec4811

Please sign in to comment.