LCOV - code coverage report
Current view: top level - test - test-device-nodes.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 21 21 100.0 %
Date: 2019-08-23 13:36:53 Functions: 4 4 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 <sys/types.h>
       4                 :            : 
       5                 :            : #include "alloc-util.h"
       6                 :            : #include "device-nodes.h"
       7                 :            : #include "string-util.h"
       8                 :            : #include "util.h"
       9                 :            : 
      10                 :            : /* helpers for test_encode_devnode_name */
      11                 :         24 : static char *do_encode_string(const char *in) {
      12                 :         24 :         size_t out_len = strlen(in) * 4 + 1;
      13                 :         24 :         char *out = malloc(out_len);
      14                 :            : 
      15         [ -  + ]:         24 :         assert_se(out);
      16         [ -  + ]:         24 :         assert_se(encode_devnode_name(in, out, out_len) >= 0);
      17                 :         24 :         puts(out);
      18                 :            : 
      19                 :         24 :         return out;
      20                 :            : }
      21                 :            : 
      22                 :         24 : static bool expect_encoded_as(const char *in, const char *expected) {
      23                 :         24 :         _cleanup_free_ char *encoded = do_encode_string(in);
      24                 :         24 :         return streq(encoded, expected);
      25                 :            : }
      26                 :            : 
      27                 :          4 : static void test_encode_devnode_name(void) {
      28         [ -  + ]:          4 :         assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
      29         [ -  + ]:          4 :         assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
      30         [ -  + ]:          4 :         assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
      31         [ -  + ]:          4 :         assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
      32         [ -  + ]:          4 :         assert_se(expect_encoded_as("/", "\\x2f"));
      33         [ -  + ]:          4 :         assert_se(expect_encoded_as("!", "\\x21"));
      34                 :          4 : }
      35                 :            : 
      36                 :          4 : int main(int argc, char *argv[]) {
      37                 :          4 :         test_encode_devnode_name();
      38                 :            : 
      39                 :          4 :         return 0;
      40                 :            : }

Generated by: LCOV version 1.14