From 26388ca2f6fc002d26e10ac2b4fdee92f673f5d4 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 31 Mar 2021 20:37:43 +0900 Subject: [PATCH] haltests: Add camera HAL test [Version] 0.0.4 [Issue Type] HAL test Change-Id: Ic90c80e759580031634824ffc988827d35d524d8 Signed-off-by: Jeongmo Yang --- CMakeLists.txt | 4 +- hal-api-camera-haltests.manifest | 6 + packaging/hal-api-camera.spec | 16 +- tests/CMakeLists.txt | 22 + tests/camera_hal_test.cpp | 1399 ++++++++++++++++++++++++++++++ 5 files changed, 1445 insertions(+), 2 deletions(-) create mode 100644 hal-api-camera-haltests.manifest create mode 100644 tests/CMakeLists.txt create mode 100644 tests/camera_hal_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fb6cb8d..8160c0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(hal-api-camera C) +PROJECT(hal-api-camera) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin") @@ -48,3 +48,5 @@ INSTALL(DIRECTORY include/ DESTINATION include/hal INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) +ADD_SUBDIRECTORY(tests) + diff --git a/hal-api-camera-haltests.manifest b/hal-api-camera-haltests.manifest new file mode 100644 index 0000000..81ace0c --- /dev/null +++ b/hal-api-camera-haltests.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/packaging/hal-api-camera.spec b/packaging/hal-api-camera.spec index f0da78d..eee5d06 100644 --- a/packaging/hal-api-camera.spec +++ b/packaging/hal-api-camera.spec @@ -4,7 +4,7 @@ ### main package ######### Name: %{name} Summary: %{name} interface -Version: 0.0.3 +Version: 0.0.4 Release: 0 Group: Development/Libraries License: Apache-2.0 @@ -15,6 +15,8 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(gmock) +BuildRequires: pkgconfig(capi-system-info) %description %{name} interface package for product vendor developer @@ -29,6 +31,14 @@ Requires: %{name} = %{version}-%{release} %description devel %{name} interface development package for product vendor developer +### test package ######### +%package haltests +Summary: tests for %{name} +Requires: %{name} = %{version} + +%description haltests +Haltests for %{name} + ### build and install ######### %prep @@ -66,3 +76,7 @@ rm -rf %{buildroot} %{_libdir}/hal/*.so %{_libdir}/pkgconfig/*.pc +%files haltests +%manifest %{name}-haltests.manifest +%{_bindir}/hal/camera-haltests + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..3b8d514 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,22 @@ +SET(HAL_CAMERA_TEST "camera-haltests") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Werror") + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ HALTEST_SRCS) +ADD_EXECUTABLE(${HAL_CAMERA_TEST} ${HALTEST_SRCS}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${HAL_CAMERA_TEST} REQUIRED glib-2.0 gmock capi-system-info) + +FOREACH(flag ${${HAL_CAMERA_TEST}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIC -pie -Wall") + +TARGET_LINK_LIBRARIES(${HAL_CAMERA_TEST} ${PROJECT_NAME} ${${HAL_CAMERA_TEST}_LDFLAGS}) +SET_TARGET_PROPERTIES(${HAL_CAMERA_TEST} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${HAL_CAMERA_TEST} PROPERTIES LINK_FLAGS "-pie") + +INSTALL(TARGETS ${HAL_CAMERA_TEST} DESTINATION ${EXEC_PREFIX}/hal/) + diff --git a/tests/camera_hal_test.cpp b/tests/camera_hal_test.cpp new file mode 100644 index 0000000..b07c226 --- /dev/null +++ b/tests/camera_hal_test.cpp @@ -0,0 +1,1399 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +static int ret; +static int g_ret_release_preview_buffer; +static int g_ret_release_video_buffer; +static void *g_hal_handle; +static camera_device_info_list_s g_device_info_list; +static camera_format_s g_preview_format; +static camera_format_s g_video_format; +static GMutex g_msg_cb_lock; +static GCond g_msg_cb_cond; +static bool g_camera_supported; +static bool g_preview_check; +static bool g_capture_check; +static bool g_video_check; + +#define CAMERA_SUPPORT_CHECK \ + do {\ + if (!g_camera_supported) {\ + cout << "CAMERA NOT SUPPORTED" << endl;\ + ASSERT_EQ(ret, CAMERA_ERROR_DEVICE_NOT_SUPPORTED);\ + return;\ + }\ + } while (0) + +/* + * callback + */ +static int _PreviewCb(camera_buffer_s *buffer, camera_metadata_s *meta, void *user_data) +{ + void *hal_handle = user_data; + + if (!hal_handle) { + cout << "NULL handle" << endl; + return -1; + } + + if (!buffer) { + cout << "NULL buffer" << endl; + return -1; + } + + g_preview_check = true; + + g_ret_release_preview_buffer = hal_camera_release_preview_buffer(hal_handle, buffer->index); + + cout << "preview buffer index [" << buffer->index << "], ret " << g_ret_release_preview_buffer << endl; + + return 0; +} + +static int _CaptureCb(camera_buffer_s *main, camera_buffer_s *postview, camera_buffer_s *thumbnail, void *user_data) +{ + if (!main) { + cout << "NULL buffer" << endl; + return -1; + } + + cout << "capture callback invoked" << endl; + + g_capture_check = true; + + return 0; +} + +static int _VideoCb(camera_buffer_s *buffer, camera_metadata_s *meta, void *user_data) +{ + void *hal_handle = user_data; + + if (!hal_handle) { + cout << "NULL handle" << endl; + return -1; + } + + if (!buffer) { + cout << "NULL buffer" << endl; + return -1; + } + + g_video_check = true; + + g_ret_release_video_buffer = hal_camera_release_video_buffer(hal_handle, buffer->index); + + cout << "video buffer index [" << buffer->index << "], ret " << g_ret_release_video_buffer << endl; + + return 0; +} + +static int _MessageCb(camera_message_s *message, void *user_data) +{ + if (!message) { + cout << "NULL message" << endl; + return -1; + } + + cout << "message - type " << message->type << endl; + + g_mutex_lock(&g_msg_cb_lock); + + switch (message->type) { + case CAMERA_MESSAGE_TYPE_FOCUS_CHANGED: + cout << "focus changed : " << message->focus_state << endl; + if (message->focus_state == CAMERA_FOCUS_STATE_FOCUSED || + message->focus_state == CAMERA_FOCUS_STATE_FAILED) { + g_cond_signal(&g_msg_cb_cond); + } + break; + case CAMERA_MESSAGE_TYPE_CAPTURED: + cout << "captured" << endl; + g_cond_signal(&g_msg_cb_cond); + break; + case CAMERA_MESSAGE_TYPE_HDR_PROGRESS: + cout << "HDR progress " << message->hdr_progress << endl; + g_cond_signal(&g_msg_cb_cond); + break; + case CAMERA_MESSAGE_TYPE_ERROR: + cout << "error " << message->error_code << endl; + break; + default: + cout << "unknown message " << message->type << endl; + break; + } + + g_mutex_unlock(&g_msg_cb_lock); + + return 0; +} + + +/* + * main class + */ +class CameraHalTest : public testing::Test +{ + public: + virtual void SetUp() + { + g_camera_supported = false; + + system_info_get_platform_bool("http://tizen.org/feature/camera", &g_camera_supported); + + ret = hal_camera_init(NULL, &g_hal_handle); + if (ret != CAMERA_ERROR_NONE) { + cout << "camera hal init failed " << ret << endl; + return; + } + + ret = hal_camera_get_device_info_list(g_hal_handle, &g_device_info_list); + if (ret != CAMERA_ERROR_NONE) { + cout << "get device list failed " << ret << endl; + return; + } + + ret = GetSupportedFormat(0); + } + + virtual void TearDown() + { + if (g_hal_handle) { + ret = hal_camera_deinit(g_hal_handle); + g_hal_handle = nullptr; + } + } + + int GetSupportedFormat(int index) + { + if (g_device_info_list.count < 1) { + cout << "no available camera device" << endl; + return CAMERA_ERROR_DEVICE_NOT_SUPPORTED; + } + + /* set preview format */ + g_preview_format.stream_format = g_device_info_list.device_info[index].format_list.formats[0]; + g_preview_format.stream_resolution.width = g_device_info_list.device_info[index].preview_list.resolutions[0].width; + g_preview_format.stream_resolution.height = g_device_info_list.device_info[index].preview_list.resolutions[0].height; + g_preview_format.stream_fps = 15; + g_preview_format.stream_rotation = CAMERA_ROTATION_0; + g_preview_format.capture_format = g_device_info_list.device_info[index].format_list.formats[0]; + g_preview_format.capture_resolution.width = g_device_info_list.device_info[index].capture_list.resolutions[0].width; + g_preview_format.capture_resolution.height = g_device_info_list.device_info[index].capture_list.resolutions[0].height; + g_preview_format.capture_quality = 95; + + /* set video format */ + g_video_format.stream_format = g_device_info_list.device_info[index].format_list.formats[0]; + g_video_format.stream_resolution.width = g_device_info_list.device_info[index].video_list.resolutions[0].width; + g_video_format.stream_resolution.height = g_device_info_list.device_info[index].video_list.resolutions[0].height; + g_video_format.stream_fps = 15; + g_video_format.stream_rotation = CAMERA_ROTATION_0; + g_video_format.capture_format = g_device_info_list.device_info[index].format_list.formats[0]; + g_video_format.capture_resolution.width = g_device_info_list.device_info[index].capture_list.resolutions[0].width; + g_video_format.capture_resolution.height = g_device_info_list.device_info[index].capture_list.resolutions[0].height; + g_video_format.capture_quality = 95; + + return CAMERA_ERROR_NONE; + } +}; + + +/** + * @testcase InitP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Initialize camera HAL handle + * @apicovered hal_camera_init + * @passcase when hal_camera_init returns CAMERA_ERROR_NONE and the handle "h" is not a NULL pointer + * @failcase when handle "h" is a NULL pointer + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, InitP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); +} + +/** + * @testcase DeinitP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Deinitialize camera HAL handle + * @apicovered hal_camera_init, hal_camera_deinit + * @passcase when hal_camera_deinit returns CAMERA_ERROR_NONE + * @failcase when hal_camera_deinit does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, DeinitP) +{ + void *hal_handle = nullptr; + + CAMERA_SUPPORT_CHECK; + + ret = hal_camera_init(NULL, &hal_handle); + + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + ASSERT_NE(hal_handle, nullptr); + + if (hal_handle) { + ret = hal_camera_deinit(hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + hal_handle = nullptr; + } +} + +/** + * @testcase GetDeviceInfoListP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Get the list of device information + * @apicovered hal_camera_get_device_info_list + * @passcase when hal_camera_get_device_info_list returns CAMERA_ERROR_NONE + * @failcase when hal_camera_get_device_info_list does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetDeviceInfoListP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); +} + +/** + * @testcase GetDeviceInfoListN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Get the list of device information + * @apicovered hal_camera_get_device_info_list + * @passcase when hal_camera_get_device_info_list returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_get_device_info_list does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetDeviceInfoListN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + + ret = hal_camera_get_device_info_list(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); +} + +/** + * @testcase OpenDeviceP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Open camera device + * @apicovered hal_camera_open_device + * @passcase when hal_camera_open_device returns CAMERA_ERROR_NONE + * @failcase when hal_camera_open_device does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, OpenDeviceP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + if (g_device_info_list.count > 0) { + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + if (ret == CAMERA_ERROR_NONE) + hal_camera_close_device(g_hal_handle); + } +} + +/** + * @testcase OpenDeviceN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Open camera device + * @apicovered hal_camera_open_device + * @passcase when hal_camera_open_device does not return CAMERA_ERROR_NONE + * @failcase when hal_camera_open_device returns CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, OpenDeviceN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + if (g_device_info_list.count > 0) { + ret = hal_camera_open_device(NULL, g_device_info_list.device_info[g_device_info_list.count - 1].index + 1); + EXPECT_NE(ret, CAMERA_ERROR_NONE); + + if (ret == CAMERA_ERROR_NONE) + hal_camera_close_device(g_hal_handle); + } +} + +/** + * @testcase CloseDeviceP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Close camera device + * @apicovered hal_camera_open_device, hal_camera_close_device + * @passcase when hal_camera_close_device returns CAMERA_ERROR_NONE + * @failcase when hal_camera_close_device does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, CloseDeviceP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + if (g_device_info_list.count > 0) { + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + if (ret == CAMERA_ERROR_NONE) { + ret = hal_camera_close_device(g_hal_handle); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + } + } +} + +/** + * @testcase SetPreviewStreamFormatP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Set the stream format for preview in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format + * @passcase when hal_camera_set_preview_stream_format returns CAMERA_ERROR_NONE + * @failcase when hal_camera_set_preview_stream_format does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, SetPreviewStreamFormatP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase SetPreviewStreamFormatN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Set the stream format for preview in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format + * @passcase when hal_camera_set_preview_stream_format returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_set_preview_stream_format does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, SetPreviewStreamFormatN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, nullptr); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase GetPreviewStreamFormatP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Get the stream format for preview in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_get_preview_stream_format + * @passcase when hal_camera_get_preview_stream_format returns CAMERA_ERROR_NONE and result is same with previous set format + * @failcase when hal_camera_get_preview_stream_format does not return CAMERA_ERROR_NONE or result is different with previous set format + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetPreviewStreamFormatP) +{ + camera_format_s get_format; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + memset(&get_format, 0x0, sizeof(camera_format_s)); + + ret = hal_camera_get_preview_stream_format(g_hal_handle, &get_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = memcmp(&g_preview_format, &get_format, sizeof(camera_format_s)); + EXPECT_EQ(ret, 0); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase GetPreviewStreamFormatN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Get the stream format for preview in camera + * @apicovered hal_camera_open_device, hal_camera_get_preview_stream_format + * @passcase when hal_camera_get_preview_stream_format returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_get_preview_stream_format does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetPreviewStreamFormatN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_get_preview_stream_format(g_hal_handle, nullptr); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartPreviewP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Start the preview stream in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview + * @passcase when hal_camera_start_preview returns CAMERA_ERROR_NONE + * @failcase when hal_camera_start_preview does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartPreviewP) +{ + unsigned int i = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + for (i = 0 ; i < g_device_info_list.count ; i++) { + cout << "Device Index " << i << endl; + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[i].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + GetSupportedFormat(i); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_preview_check = false; + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for preview frame */ + sleep(1); + + EXPECT_TRUE(g_preview_check); + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); + } +} + +/** + * @testcase StartPreviewN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Start the preview stream in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview + * @passcase when hal_camera_start_preview returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_start_preview does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartPreviewN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, nullptr, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StopPreviewP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Stop the preview stream in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_stop_preview + * @passcase when hal_camera_stop_preview returns CAMERA_ERROR_NONE + * @failcase when hal_camera_stop_preview does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StopPreviewP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_stop_preview(g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartCaptureP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Start the image capture in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_start_capture + * @passcase when hal_camera_start_capture returns CAMERA_ERROR_NONE + * @failcase when hal_camera_start_capture does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartCaptureP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_capture_check = false; + + ret = hal_camera_start_capture(g_hal_handle, _CaptureCb, NULL); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for capture frame */ + sleep(1); + + EXPECT_TRUE(g_capture_check); + + hal_camera_stop_capture(g_hal_handle); + } else { + cout << "NOT SUPPORTED : CAPTURE" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartCaptureN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Start the image capture in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_start_capture + * @passcase when hal_camera_start_capture returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_start_capture does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartCaptureN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_capture(g_hal_handle, nullptr, NULL); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StopCaptureP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Stop the image capture in camera + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_start_capture, hal_camera_stop_capture + * @passcase when hal_camera_stop_capture returns CAMERA_ERROR_NONE + * @failcase when hal_camera_stop_capture does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StopCaptureP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_capture(g_hal_handle, _CaptureCb, NULL); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for capture frame */ + sleep(1); + + ret = hal_camera_stop_capture(g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + } else { + cout << "NOT SUPPORTED : CAPTURE" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase SetVideoStreamFormatP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Set the stream format for video in camera + * @apicovered hal_camera_open_device, hal_camera_set_video_stream_format + * @passcase when hal_camera_set_video_stream_format returns CAMERA_ERROR_NONE + * @failcase when hal_camera_set_video_stream_format does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, SetVideoStreamFormatP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + else + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase SetVideoStreamFormatN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Set the stream format for video in camera + * @apicovered hal_camera_open_device, hal_camera_set_video_stream_format + * @passcase when hal_camera_set_video_stream_format returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_set_video_stream_format does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, SetVideoStreamFormatN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, nullptr); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase GetVideoStreamFormatP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Get the stream format for video in camera + * @apicovered hal_camera_open_device, hal_camera_set_video_stream_format, hal_camera_get_video_stream_format + * @passcase when hal_camera_get_video_stream_format returns CAMERA_ERROR_NONE and result is same with previous set format + * @failcase when hal_camera_get_video_stream_format does not return CAMERA_ERROR_NONE or result is different with previous set format + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetVideoStreamFormatP) +{ + camera_format_s get_format; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + memset(&get_format, 0x0, sizeof(camera_format_s)); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_get_video_stream_format(g_hal_handle, &get_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = memcmp(&g_video_format, &get_format, sizeof(camera_format_s)); + EXPECT_EQ(ret, 0); + } else { + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + } + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase GetVideoStreamFormatN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Get the stream format for video in camera + * @apicovered hal_camera_open_device, hal_camera_get_video_stream_format + * @passcase when hal_camera_get_video_stream_format returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_get_video_stream_format does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, GetVideoStreamFormatN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_get_video_stream_format(g_hal_handle, nullptr); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartRecordP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Start the record to get video frames + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_set_video_stream_format, hal_camera_start_record + * @passcase when hal_camera_start_record returns CAMERA_ERROR_NONE + * @failcase when hal_camera_start_record does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartRecordP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_video_check = false; + + ret = hal_camera_start_record(g_hal_handle, _VideoCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for video frame */ + sleep(1); + + EXPECT_TRUE(g_video_check); + + hal_camera_stop_record(g_hal_handle); + } else { + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartRecordN + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Start the record to get video frames + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_set_video_stream_format, hal_camera_start_record + * @passcase when hal_camera_start_record returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_start_record does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartRecordN) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_record(g_hal_handle, nullptr, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + } else { + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StopRecordP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Stop the record + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_set_video_stream_format, hal_camera_start_record, hal_camera_stop_record + * @passcase when hal_camera_stop_record returns CAMERA_ERROR_NONE + * @failcase when hal_camera_stop_record does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StopRecordP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_record(g_hal_handle, _VideoCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for video frame */ + sleep(1); + + ret = hal_camera_stop_record(g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + } else { + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase AddMessageCallbackP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Add message callback to receive message from camera HAL + * @apicovered hal_camera_open_device, hal_camera_add_message_callback + * @passcase when hal_camera_add_message_callback returns CAMERA_ERROR_NONE + * @failcase when hal_camera_add_message_callback does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, AddMessageCallbackP) +{ + uint32_t cb_id = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, _MessageCb, nullptr, &cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + if (ret == CAMERA_ERROR_NONE) + hal_camera_remove_message_callback(g_hal_handle, cb_id); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase AddMessageCallbackN1 + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Add message callback to receive message from camera HAL + * @apicovered hal_camera_open_device, hal_camera_add_message_callback + * @passcase when hal_camera_add_message_callback returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_add_message_callback does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, AddMessageCallbackN1) +{ + uint32_t cb_id = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, nullptr, nullptr, &cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase AddMessageCallbackN2 + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Negative, Add message callback to receive message from camera HAL + * @apicovered hal_camera_open_device, hal_camera_add_message_callback + * @passcase when hal_camera_add_message_callback returns CAMERA_ERROR_INVALID_PARAMETER + * @failcase when hal_camera_add_message_callback does not return CAMERA_ERROR_INVALID_PARAMETER + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, AddMessageCallbackN2) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, _MessageCb, nullptr, nullptr); + EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER); + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase RemoveMessageCallbackP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Remove message callback + * @apicovered hal_camera_open_device, hal_camera_add_message_callback, hal_camera_remove_message_callback + * @passcase when hal_camera_remove_message_callback returns CAMERA_ERROR_NONE + * @failcase when hal_camera_remove_message_callback does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, RemoveMessageCallbackP) +{ + uint32_t cb_id = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, _MessageCb, nullptr, &cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + if (ret == CAMERA_ERROR_NONE) { + ret = hal_camera_remove_message_callback(g_hal_handle, cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + } + + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StartAutoFocusP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Start auto focus + * @apicovered hal_camera_open_device, hal_camera_add_message_callback, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_start_auto_focus + * @passcase when hal_camera_start_auto_focus return CAMERA_ERROR_NONE and focus message is come in time + * @failcase when hal_camera_start_auto_focus does not return CAMERA_ERROR_NONE or focus message is not come in time + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StartAutoFocusP) +{ + uint32_t cb_id = 0; + gint64 end_time = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, _MessageCb, nullptr, &cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_mutex_lock(&g_msg_cb_lock); + + ret = hal_camera_start_auto_focus(g_hal_handle); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait a message and check result */ + end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND * 3; + EXPECT_EQ(g_cond_wait_until(&g_msg_cb_cond, &g_msg_cb_lock, end_time), true); + } else { + cout << "NOT SUPPORTED : AUTO FOCUS" << endl; + } + + g_mutex_unlock(&g_msg_cb_lock); + + hal_camera_stop_preview(g_hal_handle); + hal_camera_remove_message_callback(g_hal_handle, cb_id); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase StopAutoFocusP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Stop auto focus + * @apicovered hal_camera_open_device, hal_camera_add_message_callback, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_start_auto_focus, hal_camera_stop_auto_focus + * @passcase when hal_camera_stop_auto_focus returns CAMERA_ERROR_NONE + * @failcase when hal_camera_stop_auto_focus does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, StopAutoFocusP) +{ + uint32_t cb_id = 0; + + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_add_message_callback(g_hal_handle, _MessageCb, nullptr, &cb_id); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_auto_focus(g_hal_handle); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_stop_auto_focus(g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + } else { + cout << "NOT SUPPORTED : AUTO FOCUS" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_remove_message_callback(g_hal_handle, cb_id); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase ReleasePreviewBufferP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Release preview buffer to get new frame in it + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_release_preview_buffer + * @passcase when hal_camera_release_preview_buffer returns CAMERA_ERROR_NONE + * @failcase when hal_camera_release_preview_buffer does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, ReleasePreviewBufferP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_ret_release_preview_buffer = CAMERA_ERROR_INTERNAL; + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for preview frame */ + sleep(1); + + EXPECT_EQ(g_ret_release_preview_buffer, CAMERA_ERROR_NONE); + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + +/** + * @testcase ReleaseVideoBufferP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(haesu.gwon) + * @type auto + * @description Positive, Release video buffer to get new frame in it + * @apicovered hal_camera_open_device, hal_camera_set_preview_stream_format, hal_camera_start_preview, hal_camera_set_video_stream_format, hal_camera_start_record, hal_camera_release_video_buffer + * @passcase when hal_camera_release_video_buffer returns CAMERA_ERROR_NONE + * @failcase when hal_camera_release_video_buffer does not return CAMERA_ERROR_NONE + * @precondition None + * @postcondition None + */ +TEST_F(CameraHalTest, ReleaseVideoBufferP) +{ + CAMERA_SUPPORT_CHECK; + + ASSERT_NE(g_hal_handle, nullptr); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_open_device(g_hal_handle, g_device_info_list.device_info[0].index); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_preview_stream_format(g_hal_handle, &g_preview_format); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_start_preview(g_hal_handle, _PreviewCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + ret = hal_camera_set_video_stream_format(g_hal_handle, &g_video_format); + + if (ret != CAMERA_ERROR_DEVICE_NOT_SUPPORTED) { + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + g_ret_release_video_buffer = CAMERA_ERROR_INTERNAL; + + ret = hal_camera_start_record(g_hal_handle, _VideoCb, (void *)g_hal_handle); + EXPECT_EQ(ret, CAMERA_ERROR_NONE); + + /* wait for video frame */ + sleep(1); + + EXPECT_EQ(g_ret_release_video_buffer, CAMERA_ERROR_NONE); + + hal_camera_stop_record(g_hal_handle); + } else { + cout << "NOT SUPPORTED : VIDEO STREAM" << endl; + } + + hal_camera_stop_preview(g_hal_handle); + hal_camera_close_device(g_hal_handle); +} + + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} -- 2.34.1