JniMethodTest.cpp 2.7 KB

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