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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include "alloc-util.h"
       4                 :            : #include "gcrypt-util.h"
       5                 :            : #include "macro.h"
       6                 :            : #include "string-util.h"
       7                 :            : 
       8                 :          4 : static void test_string_hashsum(void) {
       9                 :          4 :         _cleanup_free_ char *out1 = NULL, *out2 = NULL, *out3 = NULL, *out4 = NULL;
      10                 :            : 
      11         [ -  + ]:          4 :         assert_se(string_hashsum("asdf", 4, GCRY_MD_SHA224, &out1) == 0);
      12                 :            :         /* echo -n 'asdf' | sha224sum - */
      13         [ -  + ]:          4 :         assert_se(streq(out1, "7872a74bcbf298a1e77d507cd95d4f8d96131cbbd4cdfc571e776c8a"));
      14                 :            : 
      15         [ -  + ]:          4 :         assert_se(string_hashsum("asdf", 4, GCRY_MD_SHA256, &out2) == 0);
      16                 :            :         /* echo -n 'asdf' | sha256sum - */
      17         [ -  + ]:          4 :         assert_se(streq(out2, "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"));
      18                 :            : 
      19         [ -  + ]:          4 :         assert_se(string_hashsum("", 0, GCRY_MD_SHA224, &out3) == 0);
      20                 :            :         /* echo -n '' | sha224sum - */
      21         [ -  + ]:          4 :         assert_se(streq(out3, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"));
      22                 :            : 
      23         [ -  + ]:          4 :         assert_se(string_hashsum("", 0, GCRY_MD_SHA256, &out4) == 0);
      24                 :            :         /* echo -n '' | sha256sum - */
      25         [ -  + ]:          4 :         assert_se(streq(out4, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
      26                 :          4 : }
      27                 :            : 
      28                 :          4 : int main(int argc, char **argv) {
      29                 :          4 :         test_string_hashsum();
      30                 :            : 
      31                 :          4 :         return 0;
      32                 :            : }

Generated by: LCOV version 1.14