summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeongmo Yang <jm80.yang@samsung.com>2018-03-15 17:51:04 +0900
committerJeongmo Yang <jm80.yang@samsung.com>2018-04-09 13:44:43 +0900
commita6fcce5f75411988c77f019b037897265c3edb4b (patch)
treeeed31543496c29126c67a1eb07b1619d7a2a1949
parent4210cfb8e601b796f37cbff53c1725a4056aa744 (diff)
downloadmm-hal-interface-a6fcce5f75411988c77f019b037897265c3edb4b.tar.gz
mm-hal-interface-a6fcce5f75411988c77f019b037897265c3edb4b.tar.bz2
mm-hal-interface-a6fcce5f75411988c77f019b037897265c3edb4b.zip
Add testcase for multimedia HAL APIs
- usage 1) set up build environment for testcase $ ./tc_env_setup.sh y $ [run gbs build command] 2) remove build environment for testcase $ ./tc_env_setup.sh n $ [run gbs build command] [Version] 0.0.4 [Profile] Common [Issue Type] Update [Dependency module] N/A Change-Id: If1f952f3b3089afbed3191aba5bf49c66d192827 Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
-rw-r--r--include/camera/tizen-camera.h26
-rw-r--r--packaging/mm-hal-interface.spec4
-rw-r--r--packaging/mm-hal-testcase.spec.bak45
-rwxr-xr-xtc_env_setup.sh56
-rw-r--r--testcase/Makefile.am4
-rw-r--r--testcase/build/Makefile.am2
-rwxr-xr-xtestcase/build/autogen.sh7
-rw-r--r--testcase/build/configure.ac46
-rw-r--r--testcase/build/mm-hal-testcase.manifest5
-rw-r--r--testcase/camera/Makefile.am14
-rw-r--r--testcase/camera/camera_hal_interface.c591
-rw-r--r--testcase/camera/camera_hal_interface.h56
-rw-r--r--testcase/camera/camera_hal_tc.cpp709
13 files changed, 1550 insertions, 15 deletions
diff --git a/include/camera/tizen-camera.h b/include/camera/tizen-camera.h
index f44d3df..399ae96 100644
--- a/include/camera/tizen-camera.h
+++ b/include/camera/tizen-camera.h
@@ -579,7 +579,7 @@ typedef struct camera_interface {
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
* @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @post If it succeeds, the camera state will be #CAMERA_STATE_INITIALIZED.
*
* @see camera_deinit()
@@ -605,7 +605,7 @@ int camera_deinit(void *camera_handle);
* @return @c 0 on success, otherwise a negative error value
* @retval #CAMERA_ERROR_NONE Successful
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
*/
int camera_get_device_list(void *camera_handle, camera_device_list_t *device_list);
@@ -620,7 +620,7 @@ int camera_get_device_list(void *camera_handle, camera_device_list_t *device_lis
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
* @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
* @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @retval #CAMERA_ERROR_DEVICE_NOT_FOUND Failed to find camera device
* @retval #CAMERA_ERROR_DEVICE_UNAVAILABLE The camera device is unavailable
* @pre The camera state must be set to #CAMERA_STATE_INITIALIZED.
@@ -680,7 +680,7 @@ int camera_remove_message_callback(void *camera_handle, uint32_t cb_id);
* @retval #CAMERA_ERROR_NONE Successful
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @pre The camera state must be set to #CAMERA_STATE_OPENED.
* @see camera_start_preview()
* @see camera_start_capture()
@@ -697,7 +697,7 @@ int camera_set_preview_stream_format(void *camera_handle, camera_format_t *forma
* @retval #CAMERA_ERROR_NONE Successful
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @see camera_start_preview()
* @see camera_start_capture()
* @see camera_set_preview_stream_format()
@@ -763,7 +763,7 @@ int camera_stop_preview(void *camera_handle);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @pre The camera state must be set to #CAMERA_STATE_PREVIEWING or #CAMERA_STATE_RECORDING.
* @post The camera focus state will be #CAMERA_FOCUS_STATE_ONGOING.
* @see camera_stop_auto_focus()
@@ -782,7 +782,7 @@ int camera_start_auto_focus(void *camera_handle);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @pre The camera state must be set to #CAMERA_STATE_PREVIEWING or #CAMERA_STATE_RECORDING.
* @post The camera focus state will be #CAMERA_FOCUS_STATE_ONGOING.
* @see camera_start_auto_focus()
@@ -848,7 +848,7 @@ int camera_stop_capture(void *camera_handle);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @pre The camera state must be set to #CAMERA_STATE_OPENED.
* @see camera_start_record()
* @see camera_start_capture()
@@ -865,7 +865,7 @@ int camera_set_video_stream_format(void *camera_handle, camera_format_t *format)
* @retval #CAMERA_ERROR_NONE Successful
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @see camera_start_preview()
* @see camera_start_capture()
* @see camera_set_preview_stream_format()
@@ -885,7 +885,7 @@ int camera_get_video_stream_format(void *camera_handle, camera_format_t *format)
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
* @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @pre The camera state must be #CAMERA_STATE_PREVIEWING.
* @post The camera state will be #CAMERA_STATE_RECORDING.
* @see camera_set_video_stream_format()
@@ -938,7 +938,7 @@ int camera_stop_record(void *camera_handle);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @see camera_get_command()
*/
int camera_set_command(void *camera_handle, int64_t command, void *value);
@@ -954,7 +954,7 @@ int camera_set_command(void *camera_handle, int64_t command, void *value);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @see camera_get_command()
*/
int camera_get_command(void *camera_handle, int64_t command, void *value);
@@ -971,7 +971,7 @@ int camera_get_command(void *camera_handle, int64_t command, void *value);
* @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
* @retval #CAMERA_ERROR_INVALID_STATE Invalid state
- * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @retval #CAMERA_ERROR_DEVICE_NOT_SUPPORTED The feature is not supported
* @see camera_set_command()
* @see camera_get_command()
*/
diff --git a/packaging/mm-hal-interface.spec b/packaging/mm-hal-interface.spec
index 1d87343..ab96996 100644
--- a/packaging/mm-hal-interface.spec
+++ b/packaging/mm-hal-interface.spec
@@ -1,7 +1,7 @@
Name: mm-hal-interface
Summary: Multimedia HAL Interface
-Version: 0.0.3
-Release: 1
+Version: 0.0.4
+Release: 0
Group: Multimedia/Development
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
diff --git a/packaging/mm-hal-testcase.spec.bak b/packaging/mm-hal-testcase.spec.bak
new file mode 100644
index 0000000..c92ecb6
--- /dev/null
+++ b/packaging/mm-hal-testcase.spec.bak
@@ -0,0 +1,45 @@
+Name: mm-hal-testcase
+Summary: Test case for multimedia HAL APIs
+Version: 0.0.1
+Release: 0
+Group: Multimedia/Utility
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: mm-hal-interface
+BuildRequires: gtest-devel
+
+%description
+Test case for multimedia HAL APIs.
+
+
+%prep
+%setup -q
+
+
+%build
+export CFLAGS+=" -D_LARGEFILE64_SOURCE"
+./autogen.sh
+%configure \
+ --enable-tc-camera \
+ --disable-static
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+
+
+%post
+/sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%license LICENSE.APLv2
+%defattr(-,root,root,-)
+%{_bindir}/*
+
diff --git a/tc_env_setup.sh b/tc_env_setup.sh
new file mode 100755
index 0000000..f3b2a97
--- /dev/null
+++ b/tc_env_setup.sh
@@ -0,0 +1,56 @@
+#! /bin/sh
+
+# variable
+tc_build_dir=testcase/build
+tc_build_files="Makefile.am autogen.sh configure.ac mm-hal-testcase.manifest"
+spec_path_interface=packaging/mm-hal-interface.spec
+spec_path_testcase=packaging/mm-hal-testcase.spec
+
+# usage
+print_usage()
+{
+ echo "[usage] : $0 [y|n]"
+ echo " - y : set up environment to build testcase"
+ echo " - n : remove environment to build testcase"
+ exit 0
+}
+
+# check argument
+if [ $# != 1 ]
+then
+
+ print_usage
+
+fi
+
+if [ $1 = "y" ]
+then
+ # set up TC build environment
+ for file in $tc_build_files
+ do
+ mv $tc_build_dir/$file .
+ done
+
+ mv $spec_path_interface $spec_path_interface.bak
+ mv $spec_path_testcase.bak $spec_path_testcase
+
+elif [ $1 = "n" ]
+then
+ # reset TC build environment
+ for file in $tc_build_files
+ do
+ mv $file $tc_build_dir
+ done
+
+ mv $spec_path_interface.bak $spec_path_interface
+ mv $spec_path_testcase $spec_path_testcase.bak
+
+else
+
+ echo "Unknown argument : $1"
+ print_usage
+
+fi
+
+exit 0
+
diff --git a/testcase/Makefile.am b/testcase/Makefile.am
new file mode 100644
index 0000000..32fae42
--- /dev/null
+++ b/testcase/Makefile.am
@@ -0,0 +1,4 @@
+if TC_CAMERA
+SUBDIRS = camera
+endif
+
diff --git a/testcase/build/Makefile.am b/testcase/build/Makefile.am
new file mode 100644
index 0000000..efb1910
--- /dev/null
+++ b/testcase/build/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = testcase
+
diff --git a/testcase/build/autogen.sh b/testcase/build/autogen.sh
new file mode 100755
index 0000000..2f43082
--- /dev/null
+++ b/testcase/build/autogen.sh
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+libtoolize --copy --force
+aclocal -I m4
+autoheader
+autoconf
+automake -a -c
diff --git a/testcase/build/configure.ac b/testcase/build/configure.ac
new file mode 100644
index 0000000..ec4cd95
--- /dev/null
+++ b/testcase/build/configure.ac
@@ -0,0 +1,46 @@
+AC_PREREQ(2.52)
+
+AC_INIT([mm-hal-testcase], [0.8.0])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_CONFIG_HEADERS([config.h:config.hin])
+AC_CONFIG_MACRO_DIR([m4])
+
+# Checks for programs.
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+AC_PROG_CC
+AC_PROG_CXX
+AM_PROG_CC_C_O
+AC_C_CONST
+AC_HEADER_STDBOOL
+AC_HEADER_STDC
+AC_HEADER_TIME
+AC_PROG_GCC_TRADITIONAL
+AC_PROG_LIBTOOL
+
+# Checks for libraries.
+AC_ARG_ENABLE(tc-camera, AC_HELP_STRING([--enable-tc-camera], [enable tc-camera]),
+[
+ case "${enableval}" in
+ yes) TC_CAMERA=yes ;;
+ no) TC_CAMERA=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-tc-camera) ;;
+ esac
+],[TC_CAMERA=no])
+AM_CONDITIONAL([TC_CAMERA], [test "x$TC_CAMERA" = "xyes"])
+
+PKG_CHECK_MODULES(GLIB, glib-2.0)
+AC_SUBST(GLIB_CFLAGS)
+AC_SUBST(GLIB_LIBS)
+
+PKG_CHECK_MODULES(DLOG, dlog)
+AC_SUBST(DLOG_CFLAGS)
+AC_SUBST(DLOG_LIBS)
+
+# Checks for library functions.
+AC_CONFIG_FILES([
+Makefile
+testcase/Makefile
+testcase/camera/Makefile
+])
+AC_OUTPUT
+
diff --git a/testcase/build/mm-hal-testcase.manifest b/testcase/build/mm-hal-testcase.manifest
new file mode 100644
index 0000000..a76fdba
--- /dev/null
+++ b/testcase/build/mm-hal-testcase.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
diff --git a/testcase/camera/Makefile.am b/testcase/camera/Makefile.am
new file mode 100644
index 0000000..1699fa8
--- /dev/null
+++ b/testcase/camera/Makefile.am
@@ -0,0 +1,14 @@
+# with gtest
+bin_PROGRAMS = camera_hal_tc
+
+camera_hal_tc_SOURCES = camera_hal_tc.cpp camera_hal_interface.c
+
+camera_hal_tc_CFLAGS = $(GLIB_CFLAGS) $(DLOG_CFLAGS)
+camera_hal_tc_CPPFLAGS = $(GLIB_CFLAGS) $(DLOG_CFLAGS)
+
+camera_hal_tc_LDADD = \
+ -ldl \
+ -lgtest \
+ $(GLIB_LIBS) \
+ $(DLOG_LIBS)
+
diff --git a/testcase/camera/camera_hal_interface.c b/testcase/camera/camera_hal_interface.c
new file mode 100644
index 0000000..a8522ab
--- /dev/null
+++ b/testcase/camera/camera_hal_interface.c
@@ -0,0 +1,591 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jeongmo Yang <jm80.yang@samsung.com>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <dlfcn.h>
+#include <glib.h>
+#include <dlog.h>
+#include "camera_hal_interface.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif /* LOG_TAG */
+#define LOG_TAG "CAMERA_HAL_INTF"
+
+#define LIB_TIZEN_CAMERA "libtizen-camera.so"
+
+struct _camera_hal_interface {
+ void *dl_handle;
+ void *hal_handle;
+ camera_interface_t intf;
+};
+
+
+int camera_hal_interface_init(camera_hal_interface **h)
+{
+ int ret = CAMERA_ERROR_NONE;
+ camera_hal_interface *tmp_h = NULL;
+
+ if (h == NULL) {
+ LOGE("invalid parameter for camera_hal_interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ tmp_h = g_new0(camera_hal_interface, 1);
+ if (tmp_h == NULL) {
+ LOGE("failed to allocate hal interface");
+ return CAMERA_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_h->dl_handle = dlopen(LIB_TIZEN_CAMERA, RTLD_NOW);
+ if (tmp_h->dl_handle) {
+ tmp_h->intf.init = dlsym(tmp_h->dl_handle, "camera_init");
+ tmp_h->intf.deinit = dlsym(tmp_h->dl_handle, "camera_deinit");
+ tmp_h->intf.get_device_list = dlsym(tmp_h->dl_handle, "camera_get_device_list");
+ tmp_h->intf.open_device = dlsym(tmp_h->dl_handle, "camera_open_device");
+ tmp_h->intf.close_device = dlsym(tmp_h->dl_handle, "camera_close_device");
+ tmp_h->intf.add_message_callback = dlsym(tmp_h->dl_handle, "camera_add_message_callback");
+ tmp_h->intf.remove_message_callback = dlsym(tmp_h->dl_handle, "camera_remove_message_callback");
+ tmp_h->intf.set_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_set_preview_stream_format");
+ tmp_h->intf.get_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_get_preview_stream_format");
+ tmp_h->intf.start_preview = dlsym(tmp_h->dl_handle, "camera_start_preview");
+ tmp_h->intf.release_preview_buffer = dlsym(tmp_h->dl_handle, "camera_release_preview_buffer");
+ tmp_h->intf.stop_preview = dlsym(tmp_h->dl_handle, "camera_stop_preview");
+ tmp_h->intf.start_auto_focus = dlsym(tmp_h->dl_handle, "camera_start_auto_focus");
+ tmp_h->intf.stop_auto_focus = dlsym(tmp_h->dl_handle, "camera_stop_auto_focus");
+ tmp_h->intf.start_capture = dlsym(tmp_h->dl_handle, "camera_start_capture");
+ tmp_h->intf.stop_capture = dlsym(tmp_h->dl_handle, "camera_stop_capture");
+ tmp_h->intf.set_video_stream_format = dlsym(tmp_h->dl_handle, "camera_set_video_stream_format");
+ tmp_h->intf.get_video_stream_format = dlsym(tmp_h->dl_handle, "camera_get_video_stream_format");
+ tmp_h->intf.start_record = dlsym(tmp_h->dl_handle, "camera_start_record");
+ tmp_h->intf.release_video_buffer = dlsym(tmp_h->dl_handle, "camera_release_video_buffer");
+ tmp_h->intf.stop_record = dlsym(tmp_h->dl_handle, "camera_stop_record");
+ tmp_h->intf.set_command = dlsym(tmp_h->dl_handle, "camera_set_command");
+ tmp_h->intf.get_command = dlsym(tmp_h->dl_handle, "camera_get_command");
+ tmp_h->intf.set_batch_command = dlsym(tmp_h->dl_handle, "camera_set_batch_command");
+
+ if (tmp_h->intf.init == NULL || tmp_h->intf.deinit == NULL) {
+ LOGE("could not get mandatory funtion. %p %1p", tmp_h->intf.init, tmp_h->intf.deinit);
+ ret = CAMERA_ERROR_INTERNAL;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+
+ if (tmp_h->intf.init) {
+ ret = tmp_h->intf.init(&tmp_h->hal_handle);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("camera_init failed 0x%x", ret);
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+ } else {
+ LOGE("no camera_init function");
+ ret = CAMERA_ERROR_INTERNAL;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+ } else {
+ LOGE("dlopen failed [%s][errno %d]", LIB_TIZEN_CAMERA, errno);
+ ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+
+ *h = tmp_h;
+
+ return ret;
+
+_CAMERA_HAL_INTERFACE_GET_FAILED:
+ if (tmp_h) {
+ if (tmp_h->dl_handle)
+ dlclose(tmp_h->dl_handle);
+
+ g_free(tmp_h);
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_deinit(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->dl_handle) {
+ ret = h->intf.deinit(h->hal_handle);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("camera_deinit failed 0x%x", ret);
+ return ret;
+ }
+
+ h->hal_handle = NULL;
+
+ dlclose(h->dl_handle);
+ h->dl_handle = NULL;
+ }
+
+ g_free(h);
+
+ return CAMERA_ERROR_NONE;
+}
+
+
+int camera_hal_interface_get_device_list(camera_hal_interface *h, camera_device_list_t *device_list)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_device_list) {
+ ret = h->intf.get_device_list(h->hal_handle, device_list);
+ } else {
+ LOGE("camera_get_device_list not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_open_device(camera_hal_interface *h, int device_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.open_device) {
+ ret = h->intf.open_device(h->hal_handle, device_index);
+ } else {
+ LOGE("camera_open_device not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_close_device(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.close_device) {
+ ret = h->intf.close_device(h->hal_handle);
+ } else {
+ LOGE("camera_close_device not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_add_message_callback(camera_hal_interface *h, camera_message_cb callback, void *user_data, uint32_t *cb_id)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.add_message_callback) {
+ ret = h->intf.add_message_callback(h->hal_handle, callback, user_data, cb_id);
+ } else {
+ LOGE("camera_add_message_callback not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_remove_message_callback(camera_hal_interface *h, uint32_t cb_id)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.remove_message_callback) {
+ ret = h->intf.remove_message_callback(h->hal_handle, cb_id);
+ } else {
+ LOGE("camera_remove_message_callback not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_preview_stream_format) {
+ ret = h->intf.set_preview_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_set_preview_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_preview_stream_format) {
+ ret = h->intf.get_preview_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_get_preview_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_preview(camera_hal_interface *h, camera_preview_frame_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_preview) {
+ ret = h->intf.start_preview(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_preview not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_release_preview_buffer(camera_hal_interface *h, int buffer_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.release_preview_buffer) {
+ ret = h->intf.release_preview_buffer(h->hal_handle, buffer_index);
+ } else {
+ LOGE("camera_release_preview_buffer not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_preview(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_preview) {
+ ret = h->intf.stop_preview(h->hal_handle);
+ } else {
+ LOGE("camera_stop_preview not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_auto_focus(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_auto_focus) {
+ ret = h->intf.start_auto_focus(h->hal_handle);
+ } else {
+ LOGE("camera_start_auto_focus not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_auto_focus(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_auto_focus) {
+ ret = h->intf.stop_auto_focus(h->hal_handle);
+ } else {
+ LOGE("camera_stop_auto_focus not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_capture(camera_hal_interface *h, camera_capture_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_capture) {
+ ret = h->intf.start_capture(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_capture not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_capture(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_capture) {
+ ret = h->intf.stop_capture(h->hal_handle);
+ } else {
+ LOGE("camera_stop_capture not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_video_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_video_stream_format) {
+ ret = h->intf.set_video_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_set_video_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_video_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_video_stream_format) {
+ ret = h->intf.get_video_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_get_video_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_record(camera_hal_interface *h, camera_video_frame_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_record) {
+ ret = h->intf.start_record(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_record not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_release_video_buffer(camera_hal_interface *h, int buffer_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.release_video_buffer) {
+ ret = h->intf.release_video_buffer(h->hal_handle, buffer_index);
+ } else {
+ LOGE("camera_release_video_buffer not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_record(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_record) {
+ ret = h->intf.stop_record(h->hal_handle);
+ } else {
+ LOGE("camera_stop_record not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_command(camera_hal_interface *h, int64_t command, void *value)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_command) {
+ ret = h->intf.set_command(h->hal_handle, command, value);
+ } else {
+ LOGE("camera_set_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_command(camera_hal_interface *h, int64_t command, void *value)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_command) {
+ ret = h->intf.get_command(h->hal_handle, command, value);
+ } else {
+ LOGE("camera_get_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_batch_command(camera_hal_interface *h, camera_batch_command_control_t *batch_command, int64_t *error_command)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_batch_command) {
+ ret = h->intf.set_batch_command(h->hal_handle, batch_command, error_command);
+ } else {
+ LOGE("camera_set_batch_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
diff --git a/testcase/camera/camera_hal_interface.h b/testcase/camera/camera_hal_interface.h
new file mode 100644
index 0000000..3323c8b
--- /dev/null
+++ b/testcase/camera/camera_hal_interface.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jeongmo Yang <jm80.yang@samsung.com>
+ *
+ * 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 <tizen-camera.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _camera_hal_interface camera_hal_interface;
+
+int camera_hal_interface_init(camera_hal_interface **h);
+int camera_hal_interface_deinit(camera_hal_interface *h);
+int camera_hal_interface_get_device_list(camera_hal_interface *h, camera_device_list_t *device_list);
+int camera_hal_interface_open_device(camera_hal_interface *h, int device_index);
+int camera_hal_interface_close_device(camera_hal_interface *h);
+int camera_hal_interface_add_message_callback(camera_hal_interface *h, camera_message_cb callback, void *user_data, uint32_t *cb_id);
+int camera_hal_interface_remove_message_callback(camera_hal_interface *h, uint32_t cb_id);
+int camera_hal_interface_set_preview_stream_format(camera_hal_interface *h, camera_format_t *format);
+int camera_hal_interface_get_preview_stream_format(camera_hal_interface *h, camera_format_t *format);
+int camera_hal_interface_start_preview(camera_hal_interface *h, camera_preview_frame_cb callback, void *user_data);
+int camera_hal_interface_release_preview_buffer(camera_hal_interface *h, int buffer_index);
+int camera_hal_interface_stop_preview(camera_hal_interface *h);
+int camera_hal_interface_start_auto_focus(camera_hal_interface *h);
+int camera_hal_interface_stop_auto_focus(camera_hal_interface *h);
+int camera_hal_interface_start_capture(camera_hal_interface *h, camera_capture_cb callback, void *user_data);
+int camera_hal_interface_stop_capture(camera_hal_interface *h);
+int camera_hal_interface_set_video_stream_format(camera_hal_interface *h, camera_format_t *format);
+int camera_hal_interface_get_video_stream_format(camera_hal_interface *h, camera_format_t *format);
+int camera_hal_interface_start_record(camera_hal_interface *h, camera_video_frame_cb callback, void *user_data);
+int camera_hal_interface_release_video_buffer(camera_hal_interface *h, int buffer_index);
+int camera_hal_interface_stop_record(camera_hal_interface *h);
+int camera_hal_interface_set_command(camera_hal_interface *h, int64_t command, void *value);
+int camera_hal_interface_get_command(camera_hal_interface *h, int64_t command, void *value);
+int camera_hal_interface_set_batch_command(camera_hal_interface *h, camera_batch_command_control_t *batch_command, int64_t *error_command);
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/testcase/camera/camera_hal_tc.cpp b/testcase/camera/camera_hal_tc.cpp
new file mode 100644
index 0000000..4f34330
--- /dev/null
+++ b/testcase/camera/camera_hal_tc.cpp
@@ -0,0 +1,709 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jeongmo Yang <jm80.yang@samsung.com>
+ *
+ * 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 <glib.h>
+#include <string.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <iostream>
+#include "camera_hal_interface.h"
+
+using namespace std;
+
+int ret;
+int preview_check;
+int capture_check;
+int video_check;
+camera_hal_interface *h;
+camera_device_list_t device_list;
+camera_format_t preview_format;
+camera_format_t video_format;
+GMutex msg_cb_lock;
+GCond msg_cb_cond;
+
+/*
+ * callback
+ */
+static int _PreviewCb(camera_buffer_t *buffer, camera_metadata_t *meta, void *user_data)
+{
+ camera_hal_interface *hal_intf_handle = (camera_hal_interface *)user_data;
+
+ if (!hal_intf_handle) {
+ cout << "NULL handle" << endl;
+ return false;
+ }
+
+ if (!buffer) {
+ cout << "NULL buffer" << endl;
+ return false;
+ }
+
+ cout << "preview buffer index [" << buffer->index << "]" << endl;
+
+ preview_check = 1;
+
+ camera_hal_interface_release_preview_buffer(hal_intf_handle, buffer->index);
+
+ return true;
+}
+
+static int _CaptureCb(camera_buffer_t *main, camera_buffer_t *postview, camera_buffer_t *thumbnail, void *user_data)
+{
+ if (!main) {
+ cout << "NULL buffer" << endl;
+ return false;
+ }
+
+ cout << "capture callback invoked" << endl;
+
+ capture_check = 1;
+
+ return true;
+}
+
+static int _VideoCb(camera_buffer_t *buffer, camera_metadata_t *meta, void *user_data)
+{
+ camera_hal_interface *hal_intf_handle = (camera_hal_interface *)user_data;
+
+ if (!hal_intf_handle) {
+ cout << "NULL handle" << endl;
+ return false;
+ }
+
+ if (!buffer) {
+ cout << "NULL buffer" << endl;
+ return false;
+ }
+
+ cout << "video buffer index [" << buffer->index << "]" << endl;
+
+ video_check = 1;
+
+ camera_hal_interface_release_video_buffer(hal_intf_handle, buffer->index);
+
+ return true;
+}
+
+static int _MessageCb(camera_message_t *message, void *user_data)
+{
+ if (!message) {
+ cout << "NULL message" << endl;
+ return false;
+ }
+
+ cout << "message - type " << message->type << endl;
+
+ g_mutex_lock(&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(&msg_cb_cond);
+ }
+ break;
+ case CAMERA_MESSAGE_TYPE_CAPTURED:
+ cout << "captured" << endl;
+ g_cond_signal(&msg_cb_cond);
+ break;
+ case CAMERA_MESSAGE_TYPE_HDR_PROGRESS:
+ cout << "HDR progress " << message->hdr_progress << endl;
+ g_cond_signal(&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(&msg_cb_lock);
+
+ return true;
+}
+
+
+/*
+ * main class
+ */
+class CameraHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ ret = camera_hal_interface_init(&h);
+ if (ret != CAMERA_ERROR_NONE) {
+ cout << "camera hal init failed " << ret << endl;
+ return;
+ }
+
+ ret = camera_hal_interface_get_device_list(h, &device_list);
+ if (ret != CAMERA_ERROR_NONE) {
+ cout << "get device list failed " << ret << endl;
+ return;
+ }
+
+ ret = GetSupportedFormat();
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ if (h) {
+ ret = camera_hal_interface_deinit(h);
+ h = nullptr;
+ }
+
+ return;
+ }
+
+ int GetSupportedFormat()
+ {
+ if (device_list.count < 1) {
+ cout << "no available camera device" << endl;
+ return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+ }
+
+ /* set preview format */
+ preview_format.stream_format = device_list.device_info[0].format_list.formats[0];
+ preview_format.stream_resolution.width = device_list.device_info[0].preview_list.resolutions[0].width;
+ preview_format.stream_resolution.height = device_list.device_info[0].preview_list.resolutions[0].height;
+ preview_format.stream_fps = 15;
+ preview_format.stream_rotation = CAMERA_ROTATION_0;
+ preview_format.capture_format = CAMERA_PIXEL_FORMAT_JPEG;
+ preview_format.capture_resolution.width = device_list.device_info[0].capture_list.resolutions[0].width;
+ preview_format.capture_resolution.height = device_list.device_info[0].capture_list.resolutions[0].height;
+ preview_format.capture_quality = 95;
+
+ /* set video format */
+ video_format.stream_format = device_list.device_info[0].format_list.formats[0];
+ video_format.stream_resolution.width = device_list.device_info[0].video_list.resolutions[0].width;
+ video_format.stream_resolution.height = device_list.device_info[0].video_list.resolutions[0].height;
+ video_format.stream_fps = 15;
+ video_format.stream_rotation = CAMERA_ROTATION_0;
+ video_format.capture_format = CAMERA_PIXEL_FORMAT_JPEG;
+ video_format.capture_resolution.width = device_list.device_info[0].capture_list.resolutions[0].width;
+ video_format.capture_resolution.height = device_list.device_info[0].capture_list.resolutions[0].height;
+ video_format.capture_quality = 95;
+
+ return CAMERA_ERROR_NONE;
+ }
+};
+
+
+/*
+ * testcase
+ */
+TEST_F(CameraHalTest, InitP)
+{
+ EXPECT_NE(h, nullptr);
+}
+
+TEST_F(CameraHalTest, DeinitP)
+{
+ camera_hal_interface *hal_handle = nullptr;
+
+ ret = camera_hal_interface_init(&hal_handle);
+
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+ EXPECT_NE(hal_handle, nullptr);
+
+ if (hal_handle) {
+ ret = camera_hal_interface_deinit(hal_handle);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+ hal_handle = nullptr;
+ }
+}
+
+TEST_F(CameraHalTest, GetDeviceListP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+}
+
+TEST_F(CameraHalTest, GetDeviceListN)
+{
+ EXPECT_NE(h, nullptr);
+
+ ret = camera_hal_interface_get_device_list(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(CameraHalTest, OpenDeviceP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (device_list.count > 0) {
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (ret == CAMERA_ERROR_NONE) {
+ camera_hal_interface_close_device(h);
+ }
+ }
+}
+
+TEST_F(CameraHalTest, OpenDeviceN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (device_list.count > 0) {
+ ret = camera_hal_interface_open_device(NULL, device_list.device_info[device_list.count - 1].index + 1);
+ EXPECT_NE(ret, CAMERA_ERROR_NONE);
+
+ if (ret == CAMERA_ERROR_NONE) {
+ camera_hal_interface_close_device(h);
+ }
+ }
+}
+
+TEST_F(CameraHalTest, CloseDeviceP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (device_list.count > 0) {
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (ret == CAMERA_ERROR_NONE) {
+ ret = camera_hal_interface_close_device(h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+ }
+ }
+}
+
+TEST_F(CameraHalTest, SetPreviewStreamFormatP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ camera_hal_interface_close_device(h);
+}
+#if 0
+TEST_F(CameraHalTest, SetPreviewStreamFormatN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, GetPreviewStreamFormatP)
+{
+ camera_format_t get_format;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ memset(&get_format, 0x0, sizeof(camera_format_t));
+
+ ret = camera_hal_interface_get_preview_stream_format(h, &get_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = memcmp(&preview_format, &get_format, sizeof(camera_format_t));
+ EXPECT_EQ(ret, 0);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, GetPreviewStreamFormatN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_get_preview_stream_format(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartPreviewP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ preview_check = 0;
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ /* wait for preview frame */
+ sleep(1);
+
+ EXPECT_TRUE(preview_check);
+
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartPreviewN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, nullptr, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StopPreviewP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_stop_preview(h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartCaptureP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ capture_check = 0;
+
+ ret = camera_hal_interface_start_capture(h, _CaptureCb, NULL);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ /* wait for capture frame */
+ sleep(1);
+
+ EXPECT_TRUE(capture_check);
+
+ camera_hal_interface_stop_capture(h);
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartCaptureN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_capture(h, nullptr, NULL);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartRecordP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_video_stream_format(h, &video_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ video_check = 0;
+
+ ret = camera_hal_interface_start_record(h, _VideoCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ /* wait for video frame */
+ sleep(1);
+
+ EXPECT_TRUE(video_check);
+
+ camera_hal_interface_stop_record(h);
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartRecordN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_video_stream_format(h, &video_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_record(h, nullptr, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, SetVideoStreamFormatP)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_video_stream_format(h, &video_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, SetVideoStreamFormatN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_video_stream_format(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, GetVideoStreamFormatP)
+{
+ camera_format_t get_format;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ memset(&get_format, 0x0, sizeof(camera_format_t));
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_video_stream_format(h, &video_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_get_video_stream_format(h, &get_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = memcmp(&video_format, &get_format, sizeof(camera_format_t));
+ EXPECT_EQ(ret, 0);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, GetVideoStreamFormatN)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_get_video_stream_format(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, AddMessageCallbackP)
+{
+ uint32_t cb_id = 0;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_add_message_callback(h, _MessageCb, nullptr, &cb_id);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (ret == CAMERA_ERROR_NONE) {
+ camera_hal_interface_remove_message_callback(h, cb_id);
+ }
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, AddMessageCallbackN1)
+{
+ uint32_t cb_id = 0;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_add_message_callback(h, nullptr, nullptr, &cb_id);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, AddMessageCallbackN2)
+{
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_add_message_callback(h, _MessageCb, nullptr, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_INVALID_PARAMETER);
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, RemoveMessageCallbackP)
+{
+ uint32_t cb_id = 0;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_add_message_callback(h, _MessageCb, nullptr, &cb_id);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ if (ret == CAMERA_ERROR_NONE) {
+ ret = camera_hal_interface_remove_message_callback(h, cb_id);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+ }
+
+ camera_hal_interface_close_device(h);
+}
+
+TEST_F(CameraHalTest, StartAutoFocusP)
+{
+ uint32_t cb_id = 0;
+ gint64 end_time = 0;
+
+ EXPECT_NE(h, nullptr);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_open_device(h, device_list.device_info[0].index);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_add_message_callback(h, _MessageCb, nullptr, &cb_id);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_set_preview_stream_format(h, &preview_format);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ ret = camera_hal_interface_start_preview(h, _PreviewCb, (void *)h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ g_mutex_lock(&msg_cb_lock);
+
+ ret = camera_hal_interface_start_auto_focus(h);
+ EXPECT_EQ(ret, CAMERA_ERROR_NONE);
+
+ /* wait a message and check result */
+ end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND * 5;
+ EXPECT_EQ(g_cond_wait_until(&msg_cb_cond, &msg_cb_lock, end_time), true);
+
+ g_mutex_unlock(&msg_cb_lock);
+
+ camera_hal_interface_stop_preview(h);
+ camera_hal_interface_remove_message_callback(h, cb_id);
+ camera_hal_interface_close_device(h);
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}