RuntimeLibraryTest.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-10-27
  6. * Changed: 2022-10-27
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std_os.hpp>
  11. #include <ls_std/ls_std_core.hpp>
  12. namespace
  13. {
  14. class RuntimeLibraryTest : public ::testing::Test
  15. {
  16. protected:
  17. RuntimeLibraryTest() = default;
  18. ~RuntimeLibraryTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(RuntimeLibraryTest, addSymbol)
  25. {
  26. ls::std::os::RuntimeLibrary runtimeLibrary{};
  27. ls::std::core::type::runtime_library_entry entry = ::std::make_pair<::std::string, void *>("_func", (void *) ::std::make_shared<int>().get());
  28. ASSERT_TRUE(runtimeLibrary.addSymbol(entry));
  29. }
  30. TEST_F(RuntimeLibraryTest, addSymbol_empty_key)
  31. {
  32. EXPECT_THROW({
  33. try
  34. {
  35. ls::std::os::RuntimeLibrary runtimeLibrary{};
  36. runtimeLibrary.addSymbol(::std::make_pair<::std::string, void *>("", (void *) ::std::make_shared<int>().get()));
  37. }
  38. catch (const ls::std::core::IllegalArgumentException &_exception)
  39. {
  40. throw;
  41. }
  42. }, ls::std::core::IllegalArgumentException);
  43. }
  44. TEST_F(RuntimeLibraryTest, addSymbol_empty_reference)
  45. {
  46. EXPECT_THROW({
  47. try
  48. {
  49. ls::std::os::RuntimeLibrary runtimeLibrary{};
  50. runtimeLibrary.addSymbol(::std::make_pair<::std::string, void *>("_func", (void *) nullptr));
  51. }
  52. catch (const ls::std::core::IllegalArgumentException &_exception)
  53. {
  54. throw;
  55. }
  56. }, ls::std::core::IllegalArgumentException);
  57. }
  58. TEST_F(RuntimeLibraryTest, getSymbol)
  59. {
  60. ls::std::os::RuntimeLibrary runtimeLibrary{};
  61. ls::std::core::type::runtime_library_entry entry = ::std::make_pair<::std::string, void *>("_func", (void *) ::std::make_shared<int>().get());
  62. ASSERT_TRUE(runtimeLibrary.addSymbol(entry));
  63. ASSERT_TRUE(runtimeLibrary.getSymbol("_func") != nullptr);
  64. }
  65. TEST_F(RuntimeLibraryTest, getSymbol_not_available)
  66. {
  67. ls::std::os::RuntimeLibrary runtimeLibrary{};
  68. ASSERT_TRUE(runtimeLibrary.getSymbol("_func") == nullptr);
  69. }
  70. TEST_F(RuntimeLibraryTest, hasSymbol)
  71. {
  72. ls::std::os::RuntimeLibrary runtimeLibrary{};
  73. ls::std::core::type::runtime_library_entry entry = ::std::make_pair<::std::string, void *>("_func", (void *) ::std::make_shared<int>().get());
  74. ASSERT_TRUE(runtimeLibrary.addSymbol(entry));
  75. ASSERT_TRUE(runtimeLibrary.hasSymbol("_func"));
  76. }
  77. TEST_F(RuntimeLibraryTest, hasSymbol_not_available)
  78. {
  79. ls::std::os::RuntimeLibrary runtimeLibrary{};
  80. ASSERT_FALSE(runtimeLibrary.hasSymbol("_func"));
  81. }
  82. }