diff --git a/tests/camera2/CameraModuleFixture.h b/tests/camera2/CameraModuleFixture.h index 0bb0e7d7..bf82a97f 100644 --- a/tests/camera2/CameraModuleFixture.h +++ b/tests/camera2/CameraModuleFixture.h @@ -22,6 +22,7 @@ #include "hardware/hardware.h" #include "hardware/camera2.h" +#include #include #include @@ -54,15 +55,17 @@ struct CameraModuleFixture { void SetUp() { TEST_EXTENSION_FORKING_SET_UP; + camera_module_t *rawModule; ASSERT_LE(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, - (const hw_module_t **)&mModule)) << "Could not load camera module"; - ASSERT_NE((void*)0, mModule); + (const hw_module_t **)&rawModule)) << "Could not load camera module"; + ASSERT_NE((void*)0, rawModule); + mModule = new CameraModule(rawModule); - mNumberOfCameras = mModule->get_number_of_cameras(); + mNumberOfCameras = mModule->getNumberOfCameras(); ASSERT_LE(0, mNumberOfCameras); ASSERT_LE( - CAMERA_MODULE_API_VERSION_2_0, mModule->common.module_api_version) + CAMERA_MODULE_API_VERSION_2_0, mModule->getRawModule()->module_api_version) << "Wrong module API version"; /* For using this fixture in other tests only */ @@ -72,6 +75,7 @@ struct CameraModuleFixture { void TearDown() { TEST_EXTENSION_FORKING_TEAR_DOWN; + delete mModule; TearDownMixin(); /* important: device must be destructed before closing module, @@ -79,14 +83,14 @@ struct CameraModuleFixture { mDevice.clear(); if (!TEST_EXTENSION_FORKING_ENABLED) { - ASSERT_EQ(0, HWModuleHelpers::closeModule(&mModule->common)) + ASSERT_EQ(0, HWModuleHelpers::closeModule(mModule->getRawModule())) << "Failed to close camera HAL module"; } } void CreateCamera(int cameraID, /*out*/ sp *device) { struct camera_info info; - ASSERT_EQ(OK, mModule->get_camera_info(cameraID, &info)); + ASSERT_EQ(OK, mModule->getCameraInfo(cameraID, &info)); ASSERT_GE((int)info.device_version, CAMERA_DEVICE_API_VERSION_2_0) << "Device version too old for camera " << cameraID << ". Version: " << @@ -116,7 +120,7 @@ struct CameraModuleFixture { int getDeviceVersion(int cameraId, status_t* status = NULL) { camera_info info; status_t res; - res = mModule->get_camera_info(cameraId, &info); + res = mModule->getCameraInfo(cameraId, &info); if (status != NULL) *status = res; return info.device_version; @@ -147,7 +151,7 @@ private: protected: int mNumberOfCameras; - camera_module_t *mModule; + CameraModule *mModule; sp mDevice; private: diff --git a/tests/camera2/CameraModuleTests.cpp b/tests/camera2/CameraModuleTests.cpp index 828c56a1..2e85d81a 100644 --- a/tests/camera2/CameraModuleTests.cpp +++ b/tests/camera2/CameraModuleTests.cpp @@ -93,11 +93,7 @@ TEST_F(CameraModuleTest, LoadModuleBadIndices) { for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) { String8 deviceName = String8::format("%d", idx[i]); - status_t res = - mModule->common.methods->open( - &mModule->common, - deviceName, - &device); + status_t res = mModule->open(deviceName, &device); EXPECT_NE(OK, res); EXPECT_EQ(-ENODEV, res) << "Incorrect error code when trying to open camera with invalid id " @@ -111,7 +107,7 @@ TEST_F(CameraModuleTest, GetCameraInfo) { for (int i = 0; i < mNumberOfCameras; ++i) { struct camera_info info; - ASSERT_EQ(OK, mModule->get_camera_info(i, &info)); + ASSERT_EQ(OK, mModule->getCameraInfo(i, &info)); } } @@ -123,8 +119,8 @@ TEST_F(CameraModuleTest, GetCameraInfoBadIndices) { int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 }; for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) { struct camera_info info; - EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info)); - EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info)) + EXPECT_NE(OK, mModule->getCameraInfo(idx[i], &info)); + EXPECT_EQ(-ENODEV, mModule->getCameraInfo(idx[i], &info)) << "Incorrect error code for get_camera_info idx= " << idx[i]; } diff --git a/tests/camera2/camera2_utils.cpp b/tests/camera2/camera2_utils.cpp index 9cc6c905..930b909a 100644 --- a/tests/camera2/camera2_utils.cpp +++ b/tests/camera2/camera2_utils.cpp @@ -580,7 +580,7 @@ void FrameWaiter::onFrameAvailable(const BufferItem& /* item */) { mCondition.signal(); } -int HWModuleHelpers::closeModule(hw_module_t* module) { +int HWModuleHelpers::closeModule(const hw_module_t* module) { int status; if (!module) { diff --git a/tests/camera2/camera2_utils.h b/tests/camera2/camera2_utils.h index c1d1e724..2072eb67 100644 --- a/tests/camera2/camera2_utils.h +++ b/tests/camera2/camera2_utils.h @@ -240,7 +240,7 @@ class FrameWaiter : public CpuConsumer::FrameAvailableListener { struct HWModuleHelpers { /* attempt to unload the library with dlclose */ - static int closeModule(hw_module_t* module); + static int closeModule(const hw_module_t* module); }; }