Added HAL testcases for nfc-manager 41/185741/1 accepted/tizen/unified/20180802.135006 submit/tizen/20180802.043858
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 2 Aug 2018 02:44:37 +0000 (11:44 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 2 Aug 2018 02:44:37 +0000 (11:44 +0900)
Change-Id: Ifaa1d88860e0d1e3ff1b1619f042126867badd08
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
CMakeLists.txt
haltest/CMakeLists.txt [new file with mode: 0644]
haltest/nfc_manager_hal_tc.cpp [new file with mode: 0644]
haltest/unittest.h [new file with mode: 0644]
packaging/capi-network-nfc.spec

index 36b7ac2..8650303 100644 (file)
@@ -92,6 +92,7 @@ CONFIGURE_FILE(
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIBDIR}/pkgconfig)
 
 ADD_SUBDIRECTORY(test)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIBDIR}/pkgconfig)
 
 ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(haltest)
 
 IF(UNIX)
 
 
 IF(UNIX)
 
diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6a3553e
--- /dev/null
@@ -0,0 +1,29 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-nfc-manager C CXX)
+
+SET(GTEST_TEST "gtest-nfc-manager")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(dependents "glib-2.0 gio-2.0 gmock dlog capi-system-info")
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${dependents})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${src_name} ${src})
+    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS})
+    INSTALL(TARGETS ${src_name} RUNTIME DESTINATION bin)
+ENDFOREACH()
+
diff --git a/haltest/nfc_manager_hal_tc.cpp b/haltest/nfc_manager_hal_tc.cpp
new file mode 100644 (file)
index 0000000..0e53402
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <nfc.h>
+#include <system_info.h>
+#include "unittest.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+void __activated(bool activated, void *user_data) {
+       std::cout<< (activated ? "activated" : "deactivated") << std::endl;
+}
+
+static bool __check_feature_supported(char *key)
+{
+       bool value = false;
+       int ret = system_info_get_platform_bool(key, &value);
+
+       EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+       EXPECT_EQ(true, value) << key << " feature is not supported";
+
+       return value;
+}
+
+/*
+@testcase      Init_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(jh8801.jung)
+@type          auto
+@description   Positive, Initialize NFC manager
+@apicovered    nfc_manager_initialize
+@passcase      when nfc_manager_initialize returns NFC_ERROR_NONE
+@failcase      when nfc_manager_initialize does not return NFC_ERROR_NONE
+@precondition  __check_feature_supported must return true for nfc feature
+@postcondition None
+*/
+TEST(Hal_nfc, Init_p)
+{
+       g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
+       ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
+
+       nfc_manager_set_activation_changed_cb(__activated, NULL);
+       int rv = nfc_manager_initialize();
+       EXPECT_EQ(NFC_ERROR_NONE, rv) << "Initialization failure";
+
+}
+
+/*
+@testcase      Set_Activation_true_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(jh8801.jung)
+@type          auto
+@description   Positive, Activate NFC manager
+@apicovered    nfc_manager_set_activation
+@passcase      when nfc_manager_set_activation returns NFC_ERROR_NONE or NFC_ERROR_ALREADY_ACTIVATED
+@failcase      when nfc_manager_set_activation does not return NFC_ERROR_NONE or NFC_ERROR_ALREADY_ACTIVATED
+@precondition  __check_feature_supported must return true for nfc feature
+@postcondition None
+*/
+TEST(Hal_nfc, Set_Activation_true_p)
+{
+       g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
+       ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
+
+       int rv = nfc_manager_set_activation(true, NULL, NULL);
+       sleep(5);
+       EXPECT_EQ(rv == NFC_ERROR_NONE || rv == NFC_ERROR_ALREADY_ACTIVATED, true)
+               << "Activation failure";
+}
+
+/*
+@testcase      Set_Activation_false_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(jh8801.jung)
+@type          auto
+@description   Positive, Deactivate NFC manager
+@apicovered    nfc_manager_set_activation
+@passcase      when nfc_manager_set_activation returns NFC_ERROR_NONE
+@failcase      when nfc_manager_set_activation does not return NFC_ERROR_NONE
+@precondition  __check_feature_supported must return true for nfc feature
+@postcondition None
+*/
+TEST(Hal_nfc, Set_Activation_false_p)
+{
+       g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
+       ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
+
+       int rv = nfc_manager_set_activation(false, NULL, NULL);
+       EXPECT_EQ(NFC_ERROR_NONE, rv) << "Deactivation failure";
+}
+
+/*
+@testcase      Deinit_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(jh8801.jung)
+@type          auto
+@description   Positive, Deinitialize NFC manager
+@apicovered    nfc_manager_deinitialize
+@passcase      when nfc_manager_deinitialize returns NFC_ERROR_NONE
+@failcase      when nfc_manager_deinitialize does not return NFC_ERROR_NONE
+@precondition  __check_feature_supported must return true for nfc feature
+@postcondition None
+*/
+TEST(Hal_nfc, Deinit_p)
+{
+       g_bFeatureNfc = __check_feature_supported((char*)FEATURE_NFC);
+       ASSERT_EQ(true, g_bFeatureNfc) << FEATURE_NFC << " feature is not supported";
+
+       int rv = nfc_manager_deinitialize();
+       EXPECT_EQ(NFC_ERROR_NONE, rv) << "De-initialization failure";
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/haltest/unittest.h b/haltest/unittest.h
new file mode 100644 (file)
index 0000000..f93a99d
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#ifndef __NFC_MANAGER_H__
+#define __NFC_MANAGER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define FEATURE_NFC       "http://tizen.org/feature/network.nfc"
+#define FEATURE_NFC_TAG   "http://tizen.org/feature/network.nfc.tag"
+
+bool g_bFeatureNfc;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NFC_MANAGER_H__ */
index f5602ac..81dadf6 100644 (file)
@@ -22,6 +22,14 @@ Requires(postun): /sbin/ldconfig
 %description
 A library for Tizen NFC Native API.
 
 %description
 A library for Tizen NFC Native API.
 
+%package haltests
+Summary:        nfc-manager extension for HAL test
+BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(capi-system-info)
+Requires:       %{name} = %{version}-%{release}
+%description haltests
+TIZEN nfc-manager extension for HAL test.
+
 %package devel
 Summary:  A NFC library in Native API (Development)
 Group:    Network & Connectivity/Development
 %package devel
 Summary:  A NFC library in Native API (Development)
 Group:    Network & Connectivity/Development
@@ -70,3 +78,7 @@ rm -rf %{buildroot}
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libcapi-network-nfc.so
 %{_bindir}/nfc_unit_test
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libcapi-network-nfc.so
 %{_bindir}/nfc_unit_test
+
+%files haltests
+%manifest %{name}.manifest
+%{_bindir}/*hal_tc