LCOV - code coverage report
Current view: top level - test - test-format-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 26 26 100.0 %
Date: 2019-08-23 13:36:53 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 16 75.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include "format-util.h"
       4                 :            : #include "macro.h"
       5                 :            : #include "string-util.h"
       6                 :            : 
       7                 :         60 : static void test_format_bytes_one(uint64_t val, bool trailing_B, const char *iec_with_p, const char *iec_without_p,
       8                 :            :                                   const char *si_with_p, const char *si_without_p) {
       9                 :            :         char buf[FORMAT_BYTES_MAX];
      10                 :            : 
      11   [ +  +  -  + ]:         60 :         assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_with_p));
      12   [ +  +  -  + ]:         60 :         assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_without_p));
      13   [ +  +  -  + ]:         60 :         assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), si_with_p));
      14   [ +  +  -  + ]:         60 :         assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, trailing_B ? FORMAT_BYTES_TRAILING_B : 0), si_without_p));
      15                 :         60 : }
      16                 :            : 
      17                 :          4 : static void test_format_bytes(void) {
      18                 :          4 :         test_format_bytes_one(900, true, "900B", "900B", "900B", "900B");
      19                 :          4 :         test_format_bytes_one(900, false, "900", "900", "900", "900");
      20                 :          4 :         test_format_bytes_one(1023, true, "1023B", "1023B", "1.0K", "1K");
      21                 :          4 :         test_format_bytes_one(1023, false, "1023", "1023", "1.0K", "1K");
      22                 :          4 :         test_format_bytes_one(1024, true, "1.0K", "1K", "1.0K", "1K");
      23                 :          4 :         test_format_bytes_one(1024, false, "1.0K", "1K", "1.0K", "1K");
      24                 :          4 :         test_format_bytes_one(1100, true, "1.0K", "1K", "1.1K", "1K");
      25                 :          4 :         test_format_bytes_one(1500, true, "1.4K", "1K", "1.5K", "1K");
      26                 :          4 :         test_format_bytes_one(UINT64_C(3)*1024*1024, true, "3.0M", "3M", "3.1M", "3M");
      27                 :          4 :         test_format_bytes_one(UINT64_C(3)*1024*1024*1024, true, "3.0G", "3G", "3.2G", "3G");
      28                 :          4 :         test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024, true, "3.0T", "3T", "3.2T", "3T");
      29                 :          4 :         test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024, true, "3.0P", "3P", "3.3P", "3P");
      30                 :          4 :         test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024*1024, true, "3.0E", "3E", "3.4E", "3E");
      31                 :          4 :         test_format_bytes_one(UINT64_MAX, true, NULL, NULL, NULL, NULL);
      32                 :          4 :         test_format_bytes_one(UINT64_MAX, false, NULL, NULL, NULL, NULL);
      33                 :          4 : }
      34                 :            : 
      35                 :          4 : int main(void) {
      36                 :          4 :         test_format_bytes();
      37                 :            : 
      38                 :          4 :         return 0;
      39                 :            : }

Generated by: LCOV version 1.14