Fix argv free position
[platform/core/appfw/appcore-widget.git] / test / unit_tests / test_widget_app.cc
index f6c73f5..3b3d2dc 100644 (file)
@@ -52,6 +52,10 @@ typedef struct _widget_base_instance_data {
   void* user_data;
 } widget_base_instance_data;
 
+struct _widget_context {
+  int context;
+};
+
 class Mocks : public ::testing::NiceMock<GioMock>,
               public ::testing::NiceMock<MultiWindowBaseMock>,
               public ::testing::NiceMock<AppCommonMock>,
@@ -266,6 +270,7 @@ TEST_F(WidgetAppTest, widget_app_main) {
       appcore_multiwindow_base_instance_exit(_)).Times(2);
 
   ret = widget_app_main(argc, argv, &callback, nullptr);
+  bundle_free_exported_argv(argc, &argv);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
@@ -276,8 +281,9 @@ TEST_F(WidgetAppTest, widget_app_exit) {
 
 TEST_F(WidgetAppTest, widget_app_terminate_context) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
   int ret = widget_app_terminate_context(context);
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
@@ -295,6 +301,11 @@ void __app_event_cb(app_event_info_h event_info, void *user_data) {
 
 TEST_F(WidgetAppTest, widget_app_add_event_handler) {
   app_event_handler_h handle;
+  EXPECT_CALL(GetMock<SystemInfoMock>(),
+      system_info_get_platform_bool(_, _)).
+          WillOnce(DoAll(
+                  SetArgPointee<1>(true),
+                  Return(0)));
   int ret = widget_app_add_event_handler(&handle, APP_EVENT_LOW_MEMORY,
       __app_event_cb, nullptr);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
@@ -302,6 +313,11 @@ TEST_F(WidgetAppTest, widget_app_add_event_handler) {
 
 TEST_F(WidgetAppTest, widget_app_remove_event_handler) {
   app_event_handler_h handle;
+  EXPECT_CALL(GetMock<SystemInfoMock>(),
+      system_info_get_platform_bool(_, _)).
+          WillRepeatedly(DoAll(
+                  SetArgPointee<1>(true),
+                  Return(0)));
   int ret = widget_app_add_event_handler(&handle, APP_EVENT_LOW_MEMORY,
       __app_event_cb, nullptr);
   ret = widget_app_remove_event_handler(handle);
@@ -310,13 +326,14 @@ TEST_F(WidgetAppTest, widget_app_remove_event_handler) {
 
 TEST_F(WidgetAppTest, widget_app_get_id) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
 
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_instance_get_id(_)).
           WillOnce(Return("test"));
 
   const char *id = widget_app_get_id(context);
+  free(context);
   EXPECT_STREQ(id, "test");
 }
 
@@ -339,19 +356,20 @@ TEST_F(WidgetAppTest, widget_app_class_create) {
 
 TEST_F(WidgetAppTest, widget_app_context_set_tag) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
 
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_instance_get_extra(_)).
       WillOnce(Invoke(__appcore_multiwindow_base_instance_get_extra_fake));
 
   int ret = widget_app_context_set_tag(context, (void*)"test");
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
 TEST_F(WidgetAppTest, widget_app_context_get_tag) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
 
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_instance_get_extra(_)).
@@ -359,12 +377,13 @@ TEST_F(WidgetAppTest, widget_app_context_get_tag) {
 
   void* tag;
   int ret = widget_app_context_get_tag(context, &tag);
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
 TEST_F(WidgetAppTest, widget_app_context_set_content_info) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
 
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_instance_get_extra(_)).
@@ -380,26 +399,25 @@ TEST_F(WidgetAppTest, widget_app_context_set_content_info) {
 
   bundle* content_info = bundle_create();
   int ret = widget_app_context_set_content_info(context, content_info);
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
 TEST_F(WidgetAppTest, widget_app_context_set_title) {
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
 
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_instance_get_extra(_)).
       WillRepeatedly(Invoke(__appcore_multiwindow_base_instance_get_extra_fake));
 
   int ret = widget_app_context_set_title(context, "title");
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
 TEST_F(WidgetAppTest, widget_app_class_add) {
   widget_instance_lifecycle_callback_s lifecycle;
-  widget_class_h cls = widget_app_class_add(
-      nullptr, "test", lifecycle, nullptr);
-
   lifecycle.create = __instance_create_cb;
   lifecycle.destroy = __instance_destroy_cb;
   lifecycle.pause = __instance_pause_cb;
@@ -407,6 +425,9 @@ TEST_F(WidgetAppTest, widget_app_class_add) {
   lifecycle.resize = __instance_resize_cb;
   lifecycle.update = __instance_update_cb;
 
+  widget_class_h cls = widget_app_class_add(
+      nullptr, "test", lifecycle, nullptr);
+
   EXPECT_CALL(GetMock<MultiWindowBaseMock>(),
       appcore_multiwindow_base_class_add(_)).
       WillOnce(Invoke(__appcore_multiwindow_base_class_add_fake));
@@ -443,14 +464,16 @@ TEST_F(WidgetAppTest, widget_app_class_add) {
   callback.terminate = __app_terminate_cb;
 
   ret = widget_app_main(argc, argv, &callback, nullptr);
+  bundle_free_exported_argv(argc, &argv);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }
 
 TEST_F(WidgetAppTest, widget_app_get_elm_win_negative) {
   Evas_Object* win;
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
   int ret = widget_app_get_elm_win(context, &win);
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_FAULT, ret);
 }
 
@@ -485,7 +508,8 @@ TEST_F(WidgetAppTest, widget_app_get_elm_win) {
 
   Evas_Object* win;
   widget_context_h context =
-      (widget_context_h)calloc(1, sizeof(widget_context_h));
+      (widget_context_h)calloc(1, sizeof(struct _widget_context));
   int ret = widget_app_get_elm_win(context, &win);
+  free(context);
   EXPECT_EQ(WIDGET_ERROR_NONE, ret);
 }