LTP GCOV extension - code coverage report
Current view: directory - src/services/scripter_module - scripter_dsa.c
Test: min.info
Date: 2009-06-18 Instrumented lines: 59
Code covered: 96.6 % Executed lines: 57

       1                 : /*
       2                 :  * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
       3                 :  * and/or its subsidiary(-ies).
       4                 :  * Contact: Marko Hyyppä
       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                 : /**
      22                 :  *  @file       scripter_dsa.c
      23                 :  *  @version    0.1
      24                 :  *  @brief      This file contains implementation of the Scripter DSA
      25                 :  */
      26                 : 
      27                 : /* ------------------------------------------------------------------------- */
      28                 : /* INCLUDE FILES */
      29                 : #include "scripter_dsa.h"
      30                 : 
      31                 : /* ------------------------------------------------------------------------- */
      32                 : /* EXTERNAL DATA STRUCTURES */
      33                 : /* None */
      34                 : 
      35                 : /* ------------------------------------------------------------------------- */
      36                 : /* EXTERNAL FUNCTION PROTOTYPES */
      37                 : /* None */
      38                 : 
      39                 : /* ------------------------------------------------------------------------- */
      40                 : /* CONSTANTS */
      41                 : /* None */
      42                 : 
      43                 : /* ------------------------------------------------------------------------- */
      44                 : /* MACROS */
      45                 : /* None */
      46                 : 
      47                 : /* ------------------------------------------------------------------------- */
      48                 : /* LOCAL CONSTANTS AND MACROS */
      49                 : /* None */
      50                 : 
      51                 : /* ------------------------------------------------------------------------- */
      52                 : /* MODULE DATA STRUCTURES */
      53                 : /* None */
      54                 : 
      55                 : /* ------------------------------------------------------------------------- */
      56                 : /* LOCAL FUNCTION PROTOTYPES */
      57                 : /* None */
      58                 : 
      59                 : /* ------------------------------------------------------------------------- */
      60                 : /* FORWARD DECLARATIONS */
      61                 : /* None */
      62                 : 
      63                 : /* ==================== LOCAL FUNCTIONS ==================================== */
      64                 : /* None */
      65                 : 
      66                 : /* ======================== FUNCTIONS ====================================== */
      67                 : 
      68                 : /** Adds Scripter Data Item to linked list of scripter data structures.
      69                 :  *  @param list_handle pointer to linked list of Scripter Data Item.
      70                 :  *  @param scripter_data pointer to Scripter Data Item structure.
      71                 :  *  @return pointer to Scripter Data Item structure,
      72                 :  *          or returns INITPTR if operation failed.  
      73                 :  *
      74                 :  *  Possible errors:
      75                 :  *  INITPTR if Scripter Data Item adding to list failed.
      76                 :  */
      77                 : DLListIterator scripter_dsa_add (DLList * list_handle,
      78                 :                                  ScripterDataItem * scripter_data)
      79             231 : {
      80             231 :         DLListIterator  dllist_item = INITPTR;
      81                 : 
      82             231 :         if (list_handle != INITPTR) {
      83             231 :                 dl_list_add (list_handle, (void *)scripter_data);
      84             231 :                 dllist_item = dl_list_tail (list_handle);
      85                 :         }
      86                 : 
      87             231 :         return dllist_item;
      88                 : }
      89                 : 
      90                 : /* ------------------------------------------------------------------------- */
      91                 : /** Creates new Scripter Data Item structure
      92                 :  *  @param DLL_name pointer to DLL name string.
      93                 :  *  @param DLL_type enumeration value of DLL type.
      94                 :  *  @return pointer to Scripter Data Item structure,
      95                 :  *          or returns INITPTR if operation failed.  
      96                 :  *
      97                 :  *  Possible errors:
      98                 :  *  INITPTR if Scripter Data Item creating to list failed.
      99                 :  */
     100                 : ScripterDataItem *scripter_dsa_create (TSChar * DLL_name, TSChar * Class_name,
     101                 :                                        TDLLType DLL_type)
     102             232 : {
     103             232 :         ScripterDataItem *scripter_data = NEW (ScripterDataItem);
     104             232 :         TSBool          complete = ESFalse;
     105             232 :         int             len = 0;
     106             232 :         int             lenc = 0;
     107                 : 
     108             232 :         if ((scripter_data != NULL) && (DLL_name != INITPTR)) {
     109                 : 
     110             232 :                 len = strlen (DLL_name) + 1;
     111             232 :                 scripter_data->DLL_name_ = NEW2 (TSChar, len);
     112             232 :                 lenc = strlen (Class_name) + 1;
     113             232 :                 scripter_data->Class_name_ = NEW2 (TSChar, lenc);
     114                 : 
     115             232 :                 scripter_data->symbol_list_ = dl_list_create ();
     116                 : 
     117             232 :                 if ((scripter_data->DLL_name_ != NULL) &&
     118                 :                     (scripter_data->symbol_list_ != INITPTR)) {
     119             232 :                         STRCPY (scripter_data->DLL_name_, DLL_name, len);
     120             232 :                         STRCPY (scripter_data->Class_name_, Class_name, lenc);
     121             232 :                         scripter_data->DLL_type_ = DLL_type;
     122             232 :                         complete = ESTrue;
     123                 :                 }
     124                 :         }
     125                 : 
     126                 :         /* Something went incorrectly and creation failed */
     127             232 :         if (complete == ESFalse)
     128               0 :                 scripter_data = INITPTR;
     129                 : 
     130             232 :         return scripter_data;
     131                 : }
     132                 : 
     133                 : /* ------------------------------------------------------------------------- */
     134                 : /** Frees the memory allocation of Scripter Data Item structure.
     135                 :  *  @param scripter_data reference pointer to Scripter Data Item.
     136                 :  *
     137                 :  *  Possible errors:
     138                 :  *  If returns INITPTR value in scripter_data then operation failed.
     139                 :  */
     140                 : void scripter_dsa_free (ScripterDataItem ** scripter_data)
     141             232 : {
     142                 :         DLListIterator it;
     143                 :         char *symbol;
     144                 : 
     145             232 :         if (*scripter_data != INITPTR) {
     146             232 :                 DELETE ((*scripter_data)->DLL_name_);
     147             232 :                 DELETE ((*scripter_data)->Class_name_);
     148             232 :                 if ((*scripter_data)->symbol_list_ != INITPTR) {
     149             232 :                         for (it = dl_list_head ((*scripter_data)->symbol_list_);
     150             883 :                              it != DLListNULLIterator;
     151             419 :                              it = dl_list_next (it)) {
     152             419 :                                 symbol = dl_list_data (it);
     153             419 :                                 DELETE (symbol);
     154                 :                         }
     155             232 :                         dl_list_free (&((*scripter_data)->symbol_list_));
     156                 :                         
     157                 : 
     158                 :                 }
     159                 : 
     160             232 :                 DELETE (*scripter_data);
     161             232 :                 if (*scripter_data == NULL)
     162               0 :                         *scripter_data = INITPTR;
     163                 :         }
     164             232 : }
     165                 : 
     166                 : /* ------------------------------------------------------------------------- */
     167                 : /** Removes Scripter Data Item structure from linked list.
     168                 :  *  @param scr_data_item pointer to list item in linked list.
     169                 :  *  @return returns 0 error value is removing completed successfully,
     170                 :  *          or returns error value if operation failed.  
     171                 :  *
     172                 :  *  Possible errors:
     173                 :  *  -1 If removing operation failed.
     174                 :  */
     175                 : int scripter_dsa_remove (DLListIterator scr_data_item)
     176             230 : {
     177             230 :         int             retval = 0;
     178                 :         ScripterDataItem *data;
     179             230 :         if (scr_data_item != INITPTR) {
     180             229 :                 data = dl_list_data (scr_data_item);
     181             229 :                 scripter_dsa_free (&data);
     182             229 :                 retval = dl_list_remove_it (scr_data_item);
     183                 :         } else {
     184               1 :                 errno = EINVAL;
     185               1 :                 retval = -1;
     186                 :         }
     187                 : 
     188             230 :         return retval;
     189                 : }
     190                 : 
     191                 : /* ------------------------------------------------------------------------- */
     192                 : /** Adds symbol name data to Scripter Data Item structure.
     193                 :  *  @param scr_data_item pointer to list item in linked list.
     194                 :  *  @param symbol_name Pointer symbol name string.
     195                 :  *  @return returns 0 error value when adding completed successfully,
     196                 :  *          or returns error value if operation failed.  
     197                 :  *
     198                 :  *  Possible errors:
     199                 :  *  -1 If adding operation failed.
     200                 :  */
     201                 : int scripter_dsa_add_symbol (DLListIterator scr_data_item,
     202                 :                              TSChar * symbol_name)
     203             420 : {
     204             420 :         ScripterDataItem *scripter_data = INITPTR;
     205             420 :         int             retval = 0;
     206                 : 
     207             420 :         if (scr_data_item != INITPTR) {
     208             419 :                 scripter_data =
     209                 :                     (ScripterDataItem *) dl_list_data (scr_data_item);
     210                 : 
     211             419 :                 if (scripter_data != INITPTR) {
     212             419 :                         retval = dl_list_add (scripter_data->symbol_list_,
     213                 :                                               (void *)symbol_name);
     214                 :                 }
     215                 :         } else {
     216               1 :                 errno = EINVAL;
     217               1 :                 retval = -1;
     218                 :         }
     219                 : 
     220             420 :         return retval;
     221                 : }
     222                 : 
     223                 : /* ------------------------------------------------------------------------- */
     224                 : 
     225                 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
     226                 : /* None */
     227                 : 
     228                 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
     229                 : #ifdef MIN_UNIT_TEST
     230                 : #include "scripter_dsa.tests"
     231                 : #endif                          /* MIN_UNIT_TEST */
     232                 : 
     233                 : /* End of file */

Generated by: LTP GCOV extension version 1.6