Tests.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2013-2014 Josh Blum
  2. // SPDX-License-Identifier: BSL-1.0
  3. #include <Pothos/Plugin.hpp>
  4. #include <Pothos/Testing.hpp>
  5. #include <vector>
  6. #include <string>
  7. #include <iostream>
  8. #include <algorithm>
  9. POTHOS_TEST_BLOCK("/plugin/tests", test_plugin_path)
  10. {
  11. Pothos::PluginPath nullPath;
  12. POTHOS_TEST_TRUE(nullPath == Pothos::PluginPath());
  13. POTHOS_TEST_EQUAL(nullPath.toString(), "/");
  14. POTHOS_TEST_EQUAL(nullPath.listNodes().size(), 0);
  15. Pothos::PluginPath goodPath("/foo-bar/my_module");
  16. POTHOS_TEST_EQUAL(goodPath.listNodes().size(), 2);
  17. POTHOS_TEST_EQUAL(goodPath.listNodes()[0], "foo-bar");
  18. POTHOS_TEST_EQUAL(goodPath.listNodes()[1], "my_module");
  19. POTHOS_TEST_THROWS(Pothos::PluginPath("/foo-bar//my_module"), Pothos::PluginPathError);
  20. POTHOS_TEST_THROWS(Pothos::PluginPath("/foo-bar/my_module "), Pothos::PluginPathError);
  21. POTHOS_TEST_THROWS(Pothos::PluginPath("foo-bar/my_module"), Pothos::PluginPathError);
  22. POTHOS_TEST_THROWS(Pothos::PluginPath("/foo bar/my_module"), Pothos::PluginPathError);
  23. }
  24. POTHOS_TEST_BLOCK("/plugin/tests", test_plugin_registry)
  25. {
  26. Pothos::PluginRegistry::add(Pothos::Plugin("/tests/t0"));
  27. Pothos::PluginRegistry::add(Pothos::Plugin("/tests/t1"));
  28. POTHOS_TEST_TRUE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/t0")));
  29. POTHOS_TEST_TRUE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/t1")));
  30. POTHOS_TEST_FALSE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/t2")));
  31. std::vector<std::string> expectedList, testsList;
  32. expectedList.push_back("t0");
  33. expectedList.push_back("t1");
  34. testsList = Pothos::PluginRegistry::list(Pothos::PluginPath("/tests"));
  35. POTHOS_TEST_EQUALV(testsList, expectedList);
  36. Pothos::PluginRegistry::remove(Pothos::PluginPath("/tests/t1"));
  37. POTHOS_TEST_FALSE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/t1")));
  38. expectedList.erase(std::find(expectedList.begin(), expectedList.end(), "t1"));
  39. testsList = Pothos::PluginRegistry::list(Pothos::PluginPath("/tests"));
  40. POTHOS_TEST_EQUALV(testsList, expectedList);
  41. Pothos::PluginRegistry::add(Pothos::Plugin("/tests/foo/t2"));
  42. POTHOS_TEST_TRUE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/foo")));
  43. POTHOS_TEST_TRUE(Pothos::PluginRegistry::exists(Pothos::PluginPath("/tests/foo/t2")));
  44. expectedList.push_back("foo");
  45. testsList = Pothos::PluginRegistry::list(Pothos::PluginPath("/tests"));
  46. POTHOS_TEST_EQUALV(testsList, expectedList);
  47. POTHOS_TEST_THROWS(Pothos::PluginRegistry::add(Pothos::Plugin("/tests/t0")), Pothos::PluginRegistryError);
  48. POTHOS_TEST_THROWS(Pothos::PluginRegistry::get(Pothos::PluginPath("/tests")), Pothos::PluginRegistryError);
  49. POTHOS_TEST_THROWS(Pothos::PluginRegistry::remove(Pothos::PluginPath("/tests/foo")), Pothos::PluginRegistryError);
  50. }