Eina_Inarray: fix tests for eina_inarray_insert* API
authorArtem Popov <artem.popov@samsung.com>
Wed, 19 Apr 2017 16:33:06 +0000 (19:33 +0300)
committerArtem Popov <artem.popov@samsung.com>
Wed, 19 Apr 2017 16:33:14 +0000 (19:33 +0300)
Change-Id: I86ed1a8e4276b28e20e99bccf3867323550cf758
Signed-off-by: Artem Popov <artem.popov@samsung.com>
TC/eina/eina_inarray/utc_eina_inarray_insert.c
TC/eina/eina_inarray/utc_eina_inarray_insert_sorted.c

index daaad6b3d0a544216c5dd58e5415b4e11ef1ac20..389c9e46598f01f6def5cd5c8e3543163f5f2e99 100644 (file)
@@ -6,9 +6,10 @@
 
 static int callbackFunctionCount = 0;
 
-static Eina_Bool callback(const void *container, void *data, void *fdata)
+static int callback(const void *data1, const void *data2)
 {
-   return EINA_TRUE;
+   callbackFunctionCount = 1;
+   return 1;
 }
 
 /**
@@ -40,15 +41,16 @@ teardown(void)
  * @objective Positive test case 01: provide a safe way to iterate over an array
  * @n Input data:
  * @ li arr The array to iterate over
- * @ li callback The callback to call for each item
- * @ li data The user data to pass to the callback
+ * @ li data The user data to pass to the array
+ * @ li callback The callback to compare each item
  *
  * @procedure
  * @step 1 Create a new array
  * @step 2 Push some data to the array
- * @step 3 Provide a safe way to iterate over an array
+ * @step 3 Insert new data to array and check if compare function was called
  *
- * @passcondition: Successfully iterate all items of the array
+ * @passcondition: eina_inarray_insert should return position (not -1) and compare
+ * function should be called
  * @}
  */
 START_TEST(utc_eina_inarray_insert_p_1)
@@ -68,24 +70,28 @@ START_TEST(utc_eina_inarray_insert_p_1)
    unsigned int i;
 
    Eina_Inarray* arr = eina_inarray_new(MEMBER_SIZE, INARRAY_SIZE);
-   if ( arr == NULL )
+   if (arr == NULL)
      {
         ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
-        return;
      }
 
    for (i = 0; i < INARRAY_SIZE; ++i)
-      eina_inarray_push(arr, strs[i]);
+     eina_inarray_push(arr, strs[i]);
 
-   if ( eina_inarray_insert(arr, callback, NULL) )
+   if (eina_inarray_insert(arr, "eleven", callback) == -1)
      {
         eina_inarray_free(arr);
-        printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
-        return;
+        ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
+     }
+
+   if (callbackFunctionCount == 0)
+     {
+        eina_inarray_free(arr);
+        ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
      }
 
    eina_inarray_free(arr);
-   ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
+   printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
 }
 END_TEST
 
index aa9877ad2d707a4a8ef89d0253e5fbc8fdacbb8d..c48a9369376310a4d6f3a908cb3a2c52cc6ad256 100644 (file)
@@ -6,9 +6,10 @@
 
 static int callbackFunctionCount = 0;
 
-static Eina_Bool callback(const void *container, void *data, void *fdata)
+static int callback(const void *data1, const void *data2)
 {
-   return EINA_TRUE;
+   callbackFunctionCount = 1;
+   return 1;
 }
 
 /**
@@ -40,15 +41,16 @@ teardown(void)
  * @objective Positive test case 01: provide a safe way to iterate over an array
  * @n Input data:
  * @ li arr The array to iterate over
- * @ li callback The callback to call for each item
- * @ li data The user data to pass to the callback
+ * @ li data The user data to pass to the array
+ * @ li callback The callback to compare each item
  *
  * @procedure
  * @step 1 Create a new array
  * @step 2 Push some data to the array
- * @step 3 Provide a safe way to iterate over an array
+ * @step 3 Insert new data to sorted array and check if compare function was called
  *
- * @passcondition: Successfully iterate all items of the array
+ * @passcondition: eina_inarray_insert_sorted should return position (not -1) and compare
+ * function should be called
  * @}
  */
 START_TEST(utc_eina_inarray_insert_sorted_p_1)
@@ -68,24 +70,28 @@ START_TEST(utc_eina_inarray_insert_sorted_p_1)
    unsigned int i;
 
    Eina_Inarray* arr = eina_inarray_new(MEMBER_SIZE, INARRAY_SIZE);
-   if ( arr == NULL )
+   if (arr == NULL)
      {
         ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
-        return;
      }
 
    for (i = 0; i < INARRAY_SIZE; ++i)
-      eina_inarray_push(arr, strs[i]);
+     eina_inarray_push(arr, strs[i]);
 
-   if ( eina_inarray_insert_sorted(arr, callback, NULL) )
+   if (eina_inarray_insert_sorted(arr, "ddd", callback) == -1)
      {
         eina_inarray_free(arr);
-        printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
-        return;
+        ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
+     }
+
+   if (callbackFunctionCount == 0)
+     {
+        eina_inarray_free(arr);
+        ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
      }
 
    eina_inarray_free(arr);
-   ck_abort_msg("[TEST_FAIL]:: %s[%d] : Test has failed..", __FILE__, __LINE__);
+   printf("[TEST_PASS]:: %s[%d] : Test has passed..\n", __FILE__, __LINE__);
 }
 END_TEST