JniMethodTest.cpp 2.8 KB

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