Changeset 481 for trunk/src/sh_fifo.c


Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (9 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_fifo.c

    r272 r481  
    180180              memset(getit->data, 0, len);
    181181              if (NULL != sl_strstr (getit->data, _("LOGKEY")))
    182                 {
    183                   MUNLOCK(getit->data, (len+1));
    184                   ;
    185                 }
     182                MUNLOCK(getit->data, (len+1));
    186183              if (getit->s_xtra)
    187184                SH_FREE(getit->s_xtra);
     
    197194/* push an item on the head of the list
    198195 */
    199 int push_list (SH_FIFO * fifo, char * indat, int in_i, const char * in_str)
     196int push_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str)
    200197{
    201198  struct dlist * item;
     
    224221 
    225222  if (NULL != sl_strstr (indat, _("LOGKEY")))
    226     {
    227       MLOCK(item->data, (len+1));
    228       ;
    229     }
     223    MLOCK(item->data, (len+1));
    230224
    231225  sl_strlcpy (item->data, indat, len+1);
     
    260254/* push an item on the tail of the list
    261255 */
    262 int push_tail_list (SH_FIFO * fifo, char * indat, int in_i, const char * in_str)
     256int push_tail_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str)
    263257{
    264258  struct dlist * item;
     
    287281
    288282  if (NULL != sl_strstr (indat, _("LOGKEY")))
    289     {
    290       MLOCK(item->data, (len+1));
    291       ;
    292     }
     283    MLOCK(item->data, (len+1));
    293284
    294285  sl_strlcpy (item->data, indat, len+1);
     
    318309  ++(fifo->fifo_cts);
    319310
    320   SL_RETURN((0), _("push_tail_list"));
     311  SL_RETURN((fifo->fifo_cts), _("push_tail_list"));
    321312}
    322313
     
    356347
    357348  if (NULL != sl_strstr (retval, _("LOGKEY")))
    358     {
    359       MUNLOCK(getit->data, (len+1));
    360       ;
    361     }
     349    MUNLOCK(getit->data, (len+1));
    362350
    363351  if (getit->s_xtra)
     
    372360
    373361
    374 
    375 
     362#ifdef SH_CUTEST
     363#include "CuTest.h"
     364
     365void Test_fifo (CuTest *tc) {
     366
     367  SH_FIFO ff;
     368  int ret;
     369  char * p;
     370
     371  fifo_init(&ff);
     372
     373  p = sh_fifo_pop(&ff);
     374  CuAssertPtrEquals(tc, NULL, p);
     375
     376  /* first sequence */
     377  ret = sh_fifo_push(&ff, "one");
     378  CuAssertIntEquals(tc,1,ret);
     379  ret = sh_fifo_push(&ff, "two");
     380  CuAssertIntEquals(tc,2,ret);
     381  ret = sh_fifo_push(&ff, "three");
     382  CuAssertIntEquals(tc,3,ret);
     383
     384  p = sh_fifo_pop(&ff);
     385  CuAssertPtrNotNull(tc, p);
     386  CuAssertStrEquals(tc,"one", p);
     387  p = sh_fifo_pop(&ff);
     388  CuAssertPtrNotNull(tc, p);
     389  CuAssertStrEquals(tc,"two", p);
     390  p = sh_fifo_pop(&ff);
     391  CuAssertPtrNotNull(tc, p);
     392  CuAssertStrEquals(tc,"three", p);
     393  p = sh_fifo_pop(&ff);
     394  CuAssertPtrEquals(tc, NULL, p);
     395
     396  /* second sequence */
     397  ret = sh_fifo_push(&ff, "one");
     398  CuAssertIntEquals(tc,1,ret);
     399  p = sh_fifo_pop(&ff);
     400  CuAssertPtrNotNull(tc, p);
     401  CuAssertStrEquals(tc,"one", p);
     402  ret = sh_fifo_push_tail(&ff, "one");
     403  CuAssertIntEquals(tc,1,ret);
     404  p = sh_fifo_pop(&ff);
     405  CuAssertPtrNotNull(tc, p);
     406  CuAssertStrEquals(tc,"one", p);
     407  p = sh_fifo_pop(&ff);
     408  CuAssertPtrEquals(tc, NULL, p);
     409
     410  /* third sequence */
     411  ret = sh_fifo_push(&ff, "one");
     412  CuAssertIntEquals(tc,1,ret);
     413  ret = sh_fifo_push(&ff, "two");
     414  CuAssertIntEquals(tc,2,ret);
     415  ret = sh_fifo_push(&ff, "three");
     416  CuAssertIntEquals(tc,3,ret);
     417
     418  p = sh_fifo_pop(&ff);
     419  CuAssertPtrNotNull(tc, p);
     420  CuAssertStrEquals(tc,"one", p);
     421  ret = sh_fifo_push_tail(&ff, p);
     422  CuAssertIntEquals(tc,3,ret);
     423
     424  p = sh_fifo_pop(&ff);
     425  CuAssertPtrNotNull(tc, p);
     426  CuAssertStrEquals(tc,"one", p);
     427  p = sh_fifo_pop(&ff);
     428  CuAssertPtrNotNull(tc, p);
     429  CuAssertStrEquals(tc,"two", p);
     430  p = sh_fifo_pop(&ff);
     431  CuAssertPtrNotNull(tc, p);
     432  CuAssertStrEquals(tc,"three", p);
     433  p = sh_fifo_pop(&ff);
     434  CuAssertPtrEquals(tc, NULL, p);
     435}
     436
     437#endif
     438
     439
     440
     441
Note: See TracChangeset for help on using the changeset viewer.