summaryrefslogtreecommitdiff
path: root/libnativeloader/native_loader_api_test.cpp
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2024-04-18 21:26:10 +0100
committer Martin Stjernholm <mast@google.com> 2024-04-24 13:07:20 +0000
commite337c94fc7245e60ce09815faedd59b26406f160 (patch)
treec1b623be0e6c1399003f6c8b8a6fe48e7ec9a69b /libnativeloader/native_loader_api_test.cpp
parent1dc111804f9ea778bce6258ffd10fed80fb02d0c (diff)
Clean up the test mocks.
Split them up so that the API tests only have the JNI mock that they need, and the "platform" mock - which is nonfunctional there - is not present. Also a few other code cleanups. Test: atest libnativeloader_test \ art_libnativeloader_cts_test \ libnativeloader_lazy_test Bug: 335224367 Change-Id: Ifabc64db43e0346d5aefc9809266190690178ebf
Diffstat (limited to 'libnativeloader/native_loader_api_test.cpp')
-rw-r--r--libnativeloader/native_loader_api_test.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/libnativeloader/native_loader_api_test.cpp b/libnativeloader/native_loader_api_test.cpp
index 78fb29f91d..aeda1cc2a7 100644
--- a/libnativeloader/native_loader_api_test.cpp
+++ b/libnativeloader/native_loader_api_test.cpp
@@ -14,9 +14,12 @@
* limitations under the License.
*/
-#if defined(ART_TARGET_ANDROID)
+#include <memory>
+#include <string>
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
+#include "jni.h"
#include "native_loader_test.h"
#include "nativehelper/scoped_utf_chars.h"
#include "nativeloader/native_loader.h"
@@ -35,7 +38,7 @@ using ::testing::StrEq;
class NativeLoaderLazyTest : public ::testing::Test {
protected:
void SetUp() override {
- mock = std::make_unique<testing::NiceMock<MockPlatform>>(false);
+ jni_mock = std::make_unique<testing::NiceMock<MockJni>>();
env = std::make_unique<JNIEnv>();
env->functions = CreateJNINativeInterface();
}
@@ -45,11 +48,11 @@ class NativeLoaderLazyTest : public ::testing::Test {
// reset libnativeloader internal state. Hence be sure to not reuse the same
// class loader/namespace names.
delete env->functions;
- mock.reset();
+ jni_mock.reset();
}
void CallCreateClassLoaderNamespace(const char* class_loader) {
- ON_CALL(*mock, JniObject_getParent(StrEq(class_loader))).WillByDefault(Return(nullptr));
+ ON_CALL(*jni_mock, JniObject_getParent(StrEq(class_loader))).WillByDefault(Return(nullptr));
jstring err = CreateClassLoaderNamespace(env.get(),
17,
@@ -123,5 +126,3 @@ TEST_F(NativeLoaderLazyTest, NativeLoaderFreeErrorMessage) {
} // namespace nativeloader
} // namespace android
-
-#endif // defined(ART_TARGET_ANDROID)