JniMethodTest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-04-08
  6. * Changed: 2023-04-10
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core-jni.hpp>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <memory>
  13. using ls::std::core::IllegalArgumentException;
  14. using ls::std::core::experimental::JniMethod;
  15. using std::make_shared;
  16. using testing::Test;
  17. namespace
  18. {
  19. class JniMethodTest : public Test
  20. {
  21. public:
  22. JniMethodTest() = default;
  23. ~JniMethodTest() override = default;
  24. };
  25. TEST_F(JniMethodTest, constructor_empty_method_identifier)
  26. {
  27. EXPECT_THROW(
  28. {
  29. try
  30. {
  31. JniMethod method("", "()B");
  32. }
  33. catch (const IllegalArgumentException &_exception)
  34. {
  35. throw;
  36. }
  37. },
  38. IllegalArgumentException);
  39. }
  40. TEST_F(JniMethodTest, constructor_empty_method_signature)
  41. {
  42. EXPECT_THROW(
  43. {
  44. try
  45. {
  46. JniMethod method("getDay", "");
  47. }
  48. catch (const IllegalArgumentException &_exception)
  49. {
  50. throw;
  51. }
  52. },
  53. IllegalArgumentException);
  54. }
  55. TEST_F(JniMethodTest, getMethodId)
  56. {
  57. JniMethod method{"getDay", "()B"};
  58. ASSERT_TRUE(method.getMethodId() == nullptr);
  59. }
  60. TEST_F(JniMethodTest, getMethodIdentifier)
  61. {
  62. JniMethod method{"getDay", "()B"};
  63. ASSERT_STREQ("getDay", method.getMethodIdentifier().c_str());
  64. }
  65. TEST_F(JniMethodTest, getMethodSignature)
  66. {
  67. JniMethod method{"getDay", "()B"};
  68. ASSERT_STREQ("()B", method.getMethodSignature().c_str());
  69. }
  70. TEST_F(JniMethodTest, setMethodId)
  71. {
  72. JniMethod method{"getDay", "()B"};
  73. jmethodID methodId = (jmethodID) make_shared<int>().get();
  74. method.setMethodId(methodId);
  75. ASSERT_TRUE(method.getMethodId() == methodId);
  76. }
  77. TEST_F(JniMethodTest, setMethodIdentifier)
  78. {
  79. JniMethod method{"getDay", "()B"};
  80. method.setMethodIdentifier("getHour");
  81. ASSERT_STREQ("getHour", method.getMethodIdentifier().c_str());
  82. }
  83. TEST_F(JniMethodTest, setMethodSignature)
  84. {
  85. JniMethod method{"getDay", "()B"};
  86. method.setMethodSignature("()I");
  87. ASSERT_STREQ("()I", method.getMethodSignature().c_str());
  88. }
  89. }