diff options
author | SukhyungKang <shine.kang@samsung.com> | 2023-08-22 10:51:31 +0900 |
---|---|---|
committer | SukhyungKang <shine.kang@samsung.com> | 2023-11-13 09:34:54 +0900 |
commit | f02c1987fdbfbacd4079a4355ff3ce87b0664fa6 (patch) | |
tree | 1e6775ae270713b0bd6f316c85974d9dc2a794e4 | |
parent | c504090c8bb6d70937e28fd3d07eb1380a369823 (diff) | |
download | notification-f02c1987fdbfbacd4079a4355ff3ce87b0664fa6.tar.gz notification-f02c1987fdbfbacd4079a4355ff3ce87b0664fa6.tar.bz2 notification-f02c1987fdbfbacd4079a4355ff3ce87b0664fa6.zip |
Improve coverage and add notification unittest
Change-Id: I045b5f72d2d20f024b35cc1e3d51bff5fa7008d8
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
93 files changed, 2199 insertions, 304 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b69932c..0c0fea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,10 @@ ADD_SUBDIRECTORY(notification-ex) ADD_SUBDIRECTORY(tests) ENABLE_TESTING() -SET(NOTIFICATION_UNIT_TESTS notification-ex_unittests) -ADD_TEST(NAME ${NOTIFICATION_UNIT_TESTS} COMMAND ${NOTIFICATION_UNIT_TESTS})
\ No newline at end of file +SET(NOTIFICATION_EX_UNIT_TESTS notification-ex-unittests) +ADD_TEST(NAME ${NOTIFICATION_EX_UNIT_TESTS} COMMAND ${NOTIFICATION_EX_UNIT_TESTS}) +ADD_DEPENDENCIES(${NOTIFICATION_EX_UNIT_TESTS} notification-ex) + +SET(NOTIFICATION_UNIT_TESTS notification-unittests) +ADD_TEST(NAME ${NOTIFICATION_UNIT_TESTS} COMMAND ${NOTIFICATION_UNIT_TESTS}) +ADD_DEPENDENCIES(${NOTIFICATION_UNIT_TESTS} notification) diff --git a/notification-ex/abstract_item.h b/notification-ex/abstract_item.h index c4e912d..2910294 100644 --- a/notification-ex/abstract_item.h +++ b/notification-ex/abstract_item.h @@ -37,6 +37,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ /** * @brief The class for ReceiverGroup. * @details The class to define receiver group of notification. @@ -1092,6 +1093,7 @@ class EXPORT_API AbstractItem { void UpdateSoundPrivatePath(); void UpdateVibrationPrivatePath(); }; // class AbstractItem +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/chat_message_item.cc b/notification-ex/chat_message_item.cc index c5ceb87..9a4ff73 100644 --- a/notification-ex/chat_message_item.cc +++ b/notification-ex/chat_message_item.cc @@ -134,6 +134,7 @@ AbstractItem& ChatMessageItem::FindByID(std::string id) { return FactoryManager::GetInst().GetNullItem(); } +/* LCOV_EXCL_START */ AbstractItem& ChatMessageItem::FindByMainType(MainType type) { if (GetMainType() == type) return *this; @@ -171,6 +172,7 @@ std::list<std::string> ChatMessageItem::GetSharedPath() const { return ret; } +/* LCOV_EXCL_STOP */ TextItem& ChatMessageItem::GetNameItem() const { if (impl_->name_ == nullptr) diff --git a/notification-ex/common.cc b/notification-ex/common.cc index 1ab82d9..3634cd3 100644 --- a/notification-ex/common.cc +++ b/notification-ex/common.cc @@ -27,6 +27,7 @@ namespace notification { +/* LCOV_EXCL_START */ static const GDBusErrorEntry dbus_error_entries[] = { {ERROR_INVALID_PARAMETER, "org.freedesktop.Notification-ex.Error.INVALID_PARAMETER"}, {ERROR_OUT_OF_MEMORY, "org.freedesktop.Notification-ex.Error.OUT_OF_MEMORY"}, @@ -55,5 +56,6 @@ GQuark noti_ex_error_quark(void) { dbus_error_entries, G_N_ELEMENTS(dbus_error_entries)); return (GQuark)quark_volatile; } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/db_manager.cc b/notification-ex/db_manager.cc index 12cb3e3..59f8bb6 100644 --- a/notification-ex/db_manager.cc +++ b/notification-ex/db_manager.cc @@ -73,6 +73,7 @@ namespace notification { DBManager::DBManager() = default; DBManager::~DBManager() = default; +/* LCOV_EXCL_START */ sqlite3* DBManager::OpenDB() { int ret; sqlite3* db; @@ -105,10 +106,8 @@ int DBManager::ExecuteQuery(sqlite3* db, const char* query, int* num_changes) { ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, nullptr); if (ret != SQLITE_OK) { - /* LCOV_EXCL_START */ LOGE("Sqlite3 err[%d][%s]", ret, sqlite3_errmsg(db)); return ERROR_FROM_DB; - /* LCOV_EXCL_STOP */ } ret = sqlite3_step(stmt); @@ -117,10 +116,8 @@ int DBManager::ExecuteQuery(sqlite3* db, const char* query, int* num_changes) { *num_changes = sqlite3_changes(db); ret = ERROR_NONE; } else { - /* LCOV_EXCL_START */ LOGE("Sqlite err[%d][%s]", ret, sqlite3_errmsg(db)); ret = ERROR_FROM_DB; - /* LCOV_EXCL_STOP */ } sqlite3_finalize(stmt); @@ -154,10 +151,8 @@ int DBManager::GetSequence(sqlite3* db, int64_t* seq) { " FROM noti_ex_list"; ret = sqlite3_prepare_v2(db, query.c_str(), query.size(), &stmt, nullptr); if (ret != SQLITE_OK) { - /* LCOV_EXCL_START */ LOGE("Sqlite3 err[%d][%s]", ret, sqlite3_errmsg(db)); return ERROR_FROM_DB; - /* LCOV_EXCL_STOP */ } ret = sqlite3_step(stmt); @@ -169,10 +164,8 @@ int DBManager::GetSequence(sqlite3* db, int64_t* seq) { *seq = sqlite3_column_int64(stmt, 1) + 1; ret = ERROR_NONE; } else { - /* LCOV_EXCL_START */ LOGE("Sqlite err [%d][%s]", ret, sqlite3_errmsg(db)); ret = ERROR_FROM_DB; - /* LCOV_EXCL_STOP */ } sqlite3_finalize(stmt); @@ -307,10 +300,8 @@ void DBManager::CheckLimit(shared_ptr<item::AbstractItem> addedItem, sqlite3* db ret = sqlite3_prepare_v2(db, query, -1, &stmt, nullptr); if (ret != SQLITE_OK) { - /* LCOV_EXCL_START */ LOGE("sqlite3_prepare_v2 Failed [%d][%s]", ret, sqlite3_errmsg(db)); goto out; - /* LCOV_EXCL_STOP */ } count -= NOTI_LIMIT; @@ -327,10 +318,8 @@ void DBManager::CheckLimit(shared_ptr<item::AbstractItem> addedItem, sqlite3* db ret = sqlite3_prepare_v2(db, query, -1, &delete_stmt, nullptr); if (ret != SQLITE_OK) { - /* LCOV_EXCL_START */ LOGE("sqlite3_prepare_v2 Failed [%d][%s]", ret, sqlite3_errmsg(db)); goto out; - /* LCOV_EXCL_STOP */ } while (sqlite3_step(stmt) == SQLITE_ROW && count > 0) { @@ -876,4 +865,6 @@ string DBManager::GetPkgId(const string& app_id, uid_t uid) { } return pkgid; } +/* LCOV_EXCL_STOP */ + } // namespace notification diff --git a/notification-ex/db_manager.h b/notification-ex/db_manager.h index 55d15f6..a611a81 100644 --- a/notification-ex/db_manager.h +++ b/notification-ex/db_manager.h @@ -32,6 +32,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API DBManager { public: static int InitializeDB(); @@ -65,6 +66,8 @@ class EXPORT_API DBManager { static int UpdateReceiverList(std::shared_ptr<item::AbstractItem> updatedItem, sqlite3* db); static std::list<std::shared_ptr<item::AbstractItem>> ExecuteGetList(char* query); }; +/* LCOV_EXCL_STOP */ + } // namespace notification #endif // NOTIFICATION_EX_DB_MANAGER_H_ diff --git a/notification-ex/dbus_connection_manager.cc b/notification-ex/dbus_connection_manager.cc index 633fa41..83b2f44 100644 --- a/notification-ex/dbus_connection_manager.cc +++ b/notification-ex/dbus_connection_manager.cc @@ -34,6 +34,7 @@ using namespace std; namespace notification { +/* LCOV_EXCL_START */ DBusConnectionManager::DBusConnectionManager() = default; DBusConnectionManager::~DBusConnectionManager() = default; @@ -118,5 +119,6 @@ int DBusConnectionManager::Init() { } return ERROR_NONE; } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/dbus_connection_manager.h b/notification-ex/dbus_connection_manager.h index 1f96758..85a0589 100644 --- a/notification-ex/dbus_connection_manager.h +++ b/notification-ex/dbus_connection_manager.h @@ -27,6 +27,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API DBusConnectionManager { public: static DBusConnectionManager& GetInst(); @@ -44,6 +45,7 @@ class EXPORT_API DBusConnectionManager { GDBusConnection* connection_ = nullptr; bool is_DPM_ = false; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/dbus_event_listener.cc b/notification-ex/dbus_event_listener.cc index b61568a..30f79b4 100644 --- a/notification-ex/dbus_event_listener.cc +++ b/notification-ex/dbus_event_listener.cc @@ -49,6 +49,7 @@ using namespace tizen_base; namespace notification { +/* LCOV_EXCL_START */ DBusEventListener::DBusEventListener(string path) : impl_(new Impl(this, path)) { LOGW("Created (%s)", path.c_str()); @@ -521,5 +522,6 @@ list<Bundle> DBusEventListener::NotifyObserver(const IEventInfo& info) { int DBusEventListener::NotifyNumberRequest(const IEventInfo& info) { return impl_->observer_->OnRequestNumber(info); } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/dbus_event_listener_implementation.h b/notification-ex/dbus_event_listener_implementation.h index 0bc70e9..d7a9720 100644 --- a/notification-ex/dbus_event_listener_implementation.h +++ b/notification-ex/dbus_event_listener_implementation.h @@ -25,6 +25,7 @@ namespace notification { +/* LCOV_EXCL_START */ class DBusEventListener::Impl { public: virtual ~Impl(); @@ -77,6 +78,7 @@ class DBusEventListener::Impl { std::string path_; DBusEventListener* parent_; }; +/* LCOV_EXCL_STOP */ } // namespace notification #endif // NOTIFICATION_EX_DBUS_EVENT_LISTENER_IMPLEMENTATION_H_ diff --git a/notification-ex/dbus_sender.cc b/notification-ex/dbus_sender.cc index 89ea543..9d9318e 100644 --- a/notification-ex/dbus_sender.cc +++ b/notification-ex/dbus_sender.cc @@ -44,6 +44,7 @@ using namespace std; using namespace tizen_base; namespace notification { +/* LCOV_EXCL_START */ DBusSender::DBusSender(string path) : impl_(new Impl(this, path)) { LOGW("Created (%s)", path.c_str()); } @@ -361,5 +362,6 @@ int DBusSender::RequestReturnValue(const IEventInfo& info) { Bundle serialized = info.Serialize(); return impl_->MethodCall(appid, method_name, serialized); } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/dbus_sender_implementation.h b/notification-ex/dbus_sender_implementation.h index f701fa8..063d4f2 100644 --- a/notification-ex/dbus_sender_implementation.h +++ b/notification-ex/dbus_sender_implementation.h @@ -28,6 +28,7 @@ namespace notification { +/* LCOV_EXCL_START */ class DBusSender::Impl { public: virtual ~Impl(); @@ -51,6 +52,7 @@ class DBusSender::Impl { std::string path_; DBusSender* parent_; }; +/* LCOV_EXCL_STOP */ } // namespace notification #endif // NOTIFICATION_EX_DBUS_SENDER_IMPLEMENTATION_H_
\ No newline at end of file diff --git a/notification-ex/event_info.cc b/notification-ex/event_info.cc index 547abeb..244698b 100644 --- a/notification-ex/event_info.cc +++ b/notification-ex/event_info.cc @@ -159,9 +159,11 @@ void EventInfo::SetValidatedUid(uid_t uid) { impl_->validated_uid_ = uid; } +/* LCOV_EXCL_START */ int EventInfo::GetRequestId() const { return impl_->request_id_; } +/* LCOV_EXCL_STOP */ NotificationError EventInfo::GetError() const { return impl_->error_; diff --git a/notification-ex/event_listener_interface.h b/notification-ex/event_listener_interface.h index 9813a71..a27ee21 100644 --- a/notification-ex/event_listener_interface.h +++ b/notification-ex/event_listener_interface.h @@ -28,6 +28,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API IEventListener { public: virtual ~IEventListener() = default; @@ -38,6 +39,7 @@ class EXPORT_API IEventListener { virtual std::list<tizen_base::Bundle> NotifyObserver(const IEventInfo& info) = 0; virtual int NotifyNumberRequest(const IEventInfo& info) = 0; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/event_observer_interface.h b/notification-ex/event_observer_interface.h index bad3a23..71d16b3 100644 --- a/notification-ex/event_observer_interface.h +++ b/notification-ex/event_observer_interface.h @@ -29,6 +29,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API IEventObserver { public: virtual ~IEventObserver() = default; @@ -37,6 +38,7 @@ class EXPORT_API IEventObserver { virtual std::list<tizen_base::Bundle> OnRequest(const IEventInfo& info) = 0; virtual int OnRequestNumber(const IEventInfo& info) = 0; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/event_sender_interface.h b/notification-ex/event_sender_interface.h index ad1cd72..0af9d23 100644 --- a/notification-ex/event_sender_interface.h +++ b/notification-ex/event_sender_interface.h @@ -30,6 +30,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API IEventSender { public: virtual ~IEventSender() = default; @@ -42,6 +43,7 @@ class EXPORT_API IEventSender { virtual std::list<tizen_base::Bundle> Request(const IEventInfo& info) = 0; virtual int RequestReturnValue(const IEventInfo& info) = 0; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/ex_util.cc b/notification-ex/ex_util.cc index 19943ca..068bdf0 100644 --- a/notification-ex/ex_util.cc +++ b/notification-ex/ex_util.cc @@ -37,6 +37,7 @@ using namespace std; +/* LCOV_EXCL_START */ namespace { constexpr int MAX_PACKAGE_STR_SIZE = 512; constexpr int MAX_CACHE_SIZE = 100; @@ -296,7 +297,7 @@ int ConvertDBusError(int error) { return ERROR_IO_ERROR; } - +/* LCOV_EXCL_STOP */ } // namespace util } // namespace notification diff --git a/notification-ex/exception.h b/notification-ex/exception.h index aca1041..4ca36e6 100644 --- a/notification-ex/exception.h +++ b/notification-ex/exception.h @@ -34,6 +34,7 @@ namespace notification { +/* LCOV_EXCL_START */ class Exception : public std::exception { public: explicit Exception(int error_code, std::string file = __FILE__, @@ -79,6 +80,7 @@ class Exception : public std::exception { } } }; // class Exception +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/ievent_info.h b/notification-ex/ievent_info.h index 33986ef..22f09d3 100644 --- a/notification-ex/ievent_info.h +++ b/notification-ex/ievent_info.h @@ -27,6 +27,7 @@ namespace notification { #define EXPORT_API __attribute__((visibility("default"))) #endif +/* LCOV_EXCL_START */ class EXPORT_API IEventInfo { public: enum EventType { @@ -49,6 +50,7 @@ class EXPORT_API IEventInfo { virtual int GetRequestId() const = 0; virtual tizen_base::Bundle Serialize() const = 0; }; +/* LCOV_EXCL_STOP */ } // namespace notification #endif // NOTIFICATION_EX_IEVENT_INFO_H_ diff --git a/notification-ex/ievent_info_internal.h b/notification-ex/ievent_info_internal.h index c359974..327b6f3 100644 --- a/notification-ex/ievent_info_internal.h +++ b/notification-ex/ievent_info_internal.h @@ -22,6 +22,7 @@ namespace notification { +/* LCOV_EXCL_START */ class IEventInfoInternal : public IEventInfo { public: virtual ~IEventInfoInternal() = default; @@ -35,6 +36,7 @@ class IEventInfoInternal : public IEventInfo { virtual void SetError(NotificationError error) = 0; virtual void SetEventType(int type) = 0; }; +/* LCOV_EXCL_STOP */ } // namespace notification #endif // NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_ diff --git a/notification-ex/iitem_info.h b/notification-ex/iitem_info.h index bbe605e..4e10928 100644 --- a/notification-ex/iitem_info.h +++ b/notification-ex/iitem_info.h @@ -22,6 +22,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ /** * @brief The interface class for ItemInfo * @since_tizen 5.5 @@ -69,6 +70,7 @@ class EXPORT_API IItemInfo { */ virtual time_t GetTime() const = 0; }; +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/iitem_info_internal.h b/notification-ex/iitem_info_internal.h index 2f79e36..f95beec 100644 --- a/notification-ex/iitem_info_internal.h +++ b/notification-ex/iitem_info_internal.h @@ -29,6 +29,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ class EXPORT_API IItemInfoInternal : public IItemInfo { public: virtual ~IItemInfoInternal() = default; @@ -43,6 +44,7 @@ class EXPORT_API IItemInfoInternal : public IItemInfo { virtual void SetTime(time_t time) = 0; virtual bool CanReceive(std::string receiver_group) const = 0; }; +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/image_item.cc b/notification-ex/image_item.cc index ee8087c..01a5c9e 100644 --- a/notification-ex/image_item.cc +++ b/notification-ex/image_item.cc @@ -100,6 +100,7 @@ std::list<std::string> ImageItem::GetSharedPath() const { return ret; } +/* LCOV_EXCL_START */ void ImageItem::SetSharedPath() { if (!impl_->priv_image_path_.empty()) impl_->image_path_ = impl_->priv_image_path_; @@ -117,6 +118,7 @@ std::list<std::map<std::string, std::string>> ImageItem::GetPathMapList() const return path_map_list; } +/* LCOV_EXCL_STOP */ void ImageItem::UpdatePrivatePath() { std::string path; diff --git a/notification-ex/manager.cc b/notification-ex/manager.cc index 36cf000..3c483fa 100644 --- a/notification-ex/manager.cc +++ b/notification-ex/manager.cc @@ -45,6 +45,7 @@ using namespace tizen_base; using namespace notification::item; namespace notification { +/* LCOV_EXCL_START */ Manager::Manager(unique_ptr<IEventSender> sender, unique_ptr<IEventListener> listener, string receiver_group) : impl_(new Impl(this, move(sender), move(listener), receiver_group)) { @@ -284,5 +285,6 @@ int Manager::OnRequestNumberEvent(const IEventInfo& info) { string Manager::GetPath() { return NOTIFICATION_EX_MANAGER_OBJECT_PATH; } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/manager.h b/notification-ex/manager.h index 5134dee..6a92163 100644 --- a/notification-ex/manager.h +++ b/notification-ex/manager.h @@ -33,6 +33,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API Manager : public IEventObserver { public: Manager(std::unique_ptr<IEventSender> sender, @@ -70,6 +71,7 @@ class EXPORT_API Manager : public IEventObserver { class Impl; std::unique_ptr<Impl> impl_; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/multi_language.cc b/notification-ex/multi_language.cc index cb0bf6d..4d08a9b 100644 --- a/notification-ex/multi_language.cc +++ b/notification-ex/multi_language.cc @@ -42,6 +42,7 @@ using namespace tizen_base; namespace notification { namespace item { +/* LCOV_EXCL_START */ MultiLanguage::MultiLanguage(string msgid, string format, vector<string> args) : impl_(new Impl(msgid, format, args, this)) { @@ -130,6 +131,7 @@ void MultiLanguage::UpdateString(string domain, string locale_directory) { string MultiLanguage::GetTranslatedString() { return impl_->translated_; } +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification
\ No newline at end of file diff --git a/notification-ex/multi_language.h b/notification-ex/multi_language.h index 0916a1f..0f242b4 100644 --- a/notification-ex/multi_language.h +++ b/notification-ex/multi_language.h @@ -30,6 +30,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ /** * @brief The class for MultiLanguage type notification. * @details The class to make the notification with multi language. @@ -51,6 +52,7 @@ class EXPORT_API MultiLanguage { class Impl; std::unique_ptr<Impl> impl_; }; // class MultiLanguage +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/multi_language_implementation.h b/notification-ex/multi_language_implementation.h index ddacbc3..7c556d1 100644 --- a/notification-ex/multi_language_implementation.h +++ b/notification-ex/multi_language_implementation.h @@ -28,6 +28,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ class MultiLanguage::Impl { public: virtual ~Impl(); @@ -48,6 +49,7 @@ class MultiLanguage::Impl { std::string locale_directory_; MultiLanguage* parent_; }; +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/null_item.cc b/notification-ex/null_item.cc index f85cf15..131565d 100644 --- a/notification-ex/null_item.cc +++ b/notification-ex/null_item.cc @@ -32,6 +32,7 @@ using namespace tizen_base; namespace notification { namespace item { +/* LCOV_EXCL_START */ NullItem::NullItem(shared_ptr<AbstractAction> action) : AbstractItem(action) { } @@ -65,6 +66,7 @@ bool NullItem::IsItemTypeExist(int type) { return true; return false; } +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/reporter.cc b/notification-ex/reporter.cc index d100aac..5dbe2e5 100644 --- a/notification-ex/reporter.cc +++ b/notification-ex/reporter.cc @@ -43,6 +43,7 @@ using namespace tizen_base; using namespace notification::item; namespace notification { +/* LCOV_EXCL_START */ Reporter::Reporter( unique_ptr<IEventSender> sender, unique_ptr<IEventListener> listener) : impl_(new Impl(this, move(sender), move(listener))) { @@ -256,5 +257,6 @@ string Reporter::GetPath() { void Reporter::OnRegister(const IEventInfo& info) { } +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/reporter.h b/notification-ex/reporter.h index 36e6840..e8c849a 100644 --- a/notification-ex/reporter.h +++ b/notification-ex/reporter.h @@ -34,6 +34,7 @@ namespace notification { +/* LCOV_EXCL_START */ class EXPORT_API Reporter : public IEventObserver { public: Reporter(std::unique_ptr<IEventSender> sender, @@ -71,6 +72,7 @@ class EXPORT_API Reporter : public IEventObserver { class Impl; std::unique_ptr<Impl> impl_; }; +/* LCOV_EXCL_STOP */ } // namespace notification diff --git a/notification-ex/shared_file.cc b/notification-ex/shared_file.cc index 665abd3..41228ee 100644 --- a/notification-ex/shared_file.cc +++ b/notification-ex/shared_file.cc @@ -83,6 +83,7 @@ const char* SharedFile::GetLastIndex(const char* path, const char* search) { return nullptr; } +/* LCOV_EXCL_START */ bool SharedFile::MakeDir(const char* path) { if (access(path, R_OK) == 0) return true; @@ -574,6 +575,7 @@ int SharedFile::CopyPrivateFile(shared_ptr<item::AbstractItem> item) { return ERROR_NONE; } +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/shared_file.h b/notification-ex/shared_file.h index f0ee5d6..da2fc52 100644 --- a/notification-ex/shared_file.h +++ b/notification-ex/shared_file.h @@ -34,6 +34,7 @@ namespace notification { namespace item { +/* LCOV_EXCL_START */ class EXPORT_API SharedFile { public: SharedFile(); @@ -82,6 +83,7 @@ class EXPORT_API SharedFile { std::list<SharingData> sharing_data_list_; std::list<SharingTarget> sharing_target_list_; }; // class SharedFile +/* LCOV_EXCL_STOP */ } // namespace item } // namespace notification diff --git a/notification-ex/socket_handler.h b/notification-ex/socket_handler.h index aa9747f..951ddfa 100644 --- a/notification-ex/socket_handler.h +++ b/notification-ex/socket_handler.h @@ -21,6 +21,7 @@ namespace notification { +/* LCOV_EXCL_START */ class SocketHandler { public: SocketHandler(int fd):fd_(fd){} @@ -36,6 +37,7 @@ class SocketHandler { private: int fd_ = -1; }; +/* LCOV_EXCL_STOP */ } // namespace notification #endif // NOTIFICATION_EX_SOCKET_HANDLER_H_
\ No newline at end of file diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc index cd6b60a..c9f08f5 100644 --- a/notification-ex/stub.cc +++ b/notification-ex/stub.cc @@ -61,6 +61,7 @@ using namespace notification; namespace { +/* LCOV_EXCL_START */ class Handle { public: explicit Handle(item::AbstractItem* ref) : ref_(ref) { } @@ -276,9 +277,11 @@ class ReporterStub : public Reporter { private: unique_ptr<ReporterCallbackInfo> cb_; }; +/* LCOV_EXCL_STOP */ } // namespace +/* LCOV_EXCL_START */ void __noti_ex_free_str_array(char** val, int length) { int i; for (i = 0; i < length ; i++) @@ -3778,3 +3781,4 @@ extern "C" EXPORT_API int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, return NOTI_EX_ERROR_NONE; } +/* LCOV_EXCL_STOP */ diff --git a/notification/src/notification_internal.c b/notification/src/notification_internal.c index 8c2e359..3a7fff9 100644 --- a/notification/src/notification_internal.c +++ b/notification/src/notification_internal.c @@ -68,6 +68,7 @@ struct _notification_event_cb_info { static GHashTable *_noti_cb_hash = NULL; static GList *__noti_event_cb_list = NULL; +/* LCOV_EXCL_START */ void notification_reset_event_handler_list(void) { GList *iter; @@ -85,7 +86,6 @@ void notification_reset_event_handler_list(void) } } -/* LCOV_EXCL_START */ static void __free_changed_cb_info(gpointer data) { notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data; @@ -95,6 +95,7 @@ static void __free_changed_cb_info(gpointer data) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid) { notification_type_e type = NOTIFICATION_TYPE_NOTI; @@ -167,6 +168,7 @@ void notification_call_event_handler_cb(notification_h noti, int event_type) info = g_list_nth_data(find_list, 0); info->cb(noti, event_type, info->userdata); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ void notification_delete_event_handler_cb(int priv_id) @@ -195,6 +197,7 @@ void notification_delete_event_handler_cb(int priv_id) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_add_deferred_task( void (*deferred_task_cb)(void *data), void *user_data) { @@ -212,7 +215,9 @@ EXPORT_API int notification_del_deferred_task( return notification_ipc_del_deffered_task(deferred_task_cb); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_resister_changed_cb_for_uid( void (*changed_cb)(void *data, notification_type_e type), void *user_data, uid_t uid) @@ -228,10 +233,8 @@ EXPORT_API int notification_resister_changed_cb_for_uid( noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s)); if (noti_cb_info_new == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL; @@ -255,7 +258,9 @@ EXPORT_API int notification_resister_changed_cb_for_uid( return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_resister_changed_cb( void (*changed_cb)(void *data, notification_type_e type), void *user_data) @@ -431,6 +436,7 @@ EXPORT_API int notification_update_content(notification_h noti, return ret; } +/* LCOV_EXCL_STOP */ /* notification_set_icon will be removed */ /* LCOV_EXCL_START */ @@ -459,6 +465,7 @@ EXPORT_API int notification_get_icon(notification_h noti, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_translate_localized_text(notification_h noti) { int ret = NOTIFICATION_ERROR_NONE; @@ -502,6 +509,7 @@ EXPORT_API int notification_translate_localized_text(notification_h noti) return ret; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API int notification_set_title(notification_h noti, @@ -815,6 +823,7 @@ EXPORT_API int notification_set_pkgname(notification_h noti, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_set_app_id(notification_h noti, const char *app_id) { @@ -831,6 +840,7 @@ EXPORT_API int notification_set_app_id(notification_h noti, return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ int notification_delete_all_by_type_for_uid(const char *app_id, @@ -998,6 +1008,7 @@ EXPORT_API int notification_get_id(notification_h noti, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id) { if (noti == NULL || priv_id <= 0) @@ -1007,6 +1018,7 @@ EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id) return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ notification_h notification_load_for_uid(char *app_id, @@ -1124,6 +1136,7 @@ EXPORT_API int notification_get_execute_option(notification_h noti, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_insert_for_uid(notification_h noti, int *priv_id, uid_t uid) { @@ -1177,7 +1190,9 @@ EXPORT_API int notification_update_async(notification_h noti, { return notification_update_async_for_uid(noti, result_cb, user_data, getuid()); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_register_detailed_changed_cb_for_uid( void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op), void *user_data, uid_t uid) @@ -1193,10 +1208,8 @@ EXPORT_API int notification_register_detailed_changed_cb_for_uid( noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s)); if (noti_cb_info_new == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED; @@ -1220,7 +1233,9 @@ EXPORT_API int notification_register_detailed_changed_cb_for_uid( return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_register_detailed_changed_cb( void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op), void *user_data) @@ -1293,6 +1308,7 @@ EXPORT_API int notification_unregister_detailed_changed_cb( { return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid()); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API int notification_is_service_ready(void) @@ -1301,6 +1317,7 @@ EXPORT_API int notification_is_service_ready(void) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_set_uid(notification_h noti, uid_t uid) { @@ -1372,6 +1389,7 @@ static GList *__copy_private_file(notification_h noti) return file_list; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void __remove_private_file(gpointer data, gpointer user_data) @@ -1387,6 +1405,7 @@ static void __remove_private_file(gpointer data, gpointer user_data) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid) { int ret = 0; @@ -1459,7 +1478,9 @@ EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t u return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid) { int ret; @@ -1474,22 +1495,18 @@ EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_ caller_app_id = notification_get_app_id_by_pid(getpid()); if (!caller_app_id) { - /* LCOV_EXCL_START */ ERR("Failed to get a package name"); set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY); return NULL; - /* LCOV_EXCL_STOP */ } noti = (notification_h)calloc(1, sizeof(struct _notification)); if (noti == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc a new notification"); set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY); free(caller_app_id); return NULL; - /* LCOV_EXCL_STOP */ } ret = notification_ipc_request_load_noti_by_tag(noti, caller_app_id, (char *)tag, uid); @@ -1503,7 +1520,9 @@ EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_ return noti; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API notification_h notification_create_from_package_template(const char *app_id, const char *template_name) { int ret; @@ -1517,11 +1536,9 @@ EXPORT_API notification_h notification_create_from_package_template(const char * noti = (notification_h)calloc(1, sizeof(struct _notification)); if (noti == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY); return NULL; - /* LCOV_EXCL_STOP */ } ret = notification_ipc_request_create_from_package_template(noti, app_id, template_name); @@ -1533,7 +1550,9 @@ EXPORT_API notification_h notification_create_from_package_template(const char * return noti; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index) { if (noti == NULL) @@ -1654,7 +1673,9 @@ EXPORT_API int notification_get_text_input_max_length(notification_h noti, int * return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, event_handler_cb cb, void *userdata, uid_t uid) { @@ -1690,10 +1711,8 @@ EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, even } else { info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s)); if (info == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } info->priv_id = priv_id; info->cb = cb; @@ -1703,7 +1722,9 @@ EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, even return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_post_with_event_cb(notification_h noti, event_handler_cb cb, void *userdata) { return notification_post_with_event_cb_for_uid(noti, cb, userdata, getuid()); @@ -1860,9 +1881,12 @@ EXPORT_API int notification_get_extension_data(notification_h noti, const char * return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ #define KEY_LEN 40 #define EXTENSION_EVENT_KEY "_NOTIFICATION_EXTENSION_EVENT_" + +/* LCOV_EXCL_START */ EXPORT_API int notification_set_extension_event_handler(notification_h noti, notification_event_type_extension_e event, app_control_h event_handler) @@ -1898,29 +1922,23 @@ EXPORT_API int notification_set_extension_event_handler(notification_h noti, err = app_control_export_as_bundle(event_handler, &app_control_bundle); if (err != APP_CONTROL_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to export app_control to bundle [%d]", err); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } err = bundle_encode(app_control_bundle, &b_raw, &len); if (err != BUNDLE_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to encode bundle [%d]", err); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } err = bundle_add_str(noti->args, key, (const char *)b_raw); if (err != BUNDLE_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to add str to bundle [%d]", err); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } out: @@ -1931,7 +1949,9 @@ out: return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_get_extension_event_handler(notification_h noti, notification_event_type_extension_e event, app_control_h *event_handler) @@ -1964,29 +1984,23 @@ EXPORT_API int notification_get_extension_event_handler(notification_h noti, app_control_bundle = _create_bundle_from_bundle_raw((bundle_raw *)ret_str); if (app_control_bundle == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to create bundle"); return NOTIFICATION_ERROR_IO_ERROR; - /* LCOV_EXCL_STOP */ } err = app_control_create(&ret_app_control); if (err != APP_CONTROL_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to create app control [%d]", err); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } err = app_control_import_from_bundle(ret_app_control, app_control_bundle); if (err != APP_CONTROL_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to import app control from bundle [%d]", err); app_control_destroy(ret_app_control); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } *event_handler = ret_app_control; @@ -1997,7 +2011,9 @@ out: return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid) { int ret; @@ -2191,3 +2207,4 @@ EXPORT_API int notification_get_check_box_checked(notification_h noti, return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ diff --git a/notification/src/notification_ipc.c b/notification/src/notification_ipc.c index c97dcd9..07f215f 100644 --- a/notification/src/notification_ipc.c +++ b/notification/src/notification_ipc.c @@ -200,6 +200,7 @@ int notification_ipc_is_master_ready(void) /* * store tasks when daemon stopped */ + /* LCOV_EXCL_START */ int notification_ipc_add_deffered_task( void (*deferred_task_cb)(void *data), void *user_data) @@ -272,6 +273,7 @@ int notification_ipc_del_deffered_task( return NOTIFICATION_ERROR_INVALID_PARAMETER; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void _do_deffered_task(void) @@ -504,6 +506,7 @@ static void _delete_multiple_notify(GVariant *parameters) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _delete_by_display_applist_notify(GVariant *parameters) { int *buf; @@ -545,6 +548,7 @@ static void _delete_by_display_applist_notify(GVariant *parameters) free(noti_op); free(buf); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void _change_dnd_notify(GVariant *parameters) @@ -589,6 +593,7 @@ static void _handle_noti_notify(GDBusConnection *connection, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _send_event(GVariant *parameters) { int ret; @@ -599,10 +604,8 @@ static void _send_event(GVariant *parameters) noti = notification_create(NOTIFICATION_TYPE_NOTI); if (noti == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to create notification handle"); return; - /* LCOV_EXCL_STOP */ } g_variant_get(parameters, "(vi)", &coupled_body, &event_type); @@ -612,16 +615,15 @@ static void _send_event(GVariant *parameters) g_variant_unref(coupled_body); g_variant_unref(body); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to make notification handle from gvariant"); notification_free(noti); return; - /* LCOV_EXCL_STOP */ } notification_call_event_handler_cb(noti, event_type); notification_free(noti); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void _delete_event(GVariant *parameters) @@ -633,6 +635,7 @@ static void _delete_event(GVariant *parameters) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _handle_noti_event_handler_notify(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -649,7 +652,9 @@ static void _handle_noti_event_handler_notify(GDBusConnection *connection, else if (g_strcmp0(signal_name, "delete_noti") == 0) _delete_event(parameters); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _dbus_event_handler_signal_init(void) { int id; @@ -669,10 +674,8 @@ static int _dbus_event_handler_signal_init(void) DBG("subscribe id[%d]", id); if (id == 0) { - /* LCOV_EXCL_START */ ret = NOTIFICATION_ERROR_IO_ERROR; ERR("Failed to subscribe connection signal"); - /* LCOV_EXCL_STOP */ } else { event_monitor_id = id; } @@ -681,6 +684,7 @@ static int _dbus_event_handler_signal_init(void) return ret; } +/* LCOV_EXCL_START */ static int _dbus_signal_init(void) { int id; @@ -700,10 +704,8 @@ static int _dbus_signal_init(void) DBG("subscribe id : %d", id); if (id == 0) { - /* LCOV_EXCL_START */ ret = NOTIFICATION_ERROR_IO_ERROR; ERR("Failed to register dbus_interface"); - /* LCOV_EXCL_STOP */ } else { monitor_id = id; ret = NOTIFICATION_ERROR_NONE; @@ -712,6 +714,7 @@ static int _dbus_signal_init(void) return ret; } +/* LCOV_EXCL_STOP */ static GDBusMessage *__get_new_msg(GVariant *body, const char *cmd) { @@ -830,6 +833,7 @@ static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd) return ret; } +/* LCOV_EXCL_START */ static void _send_message_with_reply_async_cb(GDBusConnection *connection, GAsyncResult *res, gpointer user_data) @@ -842,10 +846,8 @@ static void _send_message_with_reply_async_cb(GDBusConnection *connection, result_cb_item *cb_item = (result_cb_item *)user_data; if (cb_item == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to get a callback item"); return; - /* LCOV_EXCL_START */ } reply = g_dbus_connection_send_message_with_reply_finish( @@ -854,16 +856,13 @@ static void _send_message_with_reply_async_cb(GDBusConnection *connection, &err); if (!reply) { - /* LCOV_EXCL_START */ if (err != NULL) { ERR("No reply[%s]", err->message); g_error_free(err); } result = NOTIFICATION_ERROR_SERVICE_NOT_READY; - /* LCOV_EXCL_STOP */ } else if (g_dbus_message_to_gerror(reply, &err)) { - /* LCOV_EXCL_START */ if (err->code == G_DBUS_ERROR_ACCESS_DENIED) result = NOTIFICATION_ERROR_PERMISSION_DENIED; else @@ -871,7 +870,6 @@ static void _send_message_with_reply_async_cb(GDBusConnection *connection, ERR("Failed to send message[%s]", err->message); g_error_free(err); - /* LCOV_EXCL_STOP */ } INFO("Async message callback result[%d]", result); @@ -890,7 +888,9 @@ static void _send_message_with_reply_async_cb(GDBusConnection *connection, g_object_unref(reply); free(cb_item); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd) { GDBusMessage *msg; @@ -901,10 +901,8 @@ static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd) PROVIDER_NOTI_INTERFACE_NAME, cmd); if (!msg) { - /* LCOV_EXCL_START */ ERR("Failed to alloc new method call"); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } if (g_variant_is_floating(body)) @@ -929,6 +927,8 @@ static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd) DBG("Success to send async message"); return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ + int notification_ipc_request_insert(notification_h noti, int *priv_id) { @@ -1026,6 +1026,7 @@ int notification_ipc_request_update(notification_h noti) return result; } +/* LCOV_EXCL_START */ int notification_ipc_request_update_async(notification_h noti, void (*result_cb)(int priv_id, int result, void *data), void *user_data) { @@ -1035,10 +1036,8 @@ int notification_ipc_request_update_async(notification_h noti, result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } cb_item = calloc(1, sizeof(result_cb_item)); @@ -1050,28 +1049,26 @@ int notification_ipc_request_update_async(notification_h noti, body = notification_ipc_make_gvariant_from_noti(noti, false); if (body == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to make gvariant from notification handle"); free(cb_item); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } result = _send_async_noti(body, cb_item, "update_noti"); DBG("Update async result[%d]", result); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ free(cb_item); cb_item = NULL; - /* LCOV_EXCL_STOP */ } g_variant_unref(body); return result; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ int notification_ipc_request_refresh(uid_t uid) { int result; @@ -1080,10 +1077,8 @@ int notification_ipc_request_refresh(uid_t uid) result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } body = g_variant_new("(i)", uid); @@ -1095,6 +1090,7 @@ int notification_ipc_request_refresh(uid_t uid) DBG("result[%d]", result); return result; } +/* LCOV_EXCL_STOP */ int notification_ipc_request_delete_single(notification_type_e type, char *app_id, int priv_id, uid_t uid) { @@ -1162,6 +1158,7 @@ int notification_ipc_request_delete_multiple(notification_type_e type, char *app return result; } +/* LCOV_EXCL_START */ int notification_ipc_request_delete_by_display_applist(int display_applist, uid_t uid) { int result; @@ -1191,6 +1188,7 @@ int notification_ipc_request_delete_by_display_applist(int display_applist, uid_ DBG("result[%d]", result); return result; } +/* LCOV_EXCL_STOP */ int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *app_id, const char *tag, uid_t uid) { @@ -1470,6 +1468,7 @@ int notification_ipc_request_load_noti_detail_list(const char *app_id, return result; } +/* LCOV_EXCL_START */ int notification_ipc_request_get_setting_array( notification_setting_h *setting_array, int *count, @@ -1487,10 +1486,8 @@ int notification_ipc_request_get_setting_array( result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "get_setting_array"); @@ -1502,12 +1499,10 @@ int notification_ipc_request_get_setting_array( DBG("get setting arr cnt: %d", setting_cnt); result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt); if (result_setting_array == NULL) { - /* LCOV_EXCL_START */ ERR("malloc failed"); g_object_unref(reply); g_variant_iter_free(iter); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } setting_idx = 0; @@ -1528,7 +1523,9 @@ int notification_ipc_request_get_setting_array( DBG("result[%d]", result); return result; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ int notification_ipc_request_get_setting_by_app_id( const char *app_id, notification_setting_h *setting, uid_t uid) { @@ -1554,12 +1551,10 @@ int notification_ipc_request_get_setting_by_app_id( result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting)); if (result_setting == NULL) { - /* LCOV_EXCL_START */ ERR("malloc failed"); g_object_unref(reply); g_variant_unref(body); return NOTIFICATION_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ } notification_ipc_make_setting_from_gvariant(result_setting, setting_body); @@ -1573,7 +1568,9 @@ int notification_ipc_request_get_setting_by_app_id( DBG("result[%d]", result); return result; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ int notification_ipc_request_load_system_setting(notification_system_setting_h *setting, uid_t uid) { int result; @@ -1588,10 +1585,8 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h * result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "load_system_setting"); @@ -1601,11 +1596,9 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h * result_setting = (struct notification_system_setting *)calloc(1, sizeof(struct notification_system_setting)); if (result_setting == NULL) { - /* LCOV_EXCL_START */ ERR("malloc failed"); result = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body); @@ -1623,12 +1616,10 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h * while (g_variant_iter_loop(iter, "(v)", &iter_body)) { dnd_allow_exception = (dnd_allow_exception_h)calloc(1, sizeof(struct notification_system_setting_dnd_allow_exception)); if (dnd_allow_exception == NULL) { - /* LCOV_EXCL_START */ ERR("Out of memory"); result = NOTIFICATION_ERROR_OUT_OF_MEMORY; g_variant_unref(iter_body); goto out; - /* LCOV_EXCL_STOP */ } notification_ipc_make_dnd_allow_exception_from_gvariant(dnd_allow_exception, iter_body); @@ -1652,6 +1643,7 @@ out: DBG("result[%d]", result); return result; } +/* LCOV_EXCL_START */ int notification_ipc_update_setting(notification_setting_h setting, uid_t uid) { @@ -1686,6 +1678,7 @@ int notification_ipc_update_setting(notification_setting_h setting, uid_t uid) return result; } +/* LCOV_EXCL_START */ int notification_ipc_update_system_setting(notification_system_setting_h system_setting, uid_t uid) { int result; @@ -1696,10 +1689,8 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_ result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } body = g_variant_new("(iiiiiiiiii)", @@ -1735,6 +1726,7 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_ DBG("result[%d]", result); return result; } +/* LCOV_EXCL_STOP */ int notification_ipc_request_save_as_template(notification_h noti, const char *template_name) { @@ -1801,6 +1793,7 @@ int notification_ipc_request_create_from_template(notification_h noti, const cha return result; } +/* LCOV_EXCL_START */ int notification_ipc_request_create_from_package_template(notification_h noti, const char *app_id, const char *template_name) { int result; @@ -1811,10 +1804,8 @@ int notification_ipc_request_create_from_package_template(notification_h noti, c result = _dbus_init(); if (result != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", result); return result; - /* LCOV_EXCL_STOP */ } body = g_variant_new("(ss)", app_id, template_name); @@ -1836,6 +1827,7 @@ int notification_ipc_request_create_from_package_template(notification_h noti, c return result; } +/* LCOV_EXCL_STOP */ int notification_ipc_get_noti_block_state(const char *app_id, int *do_not_disturb, int *do_not_disturb_except, int *allow_to_notify, @@ -1883,6 +1875,7 @@ int notification_ipc_get_noti_block_state(const char *app_id, int *do_not_distur return ret; } +/* LCOV_EXCL_START */ int notification_ipc_request_get_all_count(notification_type_e type, int *count, uid_t uid) { int ret; @@ -1972,6 +1965,7 @@ int notification_ipc_check_event_receiver(int priv_id, bool *available) DBG("result[%d]", ret); return ret; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ void notification_ipc_reset_event_handler(int priv_id) @@ -2440,6 +2434,7 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti, return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_START */ EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting) { GVariant *body = NULL; @@ -2627,6 +2622,7 @@ static int _ipc_monitor_register(uid_t uid) { return _send_service_register(uid); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void _on_name_appeared(GDBusConnection *connection, @@ -2658,32 +2654,27 @@ static void _on_name_vanished(GDBusConnection *connection, } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ int notification_ipc_monitor_init(uid_t uid) { int ret; ret = _dbus_init(); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init dbus connection[%d]", ret); return ret; - /* LCOV_EXCL_STOP */ } ret = _dbus_signal_init(); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init signal[%d]", ret); return ret; - /* LCOV_EXCL_STOP */ } ret = _ipc_monitor_register(uid); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to register service[%d]", ret); return ret; - /* LCOV_EXCL_STOP */ } if (provider_monitor_id == 0) { @@ -2696,18 +2687,18 @@ int notification_ipc_monitor_init(uid_t uid) GINT_TO_POINTER((int)uid), NULL); if (provider_monitor_id == 0) { - /* LCOV_EXCL_START */ g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id); monitor_id = 0; ERR("Failed to watch name"); return NOTIFICATION_ERROR_IO_ERROR; - /* LCOV_EXCL_STOP */ } } return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _ipc_monitor_deregister(void) { if (provider_monitor_id) { @@ -2727,6 +2718,7 @@ int notification_ipc_monitor_fini(void) { return _ipc_monitor_deregister(); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ void notification_ipc_event_monitor_fini(void) diff --git a/notification/src/notification_ipc_socket.c b/notification/src/notification_ipc_socket.c index 54090ac..ae9cceb 100644 --- a/notification/src/notification_ipc_socket.c +++ b/notification/src/notification_ipc_socket.c @@ -69,12 +69,14 @@ EXPORT_API int notification_ipc_socket_get_read_buf_size(int fd, unsigned int *s return __get_socket_buffer_size(fd, size, SO_RCVBUF); } +/* LCOV_EXCL_START */ EXPORT_API int notification_ipc_socket_get_write_buf_size(int fd, unsigned int *size) { return __get_socket_buffer_size(fd, size, SO_SNDBUF); } +/* LCOV_EXCL_STOP */ - +/* LCOV_EXCL_START */ EXPORT_API int notification_ipc_socket_write(int fd, const char *buffer, unsigned int nbytes) { int retry_cnt = 0; @@ -86,7 +88,6 @@ EXPORT_API int notification_ipc_socket_write(int fd, const char *buffer, unsigne errno = 0; nb = write(fd, buffer, left); if (nb == -1) { - /* LCOV_EXCL_START */ if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { ERR("continue.."); retry_cnt++; @@ -95,7 +96,6 @@ EXPORT_API int notification_ipc_socket_write(int fd, const char *buffer, unsigne } ERR("error fd [%d] errno [%d]", fd, errno); return NOTIFICATION_ERROR_IO_ERROR; - /* LCOV_EXCL_STOP */ } left -= nb; @@ -110,31 +110,30 @@ EXPORT_API int notification_ipc_socket_write(int fd, const char *buffer, unsigne return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_ipc_socket_write_string(int fd, const char *buffer, unsigned int string_len) { int ret; ret = notification_ipc_socket_write(fd, (char *)&string_len, sizeof(string_len)); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("write string_len fail"); return ret; - /* LCOV_EXCL_STOP */ } if (string_len > 0) { ret = notification_ipc_socket_write(fd, buffer, string_len); if (ret != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("write string fail"); return ret; - /* LCOV_EXCL_STOP */ } } return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ EXPORT_API int notification_ipc_socket_read(int fd, char *buffer, unsigned int nbytes) { diff --git a/notification/src/notification_setting.c b/notification/src/notification_setting.c index 6be851f..652706a 100644 --- a/notification/src/notification_setting.c +++ b/notification/src/notification_setting.c @@ -49,6 +49,7 @@ struct _noti_dnd_cb_info { static GHashTable *_noti_dnd_cb_hash = NULL; +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_setting_array_for_uid(notification_setting_h *setting_array, int *count, uid_t uid) { if (setting_array == NULL || count == NULL) { @@ -73,6 +74,7 @@ EXPORT_API int notification_setting_get_setting_by_appid_for_uid(const char *app return notification_ipc_request_get_setting_by_app_id(app_id, setting, uid); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_setting_by_package_name(const char *package_name, notification_setting_h *setting) @@ -99,6 +101,7 @@ EXPORT_API int notification_setting_get_setting(notification_setting_h *setting) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_package_name(notification_setting_h setting, char **value) { if (setting == NULL || value == NULL) { @@ -107,17 +110,17 @@ EXPORT_API int notification_setting_get_package_name(notification_setting_h sett } if (setting->package_name == NULL) { - /* LCOV_EXCL_START */ ERR("setting->package_name is null"); return NOTIFICATION_ERROR_NOT_EXIST_ID; - /* LCOV_EXCL_STOP */ } *value = SAFE_STRDUP(setting->package_name); return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_appid(notification_setting_h setting, char **app_id) { if (setting == NULL || app_id == NULL) { @@ -126,17 +129,17 @@ EXPORT_API int notification_setting_get_appid(notification_setting_h setting, ch } if (setting->app_id == NULL) { - /* LCOV_EXCL_START */ ERR("setting->app_id is null"); return NOTIFICATION_ERROR_NOT_EXIST_ID; - /* LCOV_EXCL_STOP */ } *app_id = SAFE_STRDUP(setting->app_id); return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_allow_to_notify(notification_setting_h setting, bool *value) { if (setting == NULL || value == NULL) { @@ -184,6 +187,7 @@ EXPORT_API int notification_setting_set_do_not_disturb_except(notification_setti return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ EXPORT_API int notification_setting_get_visibility_class(notification_setting_h setting, int *value) { @@ -209,6 +213,7 @@ EXPORT_API int notification_setting_set_visibility_class(notification_setting_h return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_get_pop_up_notification(notification_setting_h setting, bool *value) { if (setting == NULL || value == NULL) { @@ -266,6 +271,7 @@ EXPORT_API int notification_setting_get_app_disabled(notification_setting_h sett return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ EXPORT_API int notification_setting_update_setting_for_uid(notification_setting_h setting, uid_t uid) { @@ -299,6 +305,7 @@ EXPORT_API int notification_setting_free_notification(notification_setting_h set return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_START */ static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, const char *app_id, uid_t uid) { @@ -319,20 +326,16 @@ static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, uid, package_name); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("fail to alloc query"); return false; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); if (sql_ret != SQLITE_OK) { - /* LCOV_EXCL_START */ ERR("sqlite3_prepare_v2 failed [%d][%s]", sql_ret, sqlite3_errmsg(db)); err = false; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_step(stmt); @@ -344,12 +347,10 @@ static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, } if (sql_ret != SQLITE_OK && sql_ret != SQLITE_ROW) { - /* LCOV_EXCL_START */ ERR("sqlite3_step failed [%d][%s]", sql_ret, sqlite3_errmsg(db)); err = false; goto out; - /* LCOV_EXCL_STOP */ } out: @@ -361,7 +362,9 @@ out: return err; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle, void *user_data) { @@ -375,21 +378,17 @@ static int _foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle, ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id); if (ret != PACKAGE_MANAGER_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to get appid from pkgmgrinfo [%d]", ret); err = false; goto out; - /* LCOV_EXCL_STOP */ } ret = pkgmgrinfo_appinfo_get_pkgname(handle, &package_name); if (ret != PACKAGE_MANAGER_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to get pkgname from pkgmgrinfo[%d]", ret); goto out; - /* LCOV_EXCL_STOP */ } if (_is_package_in_setting_table(db, package_name, app_id, info->uid) == true) { @@ -403,11 +402,9 @@ static int _foreach_app_info_callback(const pkgmgrinfo_appinfo_h handle, NOTIFICATION_SETTING_DB_TABLE, info->uid, package_name, app_id); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("fail to alloc query"); err = false; goto out; - /* LCOV_EXCL_STOP */ } ret = notification_db_exec(db, query, NULL); @@ -423,7 +420,9 @@ out: return err; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _install_and_update_package(const char *package_name, uid_t uid) { sqlite3 *db; @@ -438,31 +437,25 @@ static int _install_and_update_package(const char *package_name, uid_t uid) pkgmgr_ret = pkgmgrinfo_appinfo_filter_create(&handle); if (pkgmgr_ret != PMINFO_R_OK) { - /* LCOV_EXCL_START */ ERR("Failed to create appinfo_filter[%d]", pkgmgr_ret); err = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_PRIVILEGE, NOTIFICATION_PRIVILEGE); if (pkgmgr_ret != PMINFO_R_OK) { - /* LCOV_EXCL_START */ ERR("Failed to add string to appinfo_filter[%d]", pkgmgr_ret); err = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } pkgmgr_ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_PACKAGE, package_name); if (pkgmgr_ret != PMINFO_R_OK) { - /* LCOV_EXCL_START */ ERR("Failed to add string to appinfo_filter[%d]", pkgmgr_ret); err = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } info.db = db; @@ -470,11 +463,9 @@ static int _install_and_update_package(const char *package_name, uid_t uid) pkgmgr_ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, _foreach_app_info_callback, &info, uid); if (pkgmgr_ret != PMINFO_R_OK) { - /* LCOV_EXCL_START */ ERR("Failed to iterate appinfo[%d]", pkgmgr_ret); err = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } out: @@ -486,7 +477,9 @@ out: return err; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int _delete_package_from_setting_db(const char *package_name, uid_t uid) { sqlite3 *db = NULL; @@ -510,11 +503,9 @@ static int _delete_package_from_setting_db(const char *package_name, uid_t uid) NOTIFICATION_SETTING_DB_TABLE, uid, package_name); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc query"); err = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } err = notification_db_exec(db, query, NULL); @@ -528,6 +519,7 @@ out: return err; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API int notification_setting_refresh_setting_table(uid_t uid) @@ -580,6 +572,7 @@ out: } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_setting_insert_package_for_uid(const char *package_name, uid_t uid) { return _install_and_update_package(package_name, uid); @@ -888,6 +881,7 @@ static gint _noti_dnd_cb_compare(gconstpointer a, gconstpointer b) return 1; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ void notification_call_dnd_changed_cb_for_uid(int do_not_disturb, uid_t uid) @@ -915,6 +909,7 @@ void notification_call_dnd_changed_cb_for_uid(int do_not_disturb, uid_t uid) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_register_system_setting_dnd_changed_cb_for_uid(dnd_changed_cb callback, void *user_data, uid_t uid) { GList *noti_dnd_list = NULL; @@ -925,10 +920,8 @@ EXPORT_API int notification_register_system_setting_dnd_changed_cb_for_uid(dnd_c return NOTIFICATION_ERROR_INVALID_PARAMETER; if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) { - /* LCOV_EXCL_START */ ERR("Failed to init monitor"); return NOTIFICATION_ERROR_IO_ERROR; - /* LCOV_EXCL_STOP */ } if (_noti_dnd_cb_hash == NULL) @@ -960,7 +953,9 @@ EXPORT_API int notification_register_system_setting_dnd_changed_cb_for_uid(dnd_c return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_register_system_setting_dnd_changed_cb(dnd_changed_cb callback, void *user_data) { return notification_register_system_setting_dnd_changed_cb_for_uid(callback, user_data, getuid()); @@ -1006,11 +1001,14 @@ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb_for_uid(dnd return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb(dnd_changed_cb callback) { return notification_unregister_system_setting_dnd_changed_cb_for_uid(callback, getuid()); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static bool _is_uid_in_system_setting_table(sqlite3 *db, uid_t uid) diff --git a/notification/src/notification_setting_service.c b/notification/src/notification_setting_service.c index f757e2e..a09fb2d 100644 --- a/notification/src/notification_setting_service.c +++ b/notification/src/notification_setting_service.c @@ -33,13 +33,12 @@ #include <notification_setting_service.h> #include "notification_db_query.h" +/* LCOV_EXCL_START */ static int _get_table_field_data_int(char **table, int *buf, int index) { if (table == NULL || buf == NULL || index < 0) { - /* LCOV_EXCL_START */ ERR("table[%p], buf[%p], index[%d]", table, buf, index); return false; - /* LCOV_EXCL_STOP */ } if (table[index] != NULL) { @@ -47,10 +46,8 @@ static int _get_table_field_data_int(char **table, int *buf, int index) return true; } - /* LCOV_EXCL_START */ *buf = 0; return false; - /* LCOV_EXCL_STOP */ } static int _get_table_field_data_string(char **table, char **buf, int ucs2, int index) @@ -60,10 +57,8 @@ static int _get_table_field_data_string(char **table, char **buf, int ucs2, int char *pTemp; if (table == NULL || buf == NULL || index < 0) { - /* LCOV_EXCL_START */ ERR("table[%p], buf[%p], index[%d]", table, buf, index); return false; - /* LCOV_EXCL_STOP */ } pTemp = table[index]; @@ -118,21 +113,17 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_ NOTIFICATION_SETTING_DB_ATTRIBUTES, NOTIFICATION_SETTING_DB_TABLE, app_id, uid); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc query"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("sqlite3_get_table failed [%d][%s]", sql_ret, query); ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } if (!row_count) { @@ -147,11 +138,9 @@ int noti_setting_service_get_setting_by_app_id(const char *app_id, notification_ result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count); if (result_setting_array == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } col_index = column_count; @@ -208,21 +197,17 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c "app_id ", NOTIFICATION_SETTING_DB_ATTRIBUTES, NOTIFICATION_SETTING_DB_TABLE, uid, 0); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc query"); /* LCOV_EXCL_LINE */ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get db table [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */ ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } if (!row_count) { @@ -235,11 +220,9 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * row_count); if (result_setting_array == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); /* LCOV_EXCL_LINE */ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } col_index = column_count; @@ -298,36 +281,29 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste NOTIFICATION_SYSTEM_SETTING_DB_ATTRIBUTES, NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc query"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get db table [%d][%s]", sql_ret, query); ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } DBG("row_count [%d] column_count [%d]", row_count, column_count); result_system_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting)); if (result_system_setting == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } /* no system setting record. allow everyting */ if (!row_count) { - /* LCOV_EXCL_START */ DBG("No setting found"); result_system_setting->do_not_disturb = 0; result_system_setting->visibility_class = 0; @@ -339,9 +315,7 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste result_system_setting->dnd_end_min = 0; result_system_setting->lock_screen_content_level = 0; result_system_setting->dnd_allow_exceptions = NULL; - /* LCOV_EXCL_STOP */ } else { - /* LCOV_EXCL_START */ col_index = column_count; _get_table_field_data_int(query_result, (int *)&(result_system_setting->do_not_disturb), col_index++); _get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++); @@ -353,7 +327,6 @@ int noti_system_setting_load_system_setting(notification_system_setting_h *syste _get_table_field_data_int(query_result, &(result_system_setting->dnd_end_min), col_index++); _get_table_field_data_int(query_result, (int *)&(result_system_setting->lock_screen_content_level), col_index++); result_system_setting->dnd_allow_exceptions = NULL; - /* LCOV_EXCL_STOP */ } *system_setting = result_system_setting; @@ -399,10 +372,8 @@ int notification_setting_db_update(const char *package_name, const char *app_id, pop_up_notification, lock_screen_content_level, app_id, package_name, uid); if (query == NULL) { - /* LCOV_EXCL_START */ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } ret = notification_db_exec(db, query, NULL); @@ -442,10 +413,8 @@ int notification_setting_db_update_system_setting(int do_not_disturb, int visibi dnd_start_min, dnd_end_hour, dnd_end_min, lock_screen_content_level); if (query == NULL) { - /* LCOV_EXCL_START */ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } ret = notification_db_exec(db, query, &num_changes); @@ -464,6 +433,7 @@ out: return ret; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API @@ -567,6 +537,7 @@ out: } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_get_dnd_and_allow_to_notify(const char *app_id, int *do_not_disturb, @@ -598,31 +569,25 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id, NOTIFICATION_SETTING_DB_TABLE, app_id, uid, tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)); if (query_setting == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } query_system_setting = sqlite3_mprintf("SELECT do_not_disturb FROM %s " "WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid); if (query_system_setting == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_get_table(db, query_setting, &query_setting_result, &row_count, &col_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get DB table [%d][%s]", sql_ret, query_setting); ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } if (row_count == 0) { @@ -637,11 +602,9 @@ int notification_get_dnd_and_allow_to_notify(const char *app_id, sql_ret = sqlite3_get_table(db, query_system_setting, &query_system_setting_result, &row_count, &col_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get DB table [%d][%s]", sql_ret, query_setting); ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } if (row_count == 0) { @@ -697,20 +660,16 @@ EXPORT_API int notification_system_setting_load_dnd_allow_exception(dnd_allow_ex query = sqlite3_mprintf("SELECT type, value FROM %s WHERE uid = %d", NOTIFICATION_DND_ALLOW_EXCEPTION, uid); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } sql_ret = sqlite3_get_table(db, query, &query_result, &row_count, &column_count, NULL); if (sql_ret != SQLITE_OK && sql_ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get DB table [%d][%s]", sql_ret, query); /* LCOV_EXCL_LINE */ ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } if (!row_count) { @@ -765,11 +724,9 @@ int notification_system_setting_update_dnd_allow_exception(int type, int value, NOTIFICATION_DND_ALLOW_EXCEPTION, uid, type, value); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } ret = notification_db_exec(db, query, &num_changes); @@ -807,28 +764,22 @@ int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid) query = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid); if (query == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to alloc memory"); ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; - /* LCOV_EXCL_STOP */ } ret = sqlite3_get_table(db, query, &query_result, &row_count, &col_count, NULL); if (ret != SQLITE_OK && ret != -1) { - /* LCOV_EXCL_START */ ERR("Failed to get DB table [%d][%s]", ret, query); ret = NOTIFICATION_ERROR_FROM_DB; goto out; - /* LCOV_EXCL_STOP */ } col_index = col_count; if (row_count == 0) { - /* LCOV_EXCL_START */ ERR("No system setting found"); ret = NOTIFICATION_ERROR_INVALID_PARAMETER; - /* LCOV_EXCL_STOP */ } else { if (_get_table_field_data_int(query_result, (int *)do_not_disturb, col_index++) == false) ret = NOTIFICATION_ERROR_FROM_DB; @@ -846,6 +797,7 @@ out: return ret; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API diff --git a/notification/src/notification_shared_file.c b/notification/src/notification_shared_file.c index 2f5d886..bfd4265 100644 --- a/notification/src/notification_shared_file.c +++ b/notification/src/notification_shared_file.c @@ -84,6 +84,7 @@ typedef struct target_app_info { char *dbus_sender_name; } target_app_info_s; +/* LCOV_EXCL_START */ static const char *__last_index_of(const char *path, const char *search); static bool __make_sharing_dir(const char *dir) { @@ -98,20 +99,20 @@ static bool __make_sharing_dir(const char *dir) return false; if (g_file_make_directory(noti_dir, NULL, &g_err) == false) { - /* LCOV_EXCL_START */ if (g_err) { ERR("Failed to make sharing dir[%s]", g_err->message); g_error_free(g_err); } g_object_unref(noti_dir); return false; - /* LCOV_EXCL_STOP */ } g_object_unref(noti_dir); return true; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static char *__get_data_path_by_pkg_id(const char *pkg_id, const char *file_path, uid_t uid) { @@ -181,6 +182,7 @@ static const char *__last_index_of(const char *path, const char *search) return NULL; } +/* LCOV_EXCL_STOP */ /* Check path that include res directory */ /* LCOV_EXCL_START */ @@ -200,6 +202,7 @@ static bool __is_private_file(const char *smack_label, const char *pkg_id) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static bool __is_RO_file(const char *smack_label) { #define CHECK_LABEL "::RO" @@ -213,8 +216,10 @@ static bool __is_RO_file(const char *smack_label) return ret; } +/* LCOV_EXCL_STOP */ /* file copy from /res to /data */ +/* LCOV_EXCL_START */ int notification_copy_private_file(const char *src_path, const char *dst_path) { @@ -226,11 +231,9 @@ int notification_copy_private_file(const char *src_path, dst = g_file_new_for_path(dst_path); if (dst == NULL) { - /* LCOV_EXCL_START */ ERR("dst path is wrong [%s]", dst_path); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } if (g_file_query_exists(dst, NULL) == true) { @@ -241,16 +244,13 @@ int notification_copy_private_file(const char *src_path, src = g_file_new_for_path(src_path); if (src == NULL) { - /* LCOV_EXCL_START */ ERR("src path is wrong [%s]", src_path); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } if (!g_file_copy(src, dst, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, &g_err)) { - /* LCOV_EXCL_START */ if (g_err) { ERR("Copying file from [%s] to [%s] is failed [%s]", src_path, dst_path, g_err->message); @@ -258,7 +258,6 @@ int notification_copy_private_file(const char *src_path, } ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } ut.modtime = time(NULL); @@ -273,7 +272,9 @@ out: return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void __free_file_info(gpointer data) { sharing_file_info_s *info = (sharing_file_info_s *)data; @@ -286,6 +287,7 @@ static void __free_file_info(gpointer data) free(info); } } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static void __free_req_info(gpointer data) @@ -307,6 +309,7 @@ static void __free_req_info(gpointer data) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static char **__convert_list_to_array(GList *list, int *length) { int len, i; @@ -341,6 +344,7 @@ static gint __comp_str(gconstpointer a, gconstpointer b) return strcmp(new_file, file); } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ static gint __comp_file_info(gconstpointer a, gconstpointer b) @@ -368,6 +372,7 @@ static gint __comp_dst_path(gconstpointer a, gconstpointer b) } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static sharing_file_info_s *__dup_file_info(sharing_file_info_s *src) { sharing_file_info_s *file_info; @@ -920,7 +925,9 @@ out: return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ int __set_sharing_for_new_file(sharing_req_data_s *req_data, GList *new_file_list, bool is_overlapping) { @@ -946,21 +953,17 @@ int __set_sharing_for_new_file(sharing_req_data_s *req_data, ret = security_manager_private_sharing_req_set_owner_appid(handle, req_data->app_id); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to set owner appid[%s][%d]", req_data->app_id, ret); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } ret = security_manager_private_sharing_req_add_paths(handle, (const char **)path_array, len); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to add paths [%d]", ret); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } if (is_overlapping == true) { @@ -969,21 +972,17 @@ int __set_sharing_for_new_file(sharing_req_data_s *req_data, ret = security_manager_private_sharing_req_set_target_appid( handle, (const char *)iter->data); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to set target appid [%s]", (const char *)iter->data); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } ret = security_manager_private_sharing_drop(handle); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to drop [%d]", ret); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } } } @@ -993,21 +992,17 @@ int __set_sharing_for_new_file(sharing_req_data_s *req_data, ret = security_manager_private_sharing_req_set_target_appid(handle, (const char *)iter->data); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to set target appid [%s]", (const char *)iter->data); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } ret = security_manager_private_sharing_apply(handle); if (ret != SECURITY_MANAGER_SUCCESS) { - /* LCOV_EXCL_START */ ERR("Failed to apply PS [%d]", ret); ret = NOTIFICATION_ERROR_IO_ERROR; goto out; - /* LCOV_EXCL_STOP */ } } @@ -1020,7 +1015,9 @@ out: return ret; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_set_private_sharing(notification_h noti, uid_t uid) { @@ -1297,3 +1294,4 @@ EXPORT_API void notification_remove_private_sharing( } } +/* LCOV_EXCL_STOP */ diff --git a/notification/src/notification_status.c b/notification/src/notification_status.c index cb69bbc..7d37464 100644 --- a/notification/src/notification_status.c +++ b/notification/src/notification_status.c @@ -44,6 +44,7 @@ struct _message_cb_data { static struct _message_cb_data md; +/* LCOV_EXCL_START */ static void __notification_status_message_dbus_callback(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, @@ -56,22 +57,20 @@ static void __notification_status_message_dbus_callback(GDBusConnection *connect g_variant_get(parameters, "(&s)", &message); if (strlen(message) <= 0) { - /* LCOV_EXCL_START */ ERR("message is NULL"); return; - /* LCOV_EXCL_STOP */ } if (!md.callback) { - /* LCOV_EXCL_START */ ERR("No callback"); return; - /* LCOV_EXCL_STOP */ } md.callback(message, md.data); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_status_monitor_message_cb_set(notification_status_message_cb callback, void *user_data) { @@ -83,12 +82,10 @@ int notification_status_monitor_message_cb_set(notification_status_message_cb ca if (md.conn == NULL) { md.conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (md.conn == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to connect to the D-BUS Daemon[%s]", error->message); g_error_free(error); return NOTIFICATION_ERROR_FROM_DBUS; - /* LCOV_EXCL_STOP */ } } @@ -104,11 +101,9 @@ int notification_status_monitor_message_cb_set(notification_status_message_cb ca NULL, NULL); if (md.message_id == 0) { - /* LCOV_EXCL_START */ ERR("Failed to subscribe signal"); g_object_unref(md.conn); return NOTIFICATION_ERROR_FROM_DBUS; - /* LCOV_EXCL_STOP */ } } @@ -117,7 +112,9 @@ int notification_status_monitor_message_cb_set(notification_status_message_cb ca return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_status_monitor_message_cb_unset(void) { @@ -136,7 +133,9 @@ int notification_status_monitor_message_cb_unset(void) return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ EXPORT_API int notification_status_message_post(const char *message) { @@ -152,12 +151,10 @@ int notification_status_message_post(const char *message) conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); if (conn == NULL) { - /* LCOV_EXCL_START */ ERR("Failed to connect to the D-BUS Daemon[%s]", err->message); ret = NOTIFICATION_ERROR_FROM_DBUS; goto end; - /* LCOV_EXCL_STOP */ } param = g_variant_new("(s)", message); @@ -169,21 +166,17 @@ int notification_status_message_post(const char *message) MEMBER_NAME, param, &err) == FALSE) { - /* LCOV_EXCL_START */ ERR("Failed to emit signal[%s]", err->message); ret = NOTIFICATION_ERROR_FROM_DBUS; goto end; - /* LCOV_EXCL_STOP */ } if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) { - /* LCOV_EXCL_START */ ERR("Failed to flush connection sync[%s]", err->message); ret = NOTIFICATION_ERROR_FROM_DBUS; goto end; - /* LCOV_EXCL_STOP */ } end: @@ -195,3 +188,4 @@ end: return ret; } +/* LCOV_EXCL_STOP */ diff --git a/notification/src/notification_viewer.c b/notification/src/notification_viewer.c index 69ef54b..3d7e07b 100644 --- a/notification/src/notification_viewer.c +++ b/notification/src/notification_viewer.c @@ -69,6 +69,7 @@ EXPORT_API int notification_init_default_viewer() } /* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static int __pop_delayed_noti() { delayed_noti_info_s *noti = g_list_nth_data(_delayed_noti_list, 0); @@ -139,6 +140,7 @@ static int __push_delayed_noti(bundle *noti_info, uid_t uid) { return NOTIFICATION_ERROR_NONE; } +/* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ EXPORT_API int notification_launch_default_viewer(int priv_id, diff --git a/packaging/notification.spec b/packaging/notification.spec index 17ee72c..5f9e310 100644 --- a/packaging/notification.spec +++ b/packaging/notification.spec @@ -76,10 +76,10 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %check ctest -V %if 0%{?gcov:1} -lcov -c --ignore-errors graph --no-external -q -d . -o notification-ex.info -genhtml notification-ex.info -o notification-ex.out -zip -r notification-ex.zip notification-ex.out -install -m 0644 notification-ex.zip %{buildroot}%{_datadir}/gcov/obj/notification-ex.zip +lcov -c --ignore-errors graph --no-external -q -d . -o notification.info +genhtml notification.info -o notification.out +zip -r notification.zip notification.out +install -m 0644 notification.zip %{buildroot}%{_datadir}/gcov/obj/notification.zip %endif %install @@ -101,7 +101,7 @@ setup() { test_main() { echo "test_main start" - /usr/bin/notification-ex_unittests + /usr/bin/<NAME>-unittests } teardown() { @@ -119,6 +119,11 @@ EOF mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name} install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/ +sed -i -e 's/<NAME>/notification/g' %{buildroot}%{_bindir}/tizen-unittests/%{name}/run-unittest.sh + +mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name}-ex +install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}-ex/ +sed -i -e 's/<NAME>/notification-ex/g' %{buildroot}%{_bindir}/tizen-unittests/%{name}-ex/run-unittest.sh mkdir -p %{buildroot}%{upgrade_script_path} cp -f scripts/505.notification_upgrade.sh %{buildroot}%{upgrade_script_path} @@ -205,19 +210,33 @@ Header & package configuration files to support development of the notification. %attr(0644,root,root) %{_libdir}/libnotification-ex.so ################################################# -# notification-ex_unittests +# notification-ex-unittests ################################################# -%package -n notification-ex_unittests +%package -n notification-ex-unittests Summary: GTest for notification-ex Group: Development/Libraries -%description -n notification-ex_unittests +%description -n notification-ex-unittests GTest for notification-ex -%files -n notification-ex_unittests -%{_bindir}/notification-ex_unittests +%files -n notification-ex-unittests +%{_bindir}/notification-ex-unittests %{_bindir}/tizen-unittests/%{name}/run-unittest.sh +################################################# +# notification-unittests +################################################# +%package -n notification-unittests +Summary: GTest for notification +Group: Development/Libraries + +%description -n notification-unittests +GTest for notification + +%files -n notification-unittests +%{_bindir}/notification-unittests +%{_bindir}/tizen-unittests/%{name}-ex/run-unittest.sh + %if 0%{?gcov:1} %files gcov %{_datadir}/gcov/obj/* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 907a64d..5e5460b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,2 +1,2 @@ -ADD_SUBDIRECTORY(unittest) -ADD_DEPENDENCIES(notification-ex_unittests notification-ex) +ADD_SUBDIRECTORY(noti_unittest) +ADD_SUBDIRECTORY(noti_ex_unittest) diff --git a/tests/mock/app_common_mock.cc b/tests/mock/app_common_mock.cc index 2a49180..ef5ba69 100644 --- a/tests/mock/app_common_mock.cc +++ b/tests/mock/app_common_mock.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "app_common_mock.h" +#include "app_common_mock.hh" -#include "mock_hook.h" -#include "test_fixture.h" +#include "mock_hook.hh" +#include "test_fixture.hh" extern "C" int app_get_name(char** arg1) { return MOCK_HOOK_P1(AppCommonMock, app_get_name, arg1); diff --git a/tests/mock/app_common_mock.h b/tests/mock/app_common_mock.hh index 18bcbc8..c1b85bc 100644 --- a/tests/mock/app_common_mock.h +++ b/tests/mock/app_common_mock.hh @@ -20,7 +20,7 @@ #include <gmock/gmock.h> #include <app_common.h> -#include "module_mock.h" +#include "module_mock.hh" class AppCommonMock : public virtual ModuleMock { public: diff --git a/tests/mock/aul_mock.cc b/tests/mock/aul_mock.cc new file mode 100644 index 0000000..7c6efbc --- /dev/null +++ b/tests/mock/aul_mock.cc @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 "aul_mock.hh" + +#include "mock_hook.hh" +#include "test_fixture.hh" + +extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int len) { + return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, len); +} + +extern "C" int aul_app_get_pkgid_bypid(int pid, char* pkgid, int len) { + return MOCK_HOOK_P3(AulMock, aul_app_get_pkgid_bypid, pid, pkgid, len); +} diff --git a/tests/mock/glib_mock.h b/tests/mock/aul_mock.hh index 03688ad..2c3ea83 100644 --- a/tests/mock/glib_mock.h +++ b/tests/mock/aul_mock.hh @@ -14,28 +14,25 @@ * limitations under the License. */ -#ifndef UNIT_TESTS_MOCK_GLIB_MOCK_H_ -#define UNIT_TESTS_MOCK_GLIB_MOCK_H_ +#ifndef UNIT_TESTS_MOCK_AUL_MOCK_H_ +#define UNIT_TESTS_MOCK_AUL_MOCK_H_ -#include <gio/gio.h> -#include <glib.h> #include <gmock/gmock.h> +#include <aul.h> +#include <aul_app_event.h> +#include <aul_app_group.h> +#include <aul_app_manager.h> +#include <aul_svc.h> +#include <aul_window.h> -#include "module_mock.h" +#include "module_mock.hh" -class GlibMock : public virtual ModuleMock { +class AulMock : public virtual ModuleMock { public: - GlibMock() { - using ::testing::_; - using ::testing::Return; - using ::testing::Invoke; - } + virtual ~AulMock() {} - MOCK_METHOD1(g_file_new_for_path, GFile* (const char*)); - MOCK_METHOD2(g_file_query_exists, gboolean (GFile*, GCancellable*)); - MOCK_METHOD3(g_file_make_directory, gboolean (GFile*, GCancellable*, GError**)); - - MOCK_METHOD2(access, int (const char*, int)); + MOCK_METHOD3(aul_app_get_appid_bypid, int(int, char*, int)); + MOCK_METHOD3(aul_app_get_pkgid_bypid, int(int, char*, int)); }; -#endif // UNIT_TESTS_MOCK_GLIB_MOCK_H_ +#endif // UNIT_TESTS_MOCK_AUL_MOCK_H_ diff --git a/tests/mock/glib_mock.cc b/tests/mock/glib_mock.cc index 15569ac..2e99040 100644 --- a/tests/mock/glib_mock.cc +++ b/tests/mock/glib_mock.cc @@ -14,10 +14,14 @@ * limitations under the License. */ -#include "glib_mock.h" +#include "glib_mock.hh" -#include "mock_hook.h" -#include "test_fixture.h" +#include "mock_hook.hh" +#include "test_fixture.hh" + +extern "C" uid_t getuid() { + return 5001; +} extern "C" GFile* g_file_new_for_path(const char* arg1) { return MOCK_HOOK_P1(GlibMock, g_file_new_for_path, arg1); @@ -35,3 +39,65 @@ extern "C" gboolean g_file_make_directory(GFile* arg1, GCancellable* arg2, extern "C" int access(const char* arg1, int arg2) { return MOCK_HOOK_P2(GlibMock, access, arg1, arg2); } + +extern "C" ssize_t read(int fd, void *buf, size_t count) { + return MOCK_HOOK_P3(GlibMock, read, fd, buf, count); +} + +extern "C" GDBusConnection* g_bus_get_sync(GBusType type, + GCancellable* cancellable, GError** error) { + return MOCK_HOOK_P3(GlibMock, g_bus_get_sync, type, cancellable, error); +} + +extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync( + GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, + gint timeout, volatile guint32* out_serial, GCancellable* cancellable, + GError** error) { + return MOCK_HOOK_P7(GlibMock, g_dbus_connection_send_message_with_reply_sync, + conn, msg, flags, timeout, out_serial, cancellable, error); +} + +extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) { + return MOCK_HOOK_P1(GlibMock, g_dbus_message_get_body, arg0); +} + +extern "C" GList* g_list_append (GList* list, gpointer data) { + return MOCK_HOOK_P2(GlibMock, g_list_append, list, data); +} + +extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, + const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7, + gpointer arg8, GDestroyNotify arg9) { + return MOCK_HOOK_P10(GlibMock, g_dbus_connection_signal_subscribe, + arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); +} + +extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, + GVariant* arg5, GError** arg6) { + return MOCK_HOOK_P7(GlibMock, g_dbus_connection_emit_signal, + arg0, arg1, arg2, arg3, arg4, arg5, arg6); +} + +extern "C" gboolean g_dbus_connection_flush_sync(GDBusConnection* arg0, + GCancellable* arg1, GError** arg2) { + return MOCK_HOOK_P3(GlibMock, g_dbus_connection_flush_sync, arg0, arg1, arg2); +} + +extern "C" const gchar* g_dbus_connection_get_unique_name(GDBusConnection* connection) { + return MOCK_HOOK_P1(GlibMock, g_dbus_connection_get_unique_name, connection); +} + +extern "C" guint g_bus_watch_name (GBusType bus_type, const gchar* name, GBusNameWatcherFlags flags, + GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, + gpointer user_data, GDestroyNotify user_data_free_func) { + return MOCK_HOOK_P7(GlibMock, g_bus_watch_name, bus_type, name, flags, name_appeared_handler, + name_vanished_handler, user_data, user_data_free_func); +} + +extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3) { + return MOCK_HOOK_P4(GlibMock, g_dbus_message_new_method_call, arg0, arg1, arg2, + arg3); +} diff --git a/tests/mock/glib_mock.hh b/tests/mock/glib_mock.hh new file mode 100644 index 0000000..06331fd --- /dev/null +++ b/tests/mock/glib_mock.hh @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 UNIT_TESTS_MOCK_GLIB_MOCK_H_ +#define UNIT_TESTS_MOCK_GLIB_MOCK_H_ + +#include <gio/gio.h> +#include <glib.h> +#include <gmock/gmock.h> + +#include "module_mock.hh" + +class GlibMock : public virtual ModuleMock { + public: + GlibMock() { + using ::testing::_; + using ::testing::Return; + using ::testing::Invoke; + } + + MOCK_METHOD0(getuid, uid_t()); + MOCK_METHOD1(g_file_new_for_path, GFile* (const char*)); + MOCK_METHOD2(g_file_query_exists, gboolean (GFile*, GCancellable*)); + MOCK_METHOD3(g_file_make_directory, gboolean (GFile*, GCancellable*, GError**)); + + MOCK_METHOD2(access, int (const char*, int)); + MOCK_METHOD3(read, size_t(int , void*, size_t)); + + MOCK_METHOD3(g_bus_get_sync, GDBusConnection*(GBusType, GCancellable*, GError**)); + + MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync, + GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, + gint, volatile guint32*, GCancellable*, GError**)); + + MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*)); + MOCK_METHOD2(g_list_append, GList*(GList*, gpointer)); + MOCK_METHOD10(g_dbus_connection_signal_subscribe, + guint(GDBusConnection*, const gchar*, const gchar*, const gchar*, + const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback, + gpointer, GDestroyNotify)); + MOCK_METHOD7(g_dbus_connection_emit_signal, + gboolean(GDBusConnection*, const gchar*, const gchar*, const gchar*, + const gchar*, GVariant*, GError**)); + MOCK_METHOD3(g_dbus_connection_flush_sync, + gboolean(GDBusConnection*, GCancellable*, GError**)); + MOCK_METHOD1(g_dbus_connection_get_unique_name, const gchar*(GDBusConnection*)); + MOCK_METHOD7(g_bus_watch_name, guint(GBusType, const gchar*, GBusNameWatcherFlags, + GBusNameAppearedCallback, GBusNameVanishedCallback, gpointer, GDestroyNotify)); + MOCK_METHOD4(g_dbus_message_new_method_call, + GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*)); +}; + +#endif // UNIT_TESTS_MOCK_GLIB_MOCK_H_ diff --git a/tests/mock/mock_hook.h b/tests/mock/mock_hook.hh index 29b0932..29b0932 100644 --- a/tests/mock/mock_hook.h +++ b/tests/mock/mock_hook.hh diff --git a/tests/mock/module_mock.h b/tests/mock/module_mock.hh index 9b19d89..9b19d89 100644 --- a/tests/mock/module_mock.h +++ b/tests/mock/module_mock.hh diff --git a/tests/mock/package_manager_mock.cc b/tests/mock/package_manager_mock.cc new file mode 100644 index 0000000..e6e5e98 --- /dev/null +++ b/tests/mock/package_manager_mock.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 "package_manager_mock.hh" + +#include "mock_hook.hh" +#include "test_fixture.hh" + +extern "C" int package_info_create(const char *package, package_info_h *package_info) { + return MOCK_HOOK_P2(PackageManagerMock, package_info_create, package, package_info); +} + +extern "C" int package_info_get_root_path(package_info_h package_info, char **path) { + return MOCK_HOOK_P2(PackageManagerMock, package_info_get_root_path, package_info, path); +} + +extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, + uid_t uid, pkgmgrinfo_appinfo_h *handle) { + return MOCK_HOOK_P3(PackageManagerMock, pkgmgrinfo_appinfo_get_usr_appinfo, appid, uid, handle); +} + +extern "C" int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) { + return MOCK_HOOK_P2(PackageManagerMock, pkgmgrinfo_appinfo_get_label, handle, label); +} diff --git a/tests/mock/package_manager_mock.hh b/tests/mock/package_manager_mock.hh new file mode 100644 index 0000000..8cca951 --- /dev/null +++ b/tests/mock/package_manager_mock.hh @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 UNIT_TESTS_MOCK_PACKAGE_MANAGER_MOCK_H_ +#define UNIT_TESTS_MOCK_PACKAGE_MANAGER_MOCK_H_ + +#include <gmock/gmock.h> +#include <package_manager.h> +#include <pkgmgr-info.h> +#include <pkgmgrinfo_basic.h> + +#include "module_mock.hh" + +class PackageManagerMock : public virtual ModuleMock { + public: + virtual ~PackageManagerMock() {} + + MOCK_METHOD2(package_info_create, int(const char*, package_info_h*)); + MOCK_METHOD2(package_info_get_root_path, int(package_info_h, char**)); + MOCK_METHOD3(pkgmgrinfo_appinfo_get_usr_appinfo, int(const char*, uid_t, pkgmgrinfo_appinfo_h*)); + MOCK_METHOD2(pkgmgrinfo_appinfo_get_label, int(pkgmgrinfo_appinfo_h, char**)); +}; + +#endif // UNIT_TESTS_MOCK_PACKAGE_MANAGER_MOCK_H_ diff --git a/tests/mock/security_manager_mock.cc b/tests/mock/security_manager_mock.cc index 85710d6..67c2dad 100644 --- a/tests/mock/security_manager_mock.cc +++ b/tests/mock/security_manager_mock.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "security_manager_mock.h" +#include "security_manager_mock.hh" -#include "mock_hook.h" -#include "test_fixture.h" +#include "mock_hook.hh" +#include "test_fixture.hh" extern "C" int security_manager_private_sharing_req_new(private_sharing_req** arg1) { return MOCK_HOOK_P1(SecurityManagerMock, security_manager_private_sharing_req_new, arg1); diff --git a/tests/mock/security_manager_mock.h b/tests/mock/security_manager_mock.hh index c5424fd..cc35956 100644 --- a/tests/mock/security_manager_mock.h +++ b/tests/mock/security_manager_mock.hh @@ -20,7 +20,7 @@ #include <security-manager.h> #include <gmock/gmock.h> -#include "module_mock.h" +#include "module_mock.hh" class SecurityManagerMock : public virtual ModuleMock { public: diff --git a/tests/mock/smack_mock.cc b/tests/mock/smack_mock.cc index 4b8388d..28aae23 100644 --- a/tests/mock/smack_mock.cc +++ b/tests/mock/smack_mock.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "smack_mock.h" +#include "smack_mock.hh" -#include "mock_hook.h" -#include "test_fixture.h" +#include "mock_hook.hh" +#include "test_fixture.hh" extern "C" ssize_t smack_new_label_from_path(const char* arg1, const char* arg2, int arg3, char** arg4) { diff --git a/tests/mock/smack_mock.h b/tests/mock/smack_mock.hh index 2517c16..4ebdf44 100644 --- a/tests/mock/smack_mock.h +++ b/tests/mock/smack_mock.hh @@ -20,7 +20,7 @@ #include <gmock/gmock.h> #include <sys/smack.h> -#include "module_mock.h" +#include "module_mock.hh" class SmackMock : public virtual ModuleMock { public: diff --git a/tests/mock/socket_mock.cc b/tests/mock/socket_mock.cc new file mode 100644 index 0000000..ea5c46c --- /dev/null +++ b/tests/mock/socket_mock.cc @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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 "socket_mock.hh" + +#include "mock_hook.hh" +#include "test_fixture.hh" + +extern "C" int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen) { + return MOCK_HOOK_P5(SocketMock, getsockopt, sockfd, level, optname, optval, optlen); +} diff --git a/tests/mock/socket_mock.hh b/tests/mock/socket_mock.hh new file mode 100644 index 0000000..9bbbb40 --- /dev/null +++ b/tests/mock/socket_mock.hh @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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 UNIT_TESTS_MOCK_SOCKET_MOCK_H_ +#define UNIT_TESTS_MOCK_SOCKET_MOCK_H_ + +#include <gmock/gmock.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include "module_mock.hh" + +class SocketMock : public virtual ModuleMock { + public: + virtual ~SocketMock() {} + + MOCK_METHOD5(getsockopt, int(int, int, int, void*, socklen_t*)); +}; + +#endif // UNIT_TESTS_MOCK_SOCKET_MOCK_H_ diff --git a/tests/mock/sqlite_mock.cc b/tests/mock/sqlite_mock.cc new file mode 100644 index 0000000..b031493 --- /dev/null +++ b/tests/mock/sqlite_mock.cc @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 "sqlite_mock.hh" + +#include "mock_hook.hh" +#include "test_fixture.hh" + +typedef int(*execcb)(void*, int, char**, char**); +typedef void(*bindcb)(void*); + +extern "C" int sqlite3_open_v2(const char* arg0, + sqlite3** arg1, int arg2, const char* arg3) { + return MOCK_HOOK_P4(SqliteMock, sqlite3_open_v2, arg0, arg1, arg2, arg3); +} + +extern "C" int sqlite3_close(sqlite3* arg0) { + return MOCK_HOOK_P1(SqliteMock, sqlite3_close, arg0); +} + +extern "C" int sqlite3_changes(sqlite3* arg0) { + return MOCK_HOOK_P1(SqliteMock, sqlite3_changes, arg0); +} + +extern "C" int sqlite3_exec(sqlite3* arg0, const char* arg1, + execcb arg2, void* arg3, char** arg4) { + return MOCK_HOOK_P5(SqliteMock, sqlite3_exec, arg0, arg1, arg2, arg3, arg4); +} + +extern "C" int sqlite3_prepare_v2(sqlite3* arg0, const char* arg1, + int arg2, sqlite3_stmt** arg3, const char** arg4) { + return MOCK_HOOK_P5(SqliteMock, sqlite3_prepare_v2, arg0, arg1, arg2, arg3, arg4); +} + +extern "C" int sqlite3_step(sqlite3_stmt* arg0) { + return MOCK_HOOK_P1(SqliteMock, sqlite3_step, arg0); +} + +extern "C" const unsigned char* sqlite3_column_text(sqlite3_stmt* arg0, int arg1) { + return MOCK_HOOK_P2(SqliteMock, sqlite3_column_text, arg0, arg1); +} + +extern "C" int sqlite3_get_table(sqlite3 *db, const char *zSql, char ***pazResult, + int *pnRow, int *pnColumn, char **pzErrmsg) { + return MOCK_HOOK_P6(SqliteMock, sqlite3_get_table, db, zSql, pazResult, pnRow, pnColumn, pzErrmsg); +} + +extern "C" int sqlite3_bind_int(sqlite3_stmt* arg0, int arg1, int arg2) { + return MOCK_HOOK_P3(SqliteMock, sqlite3_bind_int, arg0, arg1, arg2); +} + +extern "C" int sqlite3_bind_double(sqlite3_stmt* arg0, int arg1, double arg2) { + return MOCK_HOOK_P3(SqliteMock, sqlite3_bind_double, arg0, arg1, arg2); +} + +extern "C" int sqlite3_bind_text(sqlite3_stmt* arg0, int arg1, const char* arg2, int arg3, bindcb arg4) { + return MOCK_HOOK_P5(SqliteMock, sqlite3_bind_text, arg0, arg1, arg2, arg3, arg4); +} + +extern "C" int sqlite3_finalize(sqlite3_stmt* arg0) { + return MOCK_HOOK_P1(SqliteMock, sqlite3_finalize, arg0); +} + +extern "C" void sqlite3_free(void* arg0) { + return MOCK_HOOK_P1(SqliteMock, sqlite3_free, arg0); +} + +extern "C" int sqlite3_column_int(sqlite3_stmt* stmt, int iCol) { + return MOCK_HOOK_P2(SqliteMock, sqlite3_column_int, stmt, iCol); +} + +extern "C" double sqlite3_column_double(sqlite3_stmt* stmt, int iCol) { + return MOCK_HOOK_P2(SqliteMock, sqlite3_column_double, stmt, iCol); +} diff --git a/tests/mock/sqlite_mock.hh b/tests/mock/sqlite_mock.hh new file mode 100644 index 0000000..0c9cfb5 --- /dev/null +++ b/tests/mock/sqlite_mock.hh @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * 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 UNIT_TESTS_MOCK_SQLITE_MOCK_H_ +#define UNIT_TESTS_MOCK_SQLITE_MOCK_H_ + +#include <gmock/gmock.h> +#include <sqlite3.h> + +#include "module_mock.hh" + +class SqliteMock : public virtual ModuleMock { + public: + virtual ~SqliteMock() {} + + MOCK_METHOD1(sqlite3_close, int(sqlite3*)); + MOCK_METHOD1(sqlite3_changes, int(sqlite3*)); + MOCK_METHOD4(sqlite3_open_v2, int(const char*, sqlite3**, int, const char*)); + MOCK_METHOD5(sqlite3_exec, int(sqlite3*, const char*, + int(*)(void*, int, char**, char**), void*, char**)); + MOCK_METHOD5(sqlite3_prepare_v2, int(sqlite3*, const char*, + int, sqlite3_stmt**, const char**)); + MOCK_METHOD1(sqlite3_step, int(sqlite3_stmt*)); + MOCK_METHOD2(sqlite3_column_text, const unsigned char*(sqlite3_stmt*, int)); + MOCK_METHOD6(sqlite3_get_table, int(sqlite3*, const char*, char***, int* , int*, char**)); + MOCK_METHOD3(sqlite3_bind_int, int(sqlite3_stmt*, int, int)); + MOCK_METHOD3(sqlite3_bind_double, int(sqlite3_stmt*, int, double)); + MOCK_METHOD5(sqlite3_bind_text, int(sqlite3_stmt*, int, const char*, int, void(*)(void*))); + MOCK_METHOD1(sqlite3_finalize, int(sqlite3_stmt*)); + MOCK_METHOD1(sqlite3_free, void(void*)); + MOCK_METHOD2(sqlite3_column_int, int(sqlite3_stmt*, int)); + MOCK_METHOD2(sqlite3_column_double, double(sqlite3_stmt*, int)); +}; + +#endif // UNIT_TESTS_MOCK_SQLITE_MOCK_H_ diff --git a/tests/mock/test_fixture.cc b/tests/mock/test_fixture.cc index 27f5666..50f39e9 100644 --- a/tests/mock/test_fixture.cc +++ b/tests/mock/test_fixture.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_fixture.h" +#include "test_fixture.hh" #include <memory> diff --git a/tests/mock/test_fixture.h b/tests/mock/test_fixture.hh index 1ea3b8f..0bf58d1 100644 --- a/tests/mock/test_fixture.h +++ b/tests/mock/test_fixture.hh @@ -24,7 +24,7 @@ #include <string> #include <utility> -#include "module_mock.h" +#include "module_mock.hh" class TestFixture : public ::testing::Test { public: diff --git a/tests/mock/tzplatform_config_mock.cc b/tests/mock/tzplatform_config_mock.cc index e6b3cbd..6094654 100644 --- a/tests/mock/tzplatform_config_mock.cc +++ b/tests/mock/tzplatform_config_mock.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "tzplatform_config_mock.h" +#include "tzplatform_config_mock.hh" -#include "mock_hook.h" -#include "test_fixture.h" +#include "mock_hook.hh" +#include "test_fixture.hh" extern "C" const char* tzplatform_getenv(enum tzplatform_variable arg1) { return MOCK_HOOK_P1(TzplatformConfigMock, tzplatform_getenv, arg1); diff --git a/tests/mock/tzplatform_config_mock.h b/tests/mock/tzplatform_config_mock.hh index b6c75e4..43d1ac1 100644 --- a/tests/mock/tzplatform_config_mock.h +++ b/tests/mock/tzplatform_config_mock.hh @@ -20,7 +20,7 @@ #include <tzplatform_config.h> #include <gmock/gmock.h> -#include "module_mock.h" +#include "module_mock.hh" class TzplatformConfigMock : public virtual ModuleMock { public: diff --git a/tests/unittest/CMakeLists.txt b/tests/noti_ex_unittest/CMakeLists.txt index 58e266b..5ff9faa 100644 --- a/tests/unittest/CMakeLists.txt +++ b/tests/noti_ex_unittest/CMakeLists.txt @@ -1,8 +1,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -PROJECT(notification-ex_unittests CXX) +PROJECT(notification-ex-unittests CXX) INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(notification-ex_unittests REQUIRED +PKG_CHECK_MODULES(notification-ex-unittests REQUIRED dlog gmock capi-appfw-app-control @@ -14,7 +14,7 @@ PKG_CHECK_MODULES(notification-ex_unittests REQUIRED libtzplatform-config ) -FOREACH(flag ${notification-ex_unittests_CFLAGS}) +FOREACH(flag ${notification-ex-unittests_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall") @@ -40,7 +40,7 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${MOCK_SOURCES} ) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${notification-ex_unittests_LDFLAGS} +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${notification-ex-unittests_LDFLAGS} ${pkgs_LDFLAGS} ${pkgs_LIBRARIES} gmock diff --git a/tests/unittest/src/test_main.cc b/tests/noti_ex_unittest/src/test_main.cc index ad7ec6c..ad7ec6c 100644 --- a/tests/unittest/src/test_main.cc +++ b/tests/noti_ex_unittest/src/test_main.cc diff --git a/tests/unittest/src/test_noti_ex_abstract_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_abstract_item.cc index e9d8459..3d1549a 100644 --- a/tests/unittest/src/test_noti_ex_abstract_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_abstract_item.cc @@ -28,9 +28,10 @@ #include "notification-ex/group_item.h" #include "notification-ex/button_item.h" -#include "mock/test_fixture.h" -#include "mock/smack_mock.h" -#include "mock/app_common_mock.h" +#include "mock/test_fixture.hh" +#include "mock/smack_mock.hh" +#include "mock/app_common_mock.hh" +#include "mock/aul_mock.hh" #define MY_ITEM_TYPE AbstractItem::Type::Custom + 1 @@ -87,6 +88,7 @@ class MyFactory : public IItemFactory { }; class Mocks : + virtual public ::testing::NiceMock<AulMock>, virtual public ::testing::NiceMock<SmackMock>, virtual public ::testing::NiceMock<AppCommonMock> {}; } // namespace diff --git a/tests/unittest/src/test_noti_ex_app_control_action.cc b/tests/noti_ex_unittest/src/test_noti_ex_app_control_action.cc index 1bdd3c4..70f53e1 100644 --- a/tests/unittest/src/test_noti_ex_app_control_action.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_app_control_action.cc @@ -17,8 +17,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/app_control_action.h" #include "notification-ex/action_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_button_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_button_item.cc index edc1560..5ef0c11 100644 --- a/tests/unittest/src/test_noti_ex_button_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_button_item.cc @@ -16,8 +16,8 @@ #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/button_item.h" #include "notification-ex/item_inflator.h" @@ -64,3 +64,19 @@ TEST_F(ButtonItemTest, SerializeDeserializeGetTitle) { auto gen_btn = std::static_pointer_cast<ButtonItem>(gen_item); ASSERT_EQ(item.GetTitle(), gen_btn->GetTitle()); } + +TEST_F(ButtonItemTest, GetSetPath) { + ButtonItem item("btn_id", "title"); + + item.SetImgPath("testpath"); + std::string path = item.GetImgPath(); + ASSERT_STREQ(path.c_str(), "testpath"); +} + +TEST_F(ButtonItemTest, GetSeContent) { + ButtonItem item("btn_id", "title"); + + item.SetContents("testcontents"); + std::string content = item.GetContents(); + ASSERT_STREQ(content.c_str(), "testcontents"); +} diff --git a/tests/unittest/src/test_noti_ex_chat_message_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_chat_message_item.cc index e5b8772..aa0f9fb 100644 --- a/tests/unittest/src/test_noti_ex_chat_message_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_chat_message_item.cc @@ -17,9 +17,9 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/smack_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/smack_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/chat_message_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_checkbox_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_checkbox_item.cc index a2f2a6a..e27f192 100644 --- a/tests/unittest/src/test_noti_ex_checkbox_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_checkbox_item.cc @@ -17,8 +17,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/checkbox_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_entry_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_entry_item.cc index 869e25a..6234c44 100644 --- a/tests/unittest/src/test_noti_ex_entry_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_entry_item.cc @@ -17,8 +17,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/entry_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_event_info.cc b/tests/noti_ex_unittest/src/test_noti_ex_event_info.cc index c480953..d117d19 100644 --- a/tests/unittest/src/test_noti_ex_event_info.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_event_info.cc @@ -16,8 +16,8 @@ #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/event_info_internal.h" using namespace tizen_base; @@ -54,3 +54,38 @@ TEST_F(EventInfoTest, GetString) { ASSERT_EQ(EventInfo::GetString(EventInfo::Delete), "Delete"); ASSERT_EQ(EventInfo::GetString(EventInfo::Get), "Get"); } + +TEST_F(EventInfoTest, GetSetEventType) { + EventInfo info(EventInfo::Get, "test", "channel", "id"); + info.SetEventType(EventInfo::Post); + int type = info.GetEventType(); + EXPECT_EQ(type, EventInfo::Post); +} + +TEST_F(EventInfoTest, GetSetValidOwner) { + EventInfo info(EventInfo::Get, "test", "channel", "id"); + info.SetValidatedOwner("testowner"); + std::string owner = info.GetValidatedOwner(); + EXPECT_STREQ(owner.c_str(), "testowner"); +} + +TEST_F(EventInfoTest, GetSetUid) { + EventInfo info(EventInfo::Get, "test", "channel", "id"); + info.SetUid(5001); + uid_t my_uid = info.GetUid(); + EXPECT_EQ(my_uid, 5001); +} + +TEST_F(EventInfoTest, GetSetValidUid) { + EventInfo info(EventInfo::Get, "test", "channel", "id"); + info.SetValidatedUid(5001); + uid_t my_uid = info.GetValidatedUid(); + EXPECT_EQ(my_uid, 5001); +} + +TEST_F(EventInfoTest, GetSetError) { + EventInfo info(EventInfo::Get, "test", "channel", "id"); + info.SetError(NotificationError::ERROR_NONE); + NotificationError err = info.GetError(); + EXPECT_EQ(err, NotificationError::ERROR_NONE); +} diff --git a/tests/unittest/src/test_noti_ex_group_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_group_item.cc index 5a1dc89..e00ae1f 100644 --- a/tests/unittest/src/test_noti_ex_group_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_group_item.cc @@ -20,8 +20,8 @@ #include "notification-ex/button_item.h" #include "notification-ex/text_item.h" #include "notification-ex/item_inflator.h" -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" using namespace tizen_base; using namespace notification; diff --git a/tests/unittest/src/test_noti_ex_icon_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_icon_item.cc index 5925d3c..0ca4010 100644 --- a/tests/unittest/src/test_noti_ex_icon_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_icon_item.cc @@ -17,9 +17,9 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/smack_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/smack_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/icon_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_image_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_image_item.cc index 63968cb..0aeb77e 100644 --- a/tests/unittest/src/test_noti_ex_image_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_image_item.cc @@ -17,9 +17,9 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/smack_mock.h" -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/smack_mock.hh" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/image_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_input_selector_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_input_selector_item.cc index 2e13a6e..e8b2669 100644 --- a/tests/unittest/src/test_noti_ex_input_selector_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_input_selector_item.cc @@ -16,8 +16,8 @@ #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/input_selector_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_progress_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_progress_item.cc index 348e0c5..0328ef3 100644 --- a/tests/unittest/src/test_noti_ex_progress_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_progress_item.cc @@ -16,8 +16,8 @@ #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/progress_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_shared_file.cc b/tests/noti_ex_unittest/src/test_noti_ex_shared_file.cc index 2b58335..2fe9684 100644 --- a/tests/unittest/src/test_noti_ex_shared_file.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_shared_file.cc @@ -17,16 +17,17 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/shared_file.h" #include "notification-ex/image_item.h" #include "notification-ex/common.h" -#include "mock/glib_mock.h" -#include "mock/smack_mock.h" -#include "mock/tzplatform_config_mock.h" -#include "mock/security_manager_mock.h" +#include "mock/glib_mock.hh" +#include "mock/smack_mock.hh" +#include "mock/tzplatform_config_mock.hh" +#include "mock/security_manager_mock.hh" +#include "mock/aul_mock.hh" using namespace notification; @@ -92,6 +93,7 @@ class SharedFileTest : public TestFixture { virtual void SetUp() { item = make_shared<ImageItem>(id, image_path); shared_file = new SharedFile(); + item->SetSenderAppId("notification-ex-unittests"); } virtual void TearDown() { @@ -110,7 +112,7 @@ TEST_F(SharedFileTest, GetDataPath) { .WillRepeatedly(Invoke(__fake_tzplatform_getenv)); ASSERT_EQ(shared_file->GetDataPath(item->GetSenderAppId(), SharedFileTest::image_path), - "/opt/usr/home/owner/apps_rw/notification-ex_unittests/data/.notification_ex/image.png"); + "/opt/usr/home/owner/apps_rw/notification-ex-unittests/data/.notification_ex/image.png"); } TEST_F(SharedFileTest, SetPrivateSharing) { diff --git a/tests/unittest/src/test_noti_ex_text_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_text_item.cc index 7f5c318..744a230 100644 --- a/tests/unittest/src/test_noti_ex_text_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_text_item.cc @@ -17,8 +17,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/text_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_time_item.cc b/tests/noti_ex_unittest/src/test_noti_ex_time_item.cc index 1e5c29b..94edabe 100644 --- a/tests/unittest/src/test_noti_ex_time_item.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_time_item.cc @@ -17,8 +17,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/time_item.h" #include "notification-ex/item_inflator.h" diff --git a/tests/unittest/src/test_noti_ex_visibility_action.cc b/tests/noti_ex_unittest/src/test_noti_ex_visibility_action.cc index 258d8e5..d56e26d 100644 --- a/tests/unittest/src/test_noti_ex_visibility_action.cc +++ b/tests/noti_ex_unittest/src/test_noti_ex_visibility_action.cc @@ -19,8 +19,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "mock/app_common_mock.h" -#include "mock/test_fixture.h" +#include "mock/app_common_mock.hh" +#include "mock/test_fixture.hh" #include "notification-ex/visibility_action.h" #include "notification-ex/action_inflator.h" diff --git a/tests/noti_unittest/CMakeLists.txt b/tests/noti_unittest/CMakeLists.txt new file mode 100644 index 0000000..79b786f --- /dev/null +++ b/tests/noti_unittest/CMakeLists.txt @@ -0,0 +1,57 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(notification-unittests C CXX) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(notification-unittests REQUIRED + dlog + dbus-1 + gmock + capi-appfw-app-control + glib-2.0 + gio-2.0 + gio-unix-2.0 + aul + security-manager + libtzplatform-config +) + +FOREACH(flag ${notification-unittests_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + + +SET(INIT-SRCS ${CMAKE_SOURCE_DIR}/notification/src/notification_init.c) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/notification/src) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/notification/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock) + + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/notification/src NOTIFICATION_SOURCES) + +LIST(REMOVE_ITEM NOTIFICATION_SOURCES ${INIT-SRCS}) + +ADD_EXECUTABLE(${PROJECT_NAME} + ${SOURCES} + ${NOTIFICATION_SOURCES} + ${MOCK_SOURCES} +) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${notification-unittests_LDFLAGS} + ${pkgs_LDFLAGS} + ${pkgs_LIBRARIES} + gmock + notification +) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/tests/noti_unittest/src/test_main.cc b/tests/noti_unittest/src/test_main.cc new file mode 100644 index 0000000..ad7ec6c --- /dev/null +++ b/tests/noti_unittest/src/test_main.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +int main(int argc, char** argv) { + int ret = -1; + + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + } + + return ret; +} diff --git a/tests/noti_unittest/src/test_notification.cc b/tests/noti_unittest/src/test_notification.cc new file mode 100644 index 0000000..8058cfd --- /dev/null +++ b/tests/noti_unittest/src/test_notification.cc @@ -0,0 +1,403 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +#include "mock/test_fixture.hh" +#include "mock/aul_mock.hh" +#include "mock/package_manager_mock.hh" +#include "mock/smack_mock.hh" +#include "mock/tzplatform_config_mock.hh" +#include "mock/glib_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_ipc.h" + +namespace { + +typedef struct { + const char *package; + char *locale; + pkgmgrinfo_app_component app_component; + application_x *app_info; +} pkgmgr_appinfo_x; + +typedef void *pkgmgrinfo_pkginfo_h; + +struct package_info_s { + char *package; + pkgmgrinfo_pkginfo_h pkgmgr_pkginfo; +}; + +GVariant *noti_body = nullptr; +notification_h cloned_noti = nullptr; + +int __fake_aul_app_get_appid_bypid(int pid, char* appid, int len) { + snprintf(appid, len, "%s", "org.tizen.testappid"); + return AUL_R_OK; +} + +int __fake_aul_app_get_pkgid_bypid(int pid, char* pkgid, int len) { + snprintf(pkgid, len, "%s", "org.tizen.testpkgid"); + return AUL_R_OK; +} + +int __fake_package_info_create(const char* package, package_info_h* package_info) { + *package_info = (package_info_h)calloc(1, sizeof(struct package_info_s)); + + return PACKAGE_MANAGER_ERROR_NONE; +} + +int __fake_package_info_get_root_path(package_info_h package_info, char** path) { + *path = strdup("testrootpath"); + + return PACKAGE_MANAGER_ERROR_NONE; +} + +int __fake_pkgmgrinfo_appinfo_get_usr_appinfo(const char* appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) { + *handle = (pkgmgrinfo_appinfo_h*)calloc(1, sizeof(pkgmgr_appinfo_x)); + + return PMINFO_R_OK; +} + +int __fake_pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char** label) { + *label = strdup("testlabel"); + + return PMINFO_R_OK; +} + +ssize_t __fake_smack_new_label_from_path(const char* path, const char* xattr, + int follow, char** label) { + *label = strdup("User::Pkg::unittest::RO"); + return 1; +} + +const char* __fake_tzplatform_getenv(tzplatform_variable id) { + return "/opt/usr/home/owner/apps_rw"; +} + +GDBusConnection* __fake_g_bus_get_sync(GBusType type, GCancellable* cancellable, GError** error) { + GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(calloc(1, 4)); + + return conn; +} + +GDBusMessage* __fake_g_dbus_connection_send_message_with_reply_sync( + GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, + gint timeout, volatile guint32* out_serial, GCancellable* cancellable, + GError** error) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +GVariant* __fake_g_dbus_message_get_body(GDBusMessage* arg0) { + GVariant* ret_body = g_variant_new("(v)", noti_body); + + return ret_body; +} + +GDBusMessage* __fake_g_dbus_message_new_method_call(const gchar* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +class Mocks : + virtual public ::testing::NiceMock<AulMock>, + virtual public ::testing::NiceMock<SmackMock>, + virtual public ::testing::NiceMock<TzplatformConfigMock>, + virtual public ::testing::NiceMock<GlibMock>, + virtual public ::testing::NiceMock<PackageManagerMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; + +class NotificationTest : public TestFixture { + public: + NotificationTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(NotificationTest, notification_test) { + EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _)) + .WillRepeatedly(Invoke(__fake_aul_app_get_appid_bypid)); + + EXPECT_CALL(GetMock<AulMock>(), aul_app_get_pkgid_bypid(_, _, _)) + .WillOnce(Invoke(__fake_aul_app_get_pkgid_bypid)); + + EXPECT_CALL(GetMock<PackageManagerMock>(), package_info_create(_, _)) + .WillOnce(Invoke(__fake_package_info_create)); + + EXPECT_CALL(GetMock<PackageManagerMock>(), package_info_get_root_path(_, _)) + .WillOnce(Invoke(__fake_package_info_get_root_path)); + + EXPECT_CALL(GetMock<PackageManagerMock>(), pkgmgrinfo_appinfo_get_usr_appinfo(_, _, _)) + .WillOnce(Invoke(__fake_pkgmgrinfo_appinfo_get_usr_appinfo)); + + EXPECT_CALL(GetMock<PackageManagerMock>(), pkgmgrinfo_appinfo_get_label(_, _)) + .WillOnce(Invoke(__fake_pkgmgrinfo_appinfo_get_label)); + + EXPECT_CALL(GetMock<SmackMock>(), smack_new_label_from_path(_, _, _, _)) + .WillOnce(Invoke(__fake_smack_new_label_from_path)); + + EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_getenv(_)) + .WillOnce(Invoke(__fake_tzplatform_getenv)); + + EXPECT_CALL(GetMock<GlibMock>(), g_bus_get_sync(_, _, _)) + .WillRepeatedly(Invoke(__fake_g_bus_get_sync)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_message_new_method_call(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_g_dbus_message_new_method_call)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_g_dbus_connection_send_message_with_reply_sync)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_message_get_body(_)) + .WillRepeatedly(Invoke(__fake_g_dbus_message_get_body)); + + notification_h noti = nullptr; + int ret; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + EXPECT_NE(noti, nullptr); + + ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + "/opt/usr/home/owner/apps_rw/org.tizen.testpkgid/data/.notification/image.png"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + char* image_path = NULL; + ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + ASSERT_STREQ(image_path, "/opt/usr/home/owner/apps_rw/org.tizen.testpkgid/data/.notification/image.png"); + + ret = notification_set_time(noti, 0xFFFFFFF); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + time_t ret_time = 0; + + ret = notification_get_time(noti, &ret_time); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + EXPECT_NE(ret_time, 0); + + ret_time = 0; + + ret = notification_get_insert_time(noti, &ret_time); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "testtitle", NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + char* title_text = nullptr; + ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &title_text); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + ASSERT_STREQ(title_text, "testtitle"); + + ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "%f %d %s %d", NULL, + NOTIFICATION_VARIABLE_TYPE_COUNT, NOTIFICATION_COUNT_POS_LEFT, + NOTIFICATION_VARIABLE_TYPE_DOUBLE, 0.0, + NOTIFICATION_VARIABLE_TYPE_COUNT, NOTIFICATION_COUNT_POS_IN, + NOTIFICATION_VARIABLE_TYPE_STRING, "Content", + NOTIFICATION_VARIABLE_TYPE_INT, 0, + NOTIFICATION_VARIABLE_TYPE_COUNT, NOTIFICATION_COUNT_POS_RIGHT, + NOTIFICATION_VARIABLE_TYPE_NONE); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + char* content_text = nullptr; + ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &content_text); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + EXPECT_NE(content_text, nullptr); + + ret = notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, time(NULL)); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret_time = 0; + ret = notification_get_time_from_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &ret_time); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, "soundpath"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_sound_type_e sound_type = NOTIFICATION_SOUND_TYPE_NONE; + const char* sound_path = nullptr; + ret = notification_get_sound(noti, &sound_type, &sound_path); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_vibration(noti, NOTIFICATION_VIBRATION_TYPE_DEFAULT, "vibpath"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE; + const char* vib_path = nullptr; + ret = notification_get_vibration(noti, &vib_type, &vib_path); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_led(noti, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, 256); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_led_op_e op = NOTIFICATION_LED_OP_OFF; + int led_argb = 0; + ret = notification_get_led(noti, &op, &led_argb); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_led_time_period(noti, 100, 200); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + int on_ms = 0; + int off_ms = 0; + ret = notification_get_led_time_period(noti, &on_ms, &off_ms); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + app_control_h app_control; + app_control_create(&app_control); + app_control_set_app_id(app_control, "org.tizen.testapp"); + ret = notification_set_launch_option(noti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, app_control); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + app_control_destroy(app_control); + + ret = notification_get_launch_option(noti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&app_control); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + app_control_destroy(app_control); + + app_control_create(&app_control); + app_control_set_app_id(app_control, "org.tizen.testapp"); + ret = notification_set_event_handler(noti, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + app_control_destroy(app_control); + + ret = notification_get_event_handler(noti, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, &app_control); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + app_control_destroy(app_control); + + ret = notification_set_property(noti, NOTIFICATION_PROP_PERMANENT_DISPLAY); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + int property; + ret = notification_get_property(noti, &property); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + int ret_applist; + ret = notification_get_display_applist(noti, &ret_applist); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_size(noti, 3.3); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + double ret_size; + ret = notification_get_size(noti, &ret_size); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_progress(noti, 30.); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + double percentage; + ret = notification_get_progress(noti, &percentage); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_ly_type_e ret_layout; + ret = notification_get_layout(noti, &ret_layout); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_type_e ret_type; + ret = notification_get_type(noti, &ret_type); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_tag(noti, "test_tag"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + const char* ret_tag; + ret = notification_get_tag(noti, &ret_tag); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + char* pkgname; + ret = notification_get_pkgname(noti, &pkgname); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_add_button(noti, NOTIFICATION_BUTTON_1); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_remove_button(noti, NOTIFICATION_BUTTON_1); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_auto_remove(noti, true); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + bool auto_remove; + ret = notification_get_auto_remove(noti, &auto_remove); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_text_input(noti, 1000); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_set_extension_image_size(noti, 20); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + int ret_height; + ret = notification_get_extension_image_size(noti, &ret_height); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_clone(noti, &cloned_noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_free(cloned_noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + noti_body = notification_ipc_make_gvariant_from_noti(noti, false); + + notification_block_state_e ret_state; + ret = notification_get_noti_block_state(&ret_state); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_save_as_template(noti, "test_template"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_h template_noti = nullptr; + template_noti = notification_create_from_template("test_template"); + EXPECT_NE(template_noti, nullptr); + + ret = notification_update(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_post(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_h tag_noti; + tag_noti = notification_load_by_tag("test_tag"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + EXPECT_NE(tag_noti, nullptr); + + ret = notification_delete(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_delete_all(NOTIFICATION_TYPE_NOTI); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} diff --git a/tests/noti_unittest/src/test_notification_db.cc b/tests/noti_unittest/src/test_notification_db.cc new file mode 100644 index 0000000..c1bd7c2 --- /dev/null +++ b/tests/noti_unittest/src/test_notification_db.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> +#include <bundle.h> + +#include "mock/test_fixture.hh" +#include "mock/glib_mock.hh" +#include "mock/sqlite_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_db.h" + +namespace { + +int __fake_sqlite3_open_v2(const char* arg0, sqlite3** arg1, int arg2, const char* arg3) { + char** table = (char** )calloc(10, sizeof(char*)); + *arg1 = (sqlite3*) table; + + return SQLITE_OK; +} + +const unsigned char* __fake_sqlite3_column_text(sqlite3_stmt* arg0, int arg1) { + const unsigned char* column_text = (const unsigned char*)strdup("testcolumn"); + + return column_text; +} + +const unsigned char* __fake_sqlite3_column_text_bundle(sqlite3_stmt* arg0, int arg1) { + bundle_raw *raw = nullptr; + int len = 0; + bundle* b = bundle_create(); + bundle_add_str(b, "testkey", "testval"); + bundle_encode(b, &raw, &len); + + const unsigned char* column_text = (const unsigned char*)raw; + + return column_text; +} + +class Mocks : + virtual public ::testing::NiceMock<GlibMock>, + virtual public ::testing::NiceMock<SqliteMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +class NotificationDBTest : public TestFixture { + public: + NotificationDBTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(NotificationDBTest, notification_db_test) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_close(_)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_changes(_)) + .WillOnce(Return(3)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_text(_, _)) + .WillOnce(Invoke(__fake_sqlite3_column_text)) + .WillOnce(Invoke(__fake_sqlite3_column_text_bundle)); + + EXPECT_CALL(GetMock<GlibMock>(), access(_, _)) + .WillOnce(Return(0)); + + int ret; + + sqlite3* db = nullptr; + db = notification_db_open(); + EXPECT_NE(db, nullptr); + + int num_changed = 0; + ret = notification_db_exec(db, "test query", &num_changed); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + EXPECT_EQ(num_changed, 3); + + char* column_text = nullptr; + sqlite3_stmt *stmt; + column_text = notification_db_column_text(stmt, 3); + EXPECT_STREQ(column_text, "testcolumn"); + + bundle* column_b = nullptr; + column_b = notification_db_column_bundle(stmt, 3); + EXPECT_NE(column_b, nullptr); + + ret = notification_db_close(&db); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} diff --git a/tests/noti_unittest/src/test_notification_list.cc b/tests/noti_unittest/src/test_notification_list.cc new file mode 100644 index 0000000..4896900 --- /dev/null +++ b/tests/noti_unittest/src/test_notification_list.cc @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +#include <sys/types.h> + +#include "mock/test_fixture.hh" +#include "mock/glib_mock.hh" +#include "mock/aul_mock.hh" +#include "mock/package_manager_mock.hh" +#include "mock/socket_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_list.h" + +namespace { + +typedef struct { + const char *package; + char *locale; + pkgmgrinfo_app_component app_component; + application_x *app_info; +} pkgmgr_appinfo_x; + +int __fake_aul_app_get_appid_bypid(int pid, char* appid, int len) { + snprintf(appid, len, "%s", "org.tizen.testappid"); + return AUL_R_OK; +} + +GDBusConnection* __fake_g_bus_get_sync(GBusType type, GCancellable* cancellable, GError** error) { + GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(calloc(1, 4)); + + return conn; +} + +GDBusMessage* __fake_g_dbus_connection_send_message_with_reply_sync( + GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, + gint timeout, volatile guint32* out_serial, GCancellable* cancellable, + GError** error) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +GVariant* __fake_g_dbus_message_get_body(GDBusMessage* arg0) { + GVariant* ret_body = g_variant_new("(i)", 1); + + return ret_body; +} + +GDBusMessage* __fake_g_dbus_message_new_method_call(const gchar* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +class Mocks : + virtual public ::testing::NiceMock<AulMock>, + virtual public ::testing::NiceMock<PackageManagerMock>, + virtual public ::testing::NiceMock<SocketMock>, + virtual public ::testing::NiceMock<GlibMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +class NotificationListTest : public TestFixture { + public: + NotificationListTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(NotificationListTest, notification_list_test) { + EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _)) + .WillRepeatedly(Invoke(__fake_aul_app_get_appid_bypid)); + + EXPECT_CALL(GetMock<GlibMock>(), g_bus_get_sync(_, _, _)) + .WillRepeatedly(Invoke(__fake_g_bus_get_sync)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_g_dbus_connection_send_message_with_reply_sync)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_message_get_body(_)) + .WillRepeatedly(Invoke(__fake_g_dbus_message_get_body)); + + EXPECT_CALL(GetMock<GlibMock>(), read(_, _, _)) + .WillRepeatedly(Return(1)); + + EXPECT_CALL(GetMock<SocketMock>(), getsockopt(_, _, _, _, _)) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_message_new_method_call(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_g_dbus_message_new_method_call)); + + int ret; + notification_list_h noti_list = nullptr; + notification_h noti = nullptr; + notification_h noti2 = nullptr; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + EXPECT_NE(noti, nullptr); + + noti2 = notification_create(NOTIFICATION_TYPE_NOTI); + EXPECT_NE(noti2, nullptr); + + noti_list = notification_list_append(noti_list, noti); + EXPECT_NE(noti_list, nullptr); + + noti_list = notification_list_append(noti_list, noti2); + EXPECT_NE(noti_list, nullptr); + + notification_list_h get_list = nullptr; + ret = notification_get_list(NOTIFICATION_TYPE_NOTI, 3, &get_list); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_list_h get_list_page = nullptr; + ret = notification_get_list_by_page(NOTIFICATION_TYPE_NOTI, 1, 3, &get_list_page); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + notification_list_h list_head = nullptr; + list_head = notification_list_get_head(nullptr); + EXPECT_EQ(list_head, nullptr); + + list_head = notification_list_get_head(noti_list); + EXPECT_NE(list_head, nullptr); + + notification_list_h list_tail = nullptr; + list_tail = notification_list_get_tail(nullptr); + EXPECT_EQ(list_tail, nullptr); + + list_tail = notification_list_get_tail(noti_list); + EXPECT_NE(list_tail, nullptr); + + notification_list_h list_prev = nullptr; + list_prev = notification_list_get_prev(nullptr); + EXPECT_EQ(list_prev, nullptr); + + list_prev = notification_list_get_prev(noti_list); + EXPECT_NE(list_prev, nullptr); + + notification_list_h list_next = nullptr; + list_next = notification_list_get_next(nullptr); + EXPECT_EQ(list_next, nullptr); + + list_next = notification_list_get_next(noti_list); + EXPECT_NE(list_prev, nullptr); + + notification_h noti_data = nullptr; + noti_data = notification_list_get_data(nullptr); + EXPECT_EQ(noti_data, nullptr); + + noti_data = notification_list_get_data(noti_list); + EXPECT_NE(noti_data, nullptr); + + int cnt = 0; + cnt = notification_list_get_count(nullptr); + EXPECT_EQ(cnt, 0); + + cnt = notification_list_get_count(noti_list); + ASSERT_EQ(cnt, 2); + + noti_list = notification_list_remove(noti_list, noti2); + EXPECT_NE(noti_list, nullptr); + + ret = notification_free_list(noti_list); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationListTest, notification_list_test2) { + int ret; + + notification_list_h get_list_detail = nullptr; + ret = notification_get_detail_list("org.tizen.testappid", 1, 1, 1, &get_list_detail); +} diff --git a/tests/noti_unittest/src/test_notification_noti.cc b/tests/noti_unittest/src/test_notification_noti.cc new file mode 100644 index 0000000..d9ca168 --- /dev/null +++ b/tests/noti_unittest/src/test_notification_noti.cc @@ -0,0 +1,379 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +#include "mock/test_fixture.hh" +#include "mock/aul_mock.hh" +#include "mock/package_manager_mock.hh" +#include "mock/glib_mock.hh" +#include "mock/sqlite_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_noti.h" + +namespace { + +notification_h noti = nullptr; + +typedef struct { + const char *package; + char *locale; + pkgmgrinfo_app_component app_component; + application_x *app_info; +} pkgmgr_appinfo_x; + +int __fake_aul_app_get_appid_bypid(int pid, char* appid, int len) { + snprintf(appid, len, "%s", "org.tizen.testappid"); + return AUL_R_OK; +} + +int __fake_sqlite3_open_v2(const char* arg0, sqlite3** arg1, int arg2, const char* arg3) { + char** table = (char** )calloc(10, sizeof(char*)); + *arg1 = (sqlite3*) table; + + return SQLITE_OK; +} + +int __fake_sqlite3_prepare_v2(sqlite3* arg0, const char* arg1, + int arg2, sqlite3_stmt** arg3, const char** arg4) { + sqlite3_stmt* stmt = (sqlite3_stmt*)malloc(sizeof(sqlite3_stmt*)); + *arg3 = stmt; + + return SQLITE_OK; +}; + +extern "C" char* sqlite3_mprintf(const char*,...) { + return (char*)strdup("test_query"); +} + +class Mocks : + virtual public ::testing::NiceMock<AulMock>, + virtual public ::testing::NiceMock<GlibMock>, + virtual public ::testing::NiceMock<SqliteMock>, + virtual public ::testing::NiceMock<PackageManagerMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +class NotificationNotiTest : public TestFixture { + public: + NotificationNotiTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(NotificationNotiTest, notification_noti_test) { + EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _)) + .WillRepeatedly(Invoke(__fake_aul_app_get_appid_bypid)); + + EXPECT_CALL(GetMock<GlibMock>(), access(_, _)) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_get_table(_, _, _, _, _, _)) + .WillRepeatedly(Return(1)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_bind_int(_, _, _)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_bind_double(_, _, _)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_bind_text(_, _, _, _, _)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)) + .WillOnce(Return(SQLITE_ROW)) + .WillOnce(Return(SQLITE_OK)) + .WillOnce(Return(SQLITE_ROW)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_finalize(_)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_free(_)) + .WillRepeatedly(Return()); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_int(_, _)) + .WillRepeatedly(Return(1)); + + int ret; + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + EXPECT_NE(noti, nullptr); + + ret = notification_noti_insert(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_noti_update(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + int deleted_num; + int* deleted_list; + ret = notification_noti_delete_all(NOTIFICATION_TYPE_NOTI, "org.tizen.testappid", + &deleted_num, &deleted_list, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test2) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_ROW)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_finalize(_)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_free(_)) + .WillRepeatedly(Return()); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_int(_, _)) + .WillRepeatedly(Return(1)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_double(_, _)) + .WillRepeatedly(Return(1.0)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_text(_, _)) + .WillRepeatedly(Return(nullptr)); + + int ret; + ret = notification_noti_get_by_tag(noti, "org.tizen.testappid", "test_tag", 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test3) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_finalize(_)) + .WillOnce(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_free(_)) + .WillOnce(Return()); + + int ret; + + int num_changes; + ret = notification_noti_delete_by_priv_id_get_changes("org.tizen.testappid", 1, &num_changes, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + + +TEST_F(NotificationNotiTest, notification_noti_test4) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_ROW)) + .WillOnce(Return(SQLITE_ROW)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_finalize(_)) + .WillRepeatedly(Return(SQLITE_OK)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_free(_)) + .WillRepeatedly(Return()); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_int(_, _)) + .WillRepeatedly(Return(1)); + + int ret; + + int deleted_num; + notification_deleted_list_info_s *deleted_list; + ret = notification_noti_delete_by_display_applist(NOTIFICATION_DISPLAY_APP_INDICATOR, + &deleted_num, &deleted_list, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test5) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_ROW)); + + int ret; + int count; + ret = notification_noti_get_all_count(NOTIFICATION_TYPE_NOTI, &count, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test6) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_ROW)); + + int ret; + int count; + notification_list_h group_list; + int list_count; + ret = notification_noti_get_grouping_list(NOTIFICATION_TYPE_NOTI, 1,1, &group_list, &list_count, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test7) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillRepeatedly(Return(SQLITE_ROW)); + + int ret; + notification_list_h detail_list; + ret = notification_noti_get_detail_list("org.tizen.testappid", 1, 1, 1, &detail_list, 5001); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test8) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillRepeatedly(Return(SQLITE_ROW)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_int(_, _)) + .WillRepeatedly(Return(1)); + + int ret; + ret = notification_set_tag(noti, "test_tag"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_noti_check_tag(noti); + ASSERT_EQ(ret, NOTIFICATION_ERROR_ALREADY_EXIST_ID); +} + +TEST_F(NotificationNotiTest, notification_noti_test9) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)); + + int ret; + int count; + ret = notification_noti_check_count_for_template(noti, &count); + ASSERT_EQ(ret, 0); +} + +TEST_F(NotificationNotiTest, notification_noti_test10) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)); + + int ret; + ret = notification_noti_add_template(noti, "test_template"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test11) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_ROW)); + + int ret; + ret = notification_noti_get_package_template(noti, "org.tizen.testappid", "test_template"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test12) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillOnce(Return(SQLITE_OK)); + + int ret; + ret = notification_noti_delete_template("org.tizen.testpkgid"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} + +TEST_F(NotificationNotiTest, notification_noti_test13) { + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_open_v2(_, _, _, _)) + .WillOnce(Invoke(__fake_sqlite3_open_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_prepare_v2(_, _, _, _, _)) + .WillRepeatedly(Invoke(__fake_sqlite3_prepare_v2)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_step(_)) + .WillRepeatedly(Return(SQLITE_ROW)); + + EXPECT_CALL(GetMock<SqliteMock>(), sqlite3_column_int(_, _)) + .WillRepeatedly(Return(101)); + + EXPECT_CALL(GetMock<GlibMock>(), g_list_append(_, _)) + .WillOnce(Return(nullptr)); + + int ret; + GList* list; + ret = notification_noti_check_limit(noti, 5001, &list); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} diff --git a/tests/noti_unittest/src/test_notification_ongoing.cc b/tests/noti_unittest/src/test_notification_ongoing.cc new file mode 100644 index 0000000..c29db7a --- /dev/null +++ b/tests/noti_unittest/src/test_notification_ongoing.cc @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +#include "mock/test_fixture.hh" +#include "mock/glib_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_ongoing.h" + +namespace { + +GDBusConnection* __fake_g_bus_get_sync(GBusType type, GCancellable* cancellable, GError** error) { + GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(calloc(1, 4)); + + return conn; +} + +guint __fake_g_dbus_connection_signal_subscribe(GDBusConnection* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, + const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7, + gpointer arg8, GDestroyNotify arg9) { + arg7(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); + + return 1; +} + +class Mocks : + virtual public ::testing::NiceMock<GlibMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +class NotificationOngoingTest : public TestFixture { + public: + NotificationOngoingTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +void __notification_ongoing_update_cb(struct ongoing_info_s *info, void *data) { +} + +TEST_F(NotificationOngoingTest, notification_ongoing_test) { + EXPECT_CALL(GetMock<GlibMock>(), g_bus_get_sync(_, _, _)) + .WillRepeatedly(Invoke(__fake_g_bus_get_sync)); + + EXPECT_CALL(GetMock<GlibMock>(), + g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)) + .WillOnce(Invoke(__fake_g_dbus_connection_signal_subscribe)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_connection_emit_signal(_, _, _, _, _, _, _)) + .WillRepeatedly(Return(true)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_connection_flush_sync(_, _, _)) + .WillRepeatedly(Return(true)); + + int ret; + + ret = notification_ongoing_update_cb_set(__notification_ongoing_update_cb, nullptr); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_ongoing_update_cb_unset(); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_ongoing_update_progress("org.tizen.caller_appid", 1, 10.0); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_ongoing_update_size("org.tizen.caller_appid", 1, 10.0); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_ongoing_update_content("org.tizen.caller_appid", 1, "test_content"); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} diff --git a/tests/noti_unittest/src/test_notification_setting.cc b/tests/noti_unittest/src/test_notification_setting.cc new file mode 100644 index 0000000..0aa4b90 --- /dev/null +++ b/tests/noti_unittest/src/test_notification_setting.cc @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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/gtest.h> +#include <gmock/gmock.h> + +#include "mock/test_fixture.hh" +#include "mock/aul_mock.hh" +#include "mock/glib_mock.hh" +#include "mock/sqlite_mock.hh" + +#include "notification/include/notification.h" +#include "notification/include/notification_setting.h" +#include "notification/include/notification_setting_internal.h" + +namespace { + +GDBusMessage* __fake_g_dbus_connection_send_message_with_reply_sync( + GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, + gint timeout, volatile guint32* out_serial, GCancellable* cancellable, + GError** error) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +GDBusMessage* __fake_g_dbus_message_new_method_call(const gchar* arg0, + const gchar* arg1, const gchar* arg2, const gchar* arg3) { + GDBusMessage* ret_msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL)); + + return ret_msg; +} + +class Mocks : + virtual public ::testing::NiceMock<AulMock>, + virtual public ::testing::NiceMock<GlibMock> {}; +} // namespace + +using ::testing::_; +using ::testing::Invoke; +using ::testing::Return; + +class NotificationSettingTest : public TestFixture { + public: + NotificationSettingTest() : TestFixture(std::make_unique<::Mocks>()) {} + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(NotificationSettingTest, notification_setting_test) { + EXPECT_CALL(GetMock<GlibMock>(), g_bus_watch_name(_, _, _, _, _, _, _)) + .WillOnce(Return(1)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_message_new_method_call(_, _, _, _)) + .WillOnce(Invoke(__fake_g_dbus_message_new_method_call)); + + EXPECT_CALL(GetMock<GlibMock>(), g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)) + .WillOnce(Invoke(__fake_g_dbus_connection_send_message_with_reply_sync)); + + int ret; + + notification_setting_h setting; + setting = (struct notification_setting *)malloc(sizeof(struct notification_setting)); + + setting->package_name = strdup("org.tizen.testpkg"); + setting->app_id = strdup("org.tizen.testapp"); + setting->allow_to_notify = true; + setting->do_not_disturb_except = false; + setting->pop_up_notification = false; + setting->visibility_class = 1; + setting->lock_screen_content_level = SHOW_ALL_CONTENT; + setting->app_disabled = false; + + int visibility; + ret = notification_setting_get_visibility_class(setting, &visibility); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_setting_set_visibility_class(setting, 3); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_setting_update_setting(setting); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); + + ret = notification_setting_free_notification(setting); + ASSERT_EQ(ret, NOTIFICATION_ERROR_NONE); +} |