LCOV - code coverage report
Current view: top level - lib/gltests - test-strnlen.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 18 21 85.7 %
Date: 2012-05-28 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 24 58.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2010-2012 Free Software Foundation, Inc.
       3                 :            :  * Written by Eric Blake
       4                 :            :  *
       5                 :            :  * This program is free software: you can redistribute it and/or modify
       6                 :            :  * it under the terms of the GNU General Public License as published by
       7                 :            :  * the Free Software Foundation; either version 3 of the License, or
       8                 :            :  * (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This program is distributed in the hope that it will be useful,
      11                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13                 :            :  * GNU General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU General Public License
      16                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      17                 :            : 
      18                 :            : #include <config.h>
      19                 :            : 
      20                 :            : #include <string.h>
      21                 :            : 
      22                 :            : #include "signature.h"
      23                 :            : SIGNATURE_CHECK (strnlen, size_t, (char const *, size_t));
      24                 :            : 
      25                 :            : #include <stdlib.h>
      26                 :            : 
      27                 :            : #include "zerosize-ptr.h"
      28                 :            : #include "macros.h"
      29                 :            : 
      30                 :            : int
      31                 :          1 : main (void)
      32                 :            : {
      33                 :            :   size_t i;
      34                 :          1 :   char *page_boundary = (char *) zerosize_ptr ();
      35         [ -  + ]:          1 :   if (!page_boundary)
      36                 :            :     {
      37                 :          0 :       page_boundary = malloc (0x1000);
      38         [ #  # ]:          0 :       ASSERT (page_boundary);
      39                 :          0 :       page_boundary += 0x1000;
      40                 :            :     }
      41                 :            : 
      42                 :            :   /* Basic behavior tests.  */
      43         [ -  + ]:          1 :   ASSERT (strnlen ("a", 0) == 0);
      44         [ -  + ]:          1 :   ASSERT (strnlen ("a", 1) == 1);
      45         [ -  + ]:          1 :   ASSERT (strnlen ("a", 2) == 1);
      46         [ -  + ]:          1 :   ASSERT (strnlen ("", 0x100000) == 0);
      47                 :            : 
      48                 :            :   /* Memory fence and alignment testing.  */
      49         [ +  + ]:        513 :   for (i = 0; i < 512; i++)
      50                 :            :     {
      51                 :        512 :       char *start = page_boundary - i;
      52                 :        512 :       size_t j = i;
      53                 :        512 :       memset (start, 'x', i);
      54                 :            :       do
      55                 :            :         {
      56         [ +  + ]:     131328 :           if (i != j)
      57                 :            :             {
      58                 :     130816 :               start[j] = 0;
      59         [ -  + ]:     130816 :               ASSERT (strnlen (start, i + j) == j);
      60                 :            :             }
      61         [ -  + ]:     131328 :           ASSERT (strnlen (start, i) == j);
      62         [ -  + ]:     131328 :           ASSERT (strnlen (start, j) == j);
      63                 :            :         }
      64         [ +  + ]:     131328 :       while (j--);
      65                 :            :     }
      66                 :            : 
      67                 :          1 :   return 0;
      68                 :            : }

Generated by: LCOV version 1.9