From 1fe51fdf428abc272015be4b5ac9a46dfdb1a52d Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Wed, 21 Nov 2018 14:33:54 +0900 Subject: Adding initial structure for unittest Change-Id: Iea696f0087069093152f77e4fc7c48b007400f9a --- unittest/Makefile.am | 36 ++++++++++++++++ unittest/gtest_libmm-radio.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++ unittest/gtest_libmm-radio.h | 26 +++++++++++ 3 files changed, 160 insertions(+) create mode 100644 unittest/Makefile.am create mode 100755 unittest/gtest_libmm-radio.cpp create mode 100644 unittest/gtest_libmm-radio.h (limited to 'unittest') diff --git a/unittest/Makefile.am b/unittest/Makefile.am new file mode 100644 index 0000000..841d81f --- /dev/null +++ b/unittest/Makefile.am @@ -0,0 +1,36 @@ +# Unit tests +bin_PROGRAMS = gtest_libmm_radio + +gtest_libmm_radio_SOURCES = gtest_libmm-radio.cpp + +gtest_libmm_radio_CXXFLAGS = -I$(top_srcdir)/src/include \ + $(GTHREAD_CFLAGS) \ + $(MMCOMMON_CFLAGS) \ + $(MM_RESOURCE_MANAGER_CFLAGS) \ + $(DLOG_CFLAGS) \ + $(GTESTS_CFLAGS) \ + -Werror -Wno-deprecated -Wno-deprecated-declarations -Wno-cpp + +gtest_libmm_radio_DEPENDENCIES = $(top_srcdir)/src/.libs/libmmfradio.la + +gtest_libmm_radio_LDADD = $(GTHREAD_LIBS) \ + $(MMCOMMON_LIBS) \ + $(MM_RESOURCE_MANAGER_LIBS) \ + $(DLOG_LIBS) \ + $(GTESTS_LIBS) \ + $(top_srcdir)/src/.libs/libmmfradio.la + +if ENABLE_EMULATOR +gtest_libmm_radio_CXXFLAGS += $(GST_CFLAGS) \ + $(GSTAPP_CFLAGS) + +gtest_libmm_radio_LDADD += $(GST_LIBS) \ + $(GSTAPP_LIBS) +endif + +if ENABLE_SOUND_VSTREAM +gtest_libmm_radio_CXXFLAGS += $(SOUNDMGR_CFLAGS) \ + -DTIZEN_FEATURE_SOUND_VSTREAM + +gtest_libmm_radio_LDADD += $(SOUNDMGR_LIBS) +endif diff --git a/unittest/gtest_libmm-radio.cpp b/unittest/gtest_libmm-radio.cpp new file mode 100755 index 0000000..8c1e147 --- /dev/null +++ b/unittest/gtest_libmm-radio.cpp @@ -0,0 +1,98 @@ +/* + * 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 "gtest_libmm-radio.h" +#include "mm_error.h" +#include "mm_radio.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +using namespace std; + +int ret; +MMHandleType hradio; + +static int _message_callback(int message, void *pParam, void *user_param) +{ + MMMessageParamType* param = (MMMessageParamType*)pParam; + + cout << "incomming message :" << message << endl; + + switch(message) + { + case MM_MESSAGE_STATE_CHANGED: + cout << "MM_MESSAGE_STATE_CHANGED: current : " << param->state.current + << "old : " << param->state.previous << endl; + break; + case MM_MESSAGE_RADIO_SCAN_START: + cout << "MM_MESSAGE_RADIO_SCAN_START" << endl; + break; + case MM_MESSAGE_RADIO_SCAN_INFO: + cout << "MM_MESSAGE_RADIO_SCAN_INFO : freq : " << param->radio_scan.frequency + << endl; + break; + case MM_MESSAGE_RADIO_SCAN_STOP: + cout << "MM_MESSAGE_RADIO_SCAN_STOP" << endl; + break; + case MM_MESSAGE_RADIO_SCAN_FINISH: + cout << "MM_MESSAGE_RADIO_SCAN_FINISHED" << endl; + break; + case MM_MESSAGE_RADIO_SEEK_START: + cout << "MM_MESSAGE_RADIO_SEEK_START" << endl; + break; + case MM_MESSAGE_RADIO_SEEK_FINISH: + cout << "MM_MESSAGE_RADIO_SEEK_FINISHED : freq : " << param->radio_scan.frequency + << endl; + break; + default: + cout << "ERROR : unknown message received!" << endl; + break; + } + + return 0; +} + +class MMRadioTest : public ::testing::Test { + protected: + void SetUp() { + ret = mm_radio_create(&hradio); + ASSERT_EQ(ret, MM_ERROR_NONE) << "[FAILED] mm_radio_create"; + + ret = mm_radio_set_message_callback(hradio, _message_callback, &hradio); + ASSERT_EQ(ret, MM_ERROR_NONE) << "[FAILED] mm_radio_set_message_callback"; + } + + void TearDown() { + ret = mm_radio_destroy(hradio); + ASSERT_EQ(ret, MM_ERROR_NONE) << "[FAILED] mm_radio_destroy"; + return; + } +}; + +TEST_F(MMRadioTest, mmradio_create_test) +{ + ASSERT_EQ(ret, MM_ERROR_NONE) << "[FAILED] mm_radio_create"; +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/unittest/gtest_libmm-radio.h b/unittest/gtest_libmm-radio.h new file mode 100644 index 0000000..0d17f4e --- /dev/null +++ b/unittest/gtest_libmm-radio.h @@ -0,0 +1,26 @@ +/* + * 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 __LIB_MM_RADIO_UNITTEST_H__ +#define __LIB_MM_RADIO_UNITTEST_H__ + +#include +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LIBMM_RADIO" + +#endif /*__LIB_MM_RADIO_UNITTEST_H__*/ -- cgit v1.2.3