LCOV - code coverage report
Current view: top level - src/tests - literal.c (source / functions) Hit Total Coverage
Test: passgen-test.info Lines: 52 52 100.0 %
Date: 2024-11-29 06:05:05 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "passgen/pattern/literal.h"
       2             : #include "tests.h"
       3             : 
       4           1 : test_result test_literal_init(void) {
       5           1 :     passgen_pattern_literal literal = {0};
       6           1 :     memset(&literal, 1, sizeof(literal));
       7             : 
       8           1 :     passgen_pattern_literal_init(&literal);
       9           1 :     assert_eq(literal.count, 0);
      10           1 :     assert_eq(literal.tainted, 0);
      11             : 
      12           1 :     return test_ok;
      13             : }
      14             : 
      15           1 : test_result test_literal_append(void) {
      16             :     passgen_pattern_literal literal;
      17           1 :     const int32_t codepoints[] =
      18             :         {0xabcd, 0x1234, 0x65ac, 0xdaa0, 0xdead, 0xbeef, 0xcafe, 0};
      19             : 
      20           1 :     passgen_pattern_literal_init(&literal);
      21           1 :     assert_eq(literal.count, 0);
      22           1 :     assert_eq(literal.tainted, 0);
      23             : 
      24           8 :     for(size_t i = 0; i < 7; i++) {
      25           7 :         assert_eq(passgen_pattern_literal_append(&literal, codepoints[i]), 0);
      26           7 :         assert_eq(literal.count, i + 1);
      27           7 :         assert_eq(literal.tainted, 0);
      28             : 
      29          35 :         for(size_t j = 0; j <= i; j++) {
      30          28 :             assert_eq(literal.codepoints[j], codepoints[j]);
      31             :         }
      32             :     }
      33             : 
      34           1 :     return test_ok;
      35             : }
      36             : 
      37           1 : test_result test_literal_append_full(void) {
      38             :     passgen_pattern_literal literal;
      39           1 :     const int32_t codepoint = 0xabcd;
      40             : 
      41           1 :     passgen_pattern_literal_init(&literal);
      42           1 :     assert_eq(literal.count, 0);
      43           1 :     assert_eq(literal.tainted, 0);
      44             : 
      45           8 :     for(size_t i = 0; i < 7; i++) {
      46           7 :         assert_eq(passgen_pattern_literal_append(&literal, codepoint), 0);
      47             :     }
      48             : 
      49           1 :     assert_eq(passgen_pattern_literal_append(&literal, codepoint), 1);
      50           1 :     assert_eq(literal.count, 7);
      51           1 :     assert_eq(literal.tainted, 0);
      52             : 
      53           1 :     return test_ok;
      54             : }
      55             : 
      56           1 : test_result test_literal_taint(void) {
      57             :     passgen_pattern_literal literal;
      58             : 
      59           1 :     passgen_pattern_literal_init(&literal);
      60           1 :     assert_eq(literal.count, 0);
      61           1 :     assert_eq(literal.tainted, 0);
      62             : 
      63           1 :     passgen_pattern_literal_taint(&literal);
      64           1 :     assert_eq(literal.count, 0);
      65           1 :     assert_eq(literal.tainted, 1);
      66             : 
      67           1 :     return test_ok;
      68             : }
      69             : 
      70           1 : test_result test_literal_append_taint(void) {
      71             :     passgen_pattern_literal literal;
      72           1 :     const int32_t codepoint = 0xabcd;
      73             : 
      74           1 :     passgen_pattern_literal_init(&literal);
      75           1 :     assert_eq(literal.count, 0);
      76           1 :     assert_eq(literal.tainted, 0);
      77             : 
      78           6 :     for(size_t i = 0; i < 5; i++) {
      79           5 :         assert_eq(passgen_pattern_literal_append(&literal, codepoint), 0);
      80             :     }
      81             : 
      82           1 :     passgen_pattern_literal_taint(&literal);
      83           1 :     assert_eq(literal.count, 5);
      84           1 :     assert_eq(literal.tainted, 1);
      85             : 
      86           1 :     assert_eq(passgen_pattern_literal_append(&literal, codepoint), 1);
      87           1 :     assert_eq(literal.count, 5);
      88           1 :     assert_eq(literal.tainted, 1);
      89             : 
      90           1 :     return test_ok;
      91             : }

Generated by: LCOV version 1.14