LTP GCOV extension - code coverage report
Current view: directory - src/utils/dllist - dllist.tests
Test: min.info
Date: 2009-06-18 Instrumented lines: 472
Code covered: 100.0 % Executed lines: 472

       1                 : /*
       2                 :  * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
       3                 :  * and/or its subsidiary(-ies).
       4                 :  * Contact: Konrad Marek Zapalowicz
       5                 :  * Contact e-mail: DG.MIN-Support@nokia.com
       6                 :  * 
       7                 :  * This program is free software: you can redistribute it and/or modify it 
       8                 :  * under the terms of the GNU General Public License as published by the Free 
       9                 :  * Software Foundation, version 2 of the License. 
      10                 :  * 
      11                 :  * This program is distributed in the hope that it will be useful, but WITHOUT 
      12                 :  * ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or 
      13                 :  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General  Public License for
      14                 :  * more details. You should have received a copy of the GNU General Public 
      15                 :  * License along with this program. If not,  see 
      16                 :  * <http://www.gnu.org/licenses/>.
      17                 :  */
      18                 : 
      19                 : 
      20                 : /**
      21                 :  *  @file       dllist.test
      22                 :  *  @version    0.1
      23                 :  *  @brief      This file contains test for Doubly Linked List
      24                 :  */
      25                 : 
      26                 : /* ------------------------------------------------------------------------- */
      27                 : /* INCLUDES */
      28                 : #include <check.h>
      29                 : 
      30                 : /* ------------------------------------------------------------------------- */
      31                 : /* CONSTANTS */
      32                 : /* None */
      33                 : 
      34                 : /* ------------------------------------------------------------------------- */
      35                 : /* MACROS */
      36                 : /* None */
      37                 : 
      38                 : /* ------------------------------------------------------------------------- */
      39                 : /* DATA TYPES */
      40                 : /* None */
      41                 : 
      42                 : /* ------------------------------------------------------------------------- */
      43                 : /* LOCAL FUNCTION PROTOTYPES */
      44                 : int equal( const void* a, const void* b );
      45                 : /* ------------------------------------------------------------------------- */
      46                 : /* FORWARD DECLARATIONS */
      47                 : /* None */
      48                 : 
      49                 : /* ------------------------------------------------------------------------- */
      50                 : /* STRUCTURES */
      51                 : /* None */
      52                 : 
      53                 : /* ------------------------------------------------------------------------- */
      54                 : /* ==================== LOCAL FUNCTIONS ==================================== */
      55                 : /* ------------------------------------------------------------------------- */
      56                 : int equal( const void* a, const void* b )
      57              22 : {
      58              22 :     if( *((int*)a) == *((int*)b) )  return 0;
      59              10 :     else                            return -1;
      60                 : }
      61                 : /* ------------------------------------------------------------------------- */
      62                 : /* ============================= TESTS ===================================== */
      63                 : /* ------------------------------------------------------------------------- */
      64               1 : START_TEST(test_dllist_create)
      65                 : {
      66               1 :         DLList* l = dl_list_create();
      67               1 :         fail_unless( l != INITPTR, "List creation error." );
      68               1 :         fail_unless( dl_list_size(l) == 0, "Size not set correctly on creation.");
      69               1 :         dl_list_free( &l );
      70                 : }
      71               1 : END_TEST
      72                 : /* ------------------------------------------------------------------------- */
      73               1 : START_TEST(test_dllist_free)
      74                 : {
      75               1 :         DLList* l = dl_list_create();
      76               1 :         fail_unless( l != INITPTR, "List creation error." );
      77               1 :         dl_list_free( &l );
      78               1 :         fail_unless( l == INITPTR, "List freeing error." );
      79                 : }
      80               1 : END_TEST
      81                 : /* ------------------------------------------------------------------------- */
      82               1 : START_TEST(test_dllist_add_item)
      83                 : {
      84               1 :         int a      = 5;
      85               1 :         int retval = 0;
      86               1 :         DLList* l = dl_list_create();
      87               1 :         fail_unless( l != INITPTR, "List creation error." );
      88               1 :         a = 5;
      89               1 :         retval = dl_list_add(l,&a);
      90               1 :         fail_unless( retval != -1, "Adding failed." );
      91               1 :         fail_unless( dl_list_size(l) == 1, "Wrong size after addition.");
      92               1 :         dl_list_free( &l );
      93                 : 
      94               1 :         retval = dl_list_add(INITPTR,&a);\
      95                 :         fail_unless( retval == -1, "Data added when list is INITPTR." );
      96                 : }
      97               1 : END_TEST
      98                 : /* ------------------------------------------------------------------------- */
      99               1 : START_TEST(test_dllist_add_item_at_1)
     100                 : {
     101               1 :         int a = 1;
     102               1 :         int retval = 0;
     103               1 :         DLList* l  = dl_list_create();
     104               1 :         dl_list_free( &l );
     105               1 :         retval = dl_list_add_at(INITPTR,&a,0);
     106               1 :         fail_unless( retval == -1, "Data added when list is INITPTR." );
     107               1 :         retval = dl_list_add_at(INITPTR,&a,99);
     108               1 :         fail_unless( retval == -1, "Data added when list is INITPTR. (2)" );
     109                 : }
     110               1 : END_TEST
     111                 : /* ------------------------------------------------------------------------- */
     112               1 : START_TEST(test_dllist_add_item_at_2)
     113                 : {
     114                 :         int a[6];
     115               1 :         int retval = -1;
     116               1 :         int i = 0;
     117               1 :         DLListIterator it = DLListNULLIterator;
     118               1 :         DLList* l = dl_list_create();
     119               1 :         fail_unless( l != INITPTR, "List creation error." );
     120               1 :         a[0]    = 5;
     121               1 :         a[1]    = 7;
     122               1 :         a[2]    = 5;
     123               1 :         a[3]    = 98;
     124               1 :         a[4]    = 5;
     125               1 :         a[5]    = 5; 
     126                 :         
     127               7 :         for( i = 0 ; i < 6 ; i++ ) {
     128               6 :                 retval = dl_list_add(l,&a[i]);
     129               6 :                 fail_unless(retval != -1,"Adding failed.");
     130                 :         }
     131                 : 
     132               1 :         i = 5;
     133               1 :         retval = dl_list_count (dl_list_head(l),
     134                 :                                 dl_list_tail(l),
     135                 :                                 equal,
     136                 :                                 &i);
     137               1 :         fail_unless( retval==4,
     138                 :                "Count does nto work, invalid result. Expected %d, got %d",
     139                 :                 4,retval);
     140                 : 
     141               1 :         dl_list_free(&l); 
     142                 : }
     143               1 : END_TEST
     144                 : /* ------------------------------------------------------------------------- */
     145               1 : START_TEST(test_dllist_add_item_at_3)
     146                 : {
     147                 :         int a[3];
     148               1 :         int new    = 55;
     149               1 :         int retval = 0;
     150               1 :         int k      = 0;
     151               1 :         int* pom   = INITPTR;
     152               1 :         DLList* l  = dl_list_create();
     153               1 :         fail_unless( l != INITPTR, "List creation error." );
     154               1 :         a[0] = 88;
     155               1 :         a[1] = 89;
     156               1 :         a[2] = 90;
     157                 : 
     158               1 :         retval = dl_list_add_at(l,&a[0],0);
     159               1 :         fail_unless(retval != -1,"Adding failed.");
     160               1 :         fail_unless( dl_list_size(l) == 1, "Wrong size after addition.");
     161                 : 
     162               1 :         retval = dl_list_add_at(l,&a[1],0);
     163               1 :         fail_unless(retval != -1,"Adding failed.");
     164               1 :         fail_unless( dl_list_size(l) == 2, "Wrong size after addition. (2)");
     165                 : 
     166               1 :         retval = dl_list_add_at(l,&a[2],0);
     167               1 :         fail_unless(retval != -1,"Adding failed.");
     168               1 :         fail_unless( dl_list_size(l) == 3, "Wrong size after addition. (3)");
     169                 : 
     170               4 :         for( k = 0 ; k < dl_list_size(l) ; k++ ) {
     171               3 :                 pom = (int*)dl_list_data( dl_list_at(l,k) );
     172               3 :                 fail_unless(pom != INITPTR, "NULL value.");
     173               3 :                 fail_unless(*pom == a[2-k], "Bad value.");
     174                 :         }
     175               1 :         dl_list_free( &l );
     176                 : }
     177               1 : END_TEST
     178                 : /* ------------------------------------------------------------------------- */
     179               1 : START_TEST(test_dllist_add_item_at_4)
     180                 : {
     181                 :         int a[3];
     182               1 :         int new    = 55;
     183               1 :         int retval = 0;
     184               1 :         int k      = 0;
     185               1 :         int* pom   = INITPTR;
     186               1 :         DLList* l  = dl_list_create();
     187               1 :         fail_unless( l != INITPTR, "List creation error." );
     188               1 :         a[0] = 88;
     189               1 :         a[1] = 89;
     190               1 :         a[2] = 90;
     191                 : 
     192               1 :         retval = dl_list_add_at(l,&a[0],1);
     193               1 :         fail_unless(retval != -1,"Adding failed.");
     194               1 :         fail_unless( dl_list_size(l) == 1, "Wrong size after addition.");
     195                 : 
     196               1 :         retval = dl_list_add_at(l,&a[1],1);
     197               1 :         fail_unless(retval != -1,"Adding failed.");
     198               1 :         fail_unless( dl_list_size(l) == 2, "Wrong size after addition. (2)");
     199                 : 
     200               1 :         retval = dl_list_add_at(l,&a[2],1);
     201               1 :         fail_unless(retval != -1,"Adding failed.");
     202               1 :         fail_unless( dl_list_size(l) == 3, "Wrong size after addition. (3)");
     203                 : 
     204               1 :         pom = (int*)dl_list_data( dl_list_at(l,0) );
     205               1 :         fail_unless(pom != INITPTR, "NULL value.");
     206               1 :         fail_unless(*pom == a[0], "Bad value. (1)");
     207                 : 
     208               1 :         pom = (int*)dl_list_data( dl_list_at(l,1) );
     209               1 :         fail_unless(pom != INITPTR, "NULL value.");
     210               1 :         fail_unless(*pom == a[2], "Bad value. (2)");
     211                 : 
     212               1 :         pom = (int*)dl_list_data( dl_list_at(l,2) );
     213               1 :         fail_unless(pom != INITPTR, "NULL value.");
     214               1 :         fail_unless(*pom == a[1], "Bad value. (3)");
     215                 : 
     216               1 :         dl_list_free( &l );
     217                 : }
     218               1 : END_TEST
     219                 : /* ------------------------------------------------------------------------- */
     220               1 : START_TEST(test_dllist_remove_item)
     221                 : {
     222               1 :         int a      = 8;
     223               1 :         int b      = 9;
     224               1 :         int retval = -1;
     225               1 :         DLList* l  = dl_list_create();
     226               1 :         fail_unless( l != INITPTR, "List creation error." );
     227               1 :         dl_list_add(l,&a);
     228               1 :         dl_list_add(l,&b);
     229               1 :         retval = dl_list_remove_it( dl_list_find(dl_list_head(l)
     230                 :                                       , dl_list_tail(l)
     231                 :                                       , equal,&a) );
     232               1 :         fail_unless( retval != -1, "Removing failed." );
     233               1 :         fail_unless( dl_list_size(l) == 1, "Wrong size after removal.");
     234               1 :         dl_list_free( &l );
     235                 : }
     236               1 : END_TEST
     237                 : /* ------------------------------------------------------------------------- */
     238               1 : START_TEST(test_dllist_add_multiple_item)
     239                 : {
     240                 :         int a[3];
     241               1 :         int i         = 0;
     242               1 :         int k         = 0;
     243               1 :         int retval    = -1;
     244               1 :         int* pom      = INITPTR;
     245               1 :         DLList* lista = dl_list_create();
     246               1 :         fail_unless( lista != INITPTR, "List creation error." );
     247               1 :         a[0]  = 5;
     248               1 :         a[1]  = 6;
     249               1 :         a[2]  = 7;
     250               4 :         for( i = 0 ; i < 3 ; i++ ) {
     251               3 :                 retval = dl_list_add(lista,&a[i]);
     252               3 :                 fail_unless(retval != -1,"Adding failed.");
     253                 :         }
     254               4 :         for( k = 0 ; k < dl_list_size(lista) ; k++ ) {
     255               3 :                 pom = (int*)dl_list_data( dl_list_at(lista,k) );
     256               3 :                 fail_unless(pom != INITPTR, "NULL value.");
     257               3 :                 fail_unless(*pom == a[k], "Bad value.");
     258                 :         }
     259               1 :         dl_list_free( &lista );
     260                 : }
     261               1 : END_TEST
     262                 : /* ------------------------------------------------------------------------- */
     263               1 : START_TEST(test_dllist_two_lists)
     264                 : {
     265               1 :         int a  = 5;
     266               1 :         int retval = -1;
     267               1 :         DLList* l  = dl_list_create();
     268               1 :         DLList* ll = dl_list_create();
     269               1 :         fail_unless( l != INITPTR, "List 1 creation error." );
     270               1 :         fail_unless( ll != INITPTR, "List 2 creation error." );
     271               1 :         retval = dl_list_add(l,&a);
     272               1 :         fail_unless( retval != -1, "Adding failed.");
     273               1 :         fail_unless( dl_list_size(l) != dl_list_size(ll), "Changes to one visible to other");
     274               1 :         dl_list_free( &l );
     275               1 :         dl_list_free( &ll );
     276                 : }
     277               1 : END_TEST
     278                 : /* ------------------------------------------------------------------------- */
     279               1 : START_TEST(test_dllist_alter_item_by_iterator)
     280                 : {
     281                 :         int a[3];
     282               1 :         int retval = -1;
     283               1 :         int i = 0;
     284               1 :         int* value = INITPTR;
     285               1 :         DLList* l  = dl_list_create();
     286               1 :         fail_unless( l != INITPTR, "List creation error." );
     287               1 :         a[0] = 5;
     288               1 :         a[1] = 7;
     289               1 :         a[2] = 98;
     290               4 :         for( i = 0 ; i < 3 ; i++ ) {
     291               3 :                 retval = dl_list_add(l,&a[i]);
     292               3 :                 fail_unless(retval != -1,"Adding failed.");
     293                 :         }
     294               1 :         retval = dl_list_alter_it( dl_list_head(l), &a[2] );
     295               1 :         fail_unless( retval != -1, "dl_list_alter_it failed." );
     296               1 :         value = (int*)dl_list_data(dl_list_head(l));
     297               1 :         fail_unless( *value == a[2], "Alter error." );
     298               1 :         retval = dl_list_alter_it( dl_list_head(l), INITPTR );
     299               1 :         fail_unless( retval != -1, "dl_list_alter_it failed when value NULL." );
     300               1 :         dl_list_free( &l );
     301               1 :         retval = dl_list_alter_it( INITPTR, &a[2] );
     302               1 :         fail_unless( retval == -1, "dl_list_alter_it executed when list is NULL." );
     303                 : }
     304               1 : END_TEST
     305                 : /* ------------------------------------------------------------------------- */
     306               1 : START_TEST(test_dllist_alter_item_by_data)
     307                 : {
     308                 :         int a[3];
     309               1 :         int i = 0;
     310               1 :         int retval = -1;
     311               1 :         void* pom = INITPTR;
     312               1 :         int* value = INITPTR;
     313               1 :         DLList* l  = dl_list_create();
     314               1 :         fail_unless( l != INITPTR, "List creation error." );
     315               1 :         a[0] = 5;
     316               1 :         a[1] = 7;
     317               1 :         a[2] = 98;
     318               4 :         for( i = 0 ; i < 3 ; i++ ) {
     319               3 :                 retval = dl_list_add(l,&a[i]);
     320               3 :                 fail_unless(retval != -1,"Adding failed.");
     321                 :         }
     322               1 :         pom = dl_list_data( dl_list_head(l) );
     323               1 :         *(int*)pom = a[2];
     324               1 :         value = (int*)dl_list_data(dl_list_head(l));
     325               1 :         fail_unless( *value == a[2], "Alter error." );
     326               1 :         dl_list_free( &l );
     327                 : }
     328               1 : END_TEST
     329                 : /* ------------------------------------------------------------------------- */
     330               1 : START_TEST(test_dllist_next_functionality)
     331                 : {
     332               1 :         DLList* l  = dl_list_create();
     333                 :         int a[3];
     334               1 :         int i = 0;
     335               1 :         int* value = INITPTR;
     336               1 :         int retval = -1;
     337               1 :         DLListIterator pom = DLListNULLIterator;
     338               1 :         fail_unless( l != INITPTR, "List creation error." );
     339               1 :         a[0] = 5;
     340               1 :         a[1] = 7;
     341               1 :         a[2] = 98;
     342               4 :         for( i = 0 ; i < 3 ; i++ ) {
     343               3 :                 retval = dl_list_add(l,&a[i]);
     344               3 :                 fail_unless(retval != -1,"Adding failed.");
     345                 :         }
     346               1 :         pom = dl_list_next( dl_list_head(l) );
     347               1 :         value = (int*)dl_list_data(pom);
     348               1 :         fail_unless(*value == a[1],"next failed.");
     349               1 :         dl_list_free( &l );
     350               1 :         pom = dl_list_next( INITPTR );
     351               1 :         fail_unless( pom == DLListNULLIterator
     352                 :                    , "Iterator not null when list is null." );
     353                 : }
     354               1 : END_TEST
     355                 : /* ------------------------------------------------------------------------- */
     356               1 : START_TEST(test_dllist_prev_functionality)
     357                 : {
     358               1 :         DLList* l  = dl_list_create();
     359                 :         int a[3];
     360               1 :         int i = 0;
     361               1 :         int* value = INITPTR;
     362               1 :         int retval = -1;
     363               1 :         DLListIterator pom = DLListNULLIterator;
     364               1 :         fail_unless( l != INITPTR, "List creation error." );
     365               1 :         a[0] = 5;
     366               1 :         a[1] = 7;
     367               1 :         a[2] = 98;
     368               4 :         for( i = 0 ; i < 3 ; i++ ) {
     369               3 :                 retval = dl_list_add(l,&a[i]);
     370               3 :                 fail_unless(retval != -1,"Adding failed.");
     371                 :         }
     372               1 :         pom = dl_list_prev( dl_list_tail(l) );
     373               1 :         value = (int*)dl_list_data(pom);
     374               1 :         fail_unless(*value == a[1],"prev failed.");
     375               1 :         dl_list_free( &l );
     376               1 :         pom = dl_list_prev( INITPTR );
     377               1 :         fail_unless( pom == DLListNULLIterator
     378                 :                    , "Iterator not null when list is null." );
     379                 : }
     380               1 : END_TEST
     381                 : /* ------------------------------------------------------------------------- */
     382               1 : START_TEST(test_dllist_head)
     383                 : {
     384               1 :         DLListIterator it = DLListNULLIterator;
     385               1 :         DLList* l  = dl_list_create();
     386                 :         int a[3];
     387               1 :         int i = 0;
     388               1 :         int* value = INITPTR;
     389               1 :         int retval = -1;
     390               1 :         fail_unless( l != INITPTR, "List creation error." );
     391               1 :         a[0] = 5;
     392               1 :         a[1] = 7;
     393               1 :         a[2] = 98;
     394               4 :         for( i = 0 ; i < 3 ; i++ ) {
     395               3 :                 retval = dl_list_add(l,&a[i]);
     396               3 :                 fail_unless(retval != -1,"Adding failed.");
     397                 :         }
     398               1 :         it = dl_list_head(l);
     399               1 :         fail_unless(it != DLListNULLIterator,"Head is NULL.");
     400               1 :         value = (int*)dl_list_data(it);
     401               1 :         fail_unless( *value == a[0], "Bad head" );
     402               1 :         dl_list_free( &l );
     403               1 :         it = dl_list_head(INITPTR);
     404               1 :         fail_unless( it == DLListNULLIterator
     405                 :                    , "Head is obtained when list is NULL." );
     406                 : }
     407               1 : END_TEST
     408                 : /* ------------------------------------------------------------------------- */
     409               1 : START_TEST(test_dllist_tail)
     410                 : {
     411               1 :         DLListIterator it = DLListNULLIterator;
     412               1 :         DLList* l  = dl_list_create();
     413                 :         int a[3];
     414               1 :         int i = 0;
     415               1 :         int* value = INITPTR;
     416               1 :         int retval = -1;
     417               1 :         fail_unless( l != INITPTR, "List creation error." );
     418               1 :         a[0] = 5;
     419               1 :         a[1] = 7;
     420               1 :         a[2] = 98;
     421               4 :         for( i = 0 ; i < 3 ; i++ ) {
     422               3 :                 retval = dl_list_add(l,&a[i]);
     423               3 :                 fail_unless(retval != -1,"Adding failed.");
     424                 :         }
     425               1 :         it = dl_list_tail(l);
     426               1 :         fail_unless( it != DLListNULLIterator, "Tail is NULL." );
     427               1 :         value = (int*)dl_list_data(it);
     428               1 :         fail_unless( *value == a[2], "Bad tail." );
     429               1 :         dl_list_free( &l );
     430               1 :         it = dl_list_tail(INITPTR);
     431               1 :         fail_unless( it == DLListNULLIterator
     432                 :                    , "Tail is obtained when list is NULL." );
     433                 : }
     434               1 : END_TEST
     435                 : /* ------------------------------------------------------------------------- */
     436               1 : START_TEST(test_dllist_size)
     437                 : {
     438               1 :         DLList* l  = dl_list_create();
     439                 :         int a[3];
     440               1 :         int retval = 0;
     441               1 :         DLListIterator it = DLListNULLIterator;
     442               1 :         fail_unless( l != INITPTR, "List creation error." );
     443               1 :         fail_unless( dl_list_size(l) == 0,"Wrong size after creation." );
     444               1 :         a[0]       = 5;
     445               1 :         a[1]       = 7;
     446               1 :         a[2]       = 98;
     447               1 :         retval = dl_list_add(l,&a[0]);
     448               1 :         fail_unless(retval != -1,"Adding failed.");
     449               1 :         fail_unless( dl_list_size(l) == 1,"Wrong size after addition." );
     450               1 :         retval = dl_list_add(l,&a[1]);
     451               1 :         fail_unless(retval != -1,"Adding failed.");
     452               1 :         fail_unless( dl_list_size(l) == 2,"Wrong size after addition." );
     453               1 :         retval = dl_list_add(l,&a[2]);
     454               1 :         fail_unless(retval != -1,"Adding failed.");
     455               1 :         fail_unless( dl_list_size(l) == 3,"Wrong size after addition." );
     456               1 :         it = dl_list_tail(l);
     457               1 :         retval = dl_list_remove_it(it);
     458               1 :         fail_unless(retval != -1,"Removing failed.");
     459               1 :         fail_unless( dl_list_size(l) == 2,"Wrong size after removal." );
     460               1 :         dl_list_free( &l );
     461               1 :         retval = dl_list_size(INITPTR);
     462               1 :         fail_unless( retval == -1,"Size counted when list is NULL.");
     463                 : }
     464               1 : END_TEST
     465                 : /* ------------------------------------------------------------------------- */
     466               1 : START_TEST(test_dllist_remove)
     467                 : {
     468               1 :         DLList* l  = dl_list_create();
     469                 :         int a[3];
     470               1 :         int retval = 0;
     471               1 :         int i = 0;
     472               1 :         DLListIterator it = DLListNULLIterator;
     473               1 :         fail_unless( l != INITPTR, "List creation error." );
     474               1 :         fail_unless( dl_list_size(l) == 0,"Wrong size after creation." );
     475               1 :         a[0]       = 5;
     476               1 :         a[1]       = 7;
     477               1 :         a[2]       = 98;
     478               4 :         for( i = 0 ; i < 3 ; i++ ) {
     479               3 :                 retval = dl_list_add(l,&a[i]);
     480               3 :                 fail_unless(retval != -1,"Adding failed.");
     481                 :         }
     482               1 :         it = dl_list_tail(l);
     483               1 :         fail_unless(it != DLListNULLIterator,"Tail is NULL.");
     484               1 :         retval = dl_list_remove_it(it);
     485               1 :         fail_unless(retval != -1,"Removing failed.");
     486               1 :         it = dl_list_head(l);
     487               1 :         fail_unless(it != DLListNULLIterator,"Head is NULL.");
     488               1 :         retval = dl_list_remove_it(it);
     489               1 :         fail_unless(retval != -1,"Removing failed.");
     490               1 :         retval = dl_list_add(l,&a[0]);
     491               1 :         fail_unless(retval != -1,"Adding failed.");
     492               1 :         it = dl_list_head(l);
     493               1 :         fail_unless(it != DLListNULLIterator,"Head is NULL.");
     494               1 :         retval = dl_list_remove_it(it);
     495               1 :         fail_unless(retval != -1,"Removing failed.");
     496               1 :         it = dl_list_head(l);
     497               1 :         fail_unless(it != DLListNULLIterator,"Head is NULL.");
     498               1 :         retval = dl_list_remove_it(it);
     499               1 :         fail_unless(retval != -1,"Removing failed.");
     500               1 :         it = dl_list_head(l);
     501               1 :         fail_unless(it == DLListNULLIterator,"Head is not NULL.");
     502               1 :         retval = dl_list_remove_it(it);
     503               1 :         fail_unless(retval == -1,"Removing failed.");
     504               1 :         dl_list_free( &l );
     505                 : }
     506               1 : END_TEST
     507                 : /* ------------------------------------------------------------------------- */
     508               1 : START_TEST(test_dllist_data_at)
     509                 : {
     510               1 :         int * value = INITPTR;
     511                 :         int a[3];
     512               1 :         int retval = 0;
     513               1 :         int i = 0;
     514               1 :         DLListIterator it = DLListNULLIterator;
     515               1 :         DLList* l  = dl_list_create();
     516               1 :         fail_unless( l != INITPTR, "List creation error." );
     517               1 :         fail_unless( dl_list_size(l) == 0,"Wrong size after creation." );
     518               1 :         a[0]       = 5;
     519               1 :         a[1]       = 7;
     520               1 :         a[2]       = 98;
     521               4 :         for( i = 0 ; i < 3 ; i++ ) {
     522               3 :                 retval = dl_list_add(l,&a[i]);
     523               3 :                 fail_unless(retval != -1,"Adding failed.");
     524                 :         }
     525               1 :         it = dl_list_at(l,0);
     526               1 :         fail_unless( it != DLListNULLIterator,"First is NULL." );
     527               1 :         value = (int*)dl_list_data(it);
     528               1 :         fail_unless(*value == a[0], "Data of first element is wrong" );
     529               1 :         it = dl_list_at(l,1);
     530               1 :         fail_unless( it != DLListNULLIterator,"Second is NULL." );
     531               1 :         value = (int*)dl_list_data(it);
     532               1 :         fail_unless(*value == a[1], "Data of second element is wrong" );
     533               1 :         it = dl_list_at(l,2);
     534               1 :         fail_unless( it != DLListNULLIterator,"Third is NULL." );
     535               1 :         value = (int*)dl_list_data(it);
     536               1 :         fail_unless(*value == a[2], "Data of third element is wrong" );
     537               1 :         it = dl_list_at(l,3);
     538               1 :         fail_unless( it == DLListNULLIterator,"Out of range is not NULL." );
     539               1 :         dl_list_free( &l );
     540               1 :         value = (int*)dl_list_data(INITPTR);
     541               1 :         fail_unless( value == DLListNULLIterator
     542                 :                    , "Data obtained but iterator is NULLed" );
     543                 : }
     544               1 : END_TEST
     545                 : /* ------------------------------------------------------------------------- */
     546               1 : START_TEST(test_dllist_find)
     547                 : {
     548               1 :         int* value = INITPTR;
     549                 :         int a[3];
     550               1 :         int retval = -1;
     551               1 :         int i = 0;
     552               1 :         DLListIterator it = DLListNULLIterator;
     553               1 :         DLList* l = dl_list_create();
     554               1 :         fail_unless( l != INITPTR, "List creation error." );
     555               1 :         a[0]       = 5;
     556               1 :         a[1]       = 7;
     557               1 :         a[2]       = 98;
     558               4 :         for( i = 0 ; i < 3 ; i++ ) {
     559               3 :                 retval = dl_list_add(l,&a[i]);
     560               3 :                 fail_unless(retval != -1,"Adding failed.");
     561                 :         }
     562               1 :         it = dl_list_find( dl_list_head(l)
     563                 :                          , dl_list_tail(l)
     564                 :                          , equal
     565                 :                          , &a[2] );
     566               1 :         fail_unless( it != DLListNULLIterator, "Not valid result of search." );
     567               1 :         value = (int*)dl_list_data(it);
     568               1 :         fail_unless( *value == a[2], "Not valid data after search." );
     569                 : 
     570               1 :         it = dl_list_find( dl_list_head(l)
     571                 :                          , dl_list_tail(l)
     572                 :                          , equal
     573                 :                          , &a[1] );
     574               1 :         fail_unless( it != DLListNULLIterator, "Not valid result of search." );
     575               1 :         value = (int*)dl_list_data(it);
     576               1 :         fail_unless( *value == a[1], "Not valid data after search." );
     577                 : 
     578               1 :         it = dl_list_find( dl_list_head(l)
     579                 :                          , dl_list_tail(l)
     580                 :                          , equal
     581                 :                          , &a[0] );
     582               1 :         fail_unless( it != DLListNULLIterator, "Not valid result of search." );
     583               1 :         value = (int*)dl_list_data(it);
     584               1 :         fail_unless( *value == a[0], "Not valid data after search." );
     585                 : 
     586               1 :         i = 17;
     587               1 :         it = dl_list_find( dl_list_head(l)
     588                 :                          , dl_list_tail(l)
     589                 :                          , equal
     590                 :                          , &i );
     591               1 :         fail_unless( it == DLListNULLIterator
     592                 :                    , "Iterator expected to be NULL, element not on the list" );
     593                 : 
     594               1 :         it = dl_list_find( DLListNULLIterator
     595                 :                          , dl_list_tail(l)
     596                 :                          , equal
     597                 :                          , &a[2] );
     598               1 :         fail_unless( it == DLListNULLIterator
     599                 :                    , "Iterator expected to be NULL, invalid parameter." );
     600                 : 
     601               1 :         it = dl_list_find( dl_list_head(l)
     602                 :                          , DLListNULLIterator
     603                 :                          , equal
     604                 :                          , &a[2] );
     605               1 :         fail_unless( it == DLListNULLIterator
     606                 :                    , "Iterator expected to be NULL, invalid parameter." );
     607                 : 
     608               1 :         it = dl_list_find( DLListNULLIterator
     609                 :                          , DLListNULLIterator
     610                 :                          , equal
     611                 :                          , &a[2] );
     612               1 :         fail_unless( it == DLListNULLIterator
     613                 :                    , "Iterator expected to be NULL, invalid parameter." );
     614                 : 
     615               1 :         it = dl_list_find( dl_list_head(l)
     616                 :                          , dl_list_tail(l)
     617                 :                          , (ptr2compare)INITPTR
     618                 :                          , &a[2] );
     619               1 :         fail_unless( it == DLListNULLIterator
     620                 :                    , "Iterator expected to be NULL, invalid parameter." );
     621                 : 
     622               1 :         it = dl_list_find( dl_list_tail(l)
     623                 :                          , dl_list_head(l)
     624                 :                          , (ptr2compare)INITPTR
     625                 :                          , &a[2] );
     626               1 :         fail_unless( it == DLListNULLIterator
     627                 :                    , "Iterator expected to be NULL, invalid parameter." );
     628                 : 
     629               1 :         it = dl_list_find( dl_list_head(l)
     630                 :                          , dl_list_head(l)
     631                 :                          , (ptr2compare)INITPTR
     632                 :                          , &a[2] );
     633               1 :         fail_unless( it == DLListNULLIterator
     634                 :                    , "Iterator expected to be NULL, invalid parameter." );
     635                 : 
     636               1 :         it = dl_list_find( dl_list_tail(l)
     637                 :                          , dl_list_tail(l)
     638                 :                          , (ptr2compare)INITPTR
     639                 :                          , &a[2] );
     640               1 :         fail_unless( it == DLListNULLIterator
     641                 :                    , "Iterator expected to be NULL, invalid parameter." );
     642                 : }
     643               1 : END_TEST
     644                 : /* ------------------------------------------------------------------------- */
     645               1 : START_TEST(test_dllist_count)
     646                 : {
     647                 :         int a[6];
     648               1 :         int retval = -1;
     649               1 :         int i = 0;
     650               1 :         DLListIterator it = DLListNULLIterator;
     651               1 :         DLList* l = dl_list_create();
     652               1 :         fail_unless( l != INITPTR, "List creation error." );
     653               1 :         a[0]    = 5;
     654               1 :         a[1]    = 7;
     655               1 :         a[2]    = 5;
     656               1 :         a[3]    = 98;
     657               1 :         a[4]    = 5;
     658               1 :         a[5]    = 5; 
     659                 :         
     660               7 :         for( i = 0 ; i < 6 ; i++ ) {
     661               6 :                 retval = dl_list_add(l,&a[i]);
     662               6 :                 fail_unless(retval != -1,"Adding failed.");
     663                 :         }
     664                 : 
     665               1 :         i = 5;
     666               1 :         retval = dl_list_count (dl_list_head(l),
     667                 :                                 dl_list_tail(l),
     668                 :                                 equal,
     669                 :                                 &i);
     670               1 :         fail_unless( retval==4,
     671                 :                "Count does nto work, invalid result. Expected %d, got %d",
     672                 :                 4,retval);
     673                 : 
     674               1 :         dl_list_free(&l); 
     675                 :                                 
     676                 : }
     677               1 : END_TEST
     678                 : /* ------------------------------------------------------------------------- */
     679                 : /* ========================== FUNCTIONS ==================================== */
     680                 : /* ------------------------------------------------------------------------- */
     681                 : Suite* dllist_suite()
     682              26 : {
     683              26 :         Suite * s = suite_create ("dllist");
     684                 : 
     685                 :         /* Core test case */
     686              26 :         TCase *tc_core = tcase_create ("Core");
     687              26 :         tcase_add_test (tc_core, test_dllist_create);
     688              26 :         tcase_add_test (tc_core, test_dllist_free);
     689              26 :         tcase_add_test (tc_core, test_dllist_add_item);
     690              26 :         tcase_add_test (tc_core, test_dllist_add_item_at_1);
     691              26 :         tcase_add_test (tc_core, test_dllist_add_item_at_2);
     692              26 :         tcase_add_test (tc_core, test_dllist_add_item_at_3);
     693              26 :         tcase_add_test (tc_core, test_dllist_add_item_at_4);
     694              26 :         tcase_add_test (tc_core, test_dllist_remove_item);
     695              26 :         tcase_add_test (tc_core, test_dllist_add_multiple_item);
     696              26 :         tcase_add_test (tc_core, test_dllist_two_lists);
     697              26 :         tcase_add_test (tc_core, test_dllist_alter_item_by_iterator);
     698              26 :         tcase_add_test (tc_core, test_dllist_alter_item_by_data);
     699              26 :         tcase_add_test (tc_core, test_dllist_next_functionality);
     700              26 :         tcase_add_test (tc_core, test_dllist_prev_functionality);
     701              26 :         tcase_add_test (tc_core, test_dllist_head);
     702              26 :         tcase_add_test (tc_core, test_dllist_tail);
     703              26 :         tcase_add_test (tc_core, test_dllist_size);
     704              26 :         tcase_add_test (tc_core, test_dllist_remove);
     705              26 :         tcase_add_test (tc_core, test_dllist_data_at);
     706              26 :         tcase_add_test (tc_core, test_dllist_find);
     707                 : 
     708              26 :         tcase_add_test (tc_core, test_dllist_count);
     709                 : 
     710              26 :         suite_add_tcase (s, tc_core);
     711                 : 
     712              26 :         return s;
     713                 : }
     714                 : /* ------------------------------------------------------------------------- */
     715                 : int dllist_tests()
     716              26 : {
     717              26 :         int number_failed = 0;
     718              26 :         Suite   * s  = dllist_suite ();
     719              26 :         SRunner * sr = srunner_create (s);
     720              26 :         srunner_run_all(sr, CK_NORMAL);
     721               5 :         number_failed = srunner_ntests_failed(sr);
     722               5 :         srunner_free(sr);
     723               5 :         return number_failed;
     724                 : }
     725                 : /* ------------------------------------------------------------------------- */
     726                 : /* End of file */

Generated by: LTP GCOV extension version 1.6