dte test coverage


Directory: ./
File: src/terminal/osc52.c
Date: 2025-11-12 12:04:10
Coverage Exec Excl Total
Lines: 100.0% 28 0 28
Functions: 100.0% 1 0 1
Branches: 75.0% 6 0 8

Line Branch Exec Source
1 #include <stdlib.h>
2 #include "osc52.h"
3 #include "output.h"
4 #include "util/base64.h"
5 #include "util/debug.h"
6 #include "util/xstring.h"
7
8 3 bool term_osc52_copy(TermOutputBuffer *output, StringView text, TermCopyFlags flags)
9 {
10 3 BUG_ON(flags == 0);
11 3 size_t bufsize = (text.length / 3 * 4) + 4;
12 3 char *buf = malloc(bufsize);
13
1/2
✓ Branch 4 → 5 taken 3 times.
✗ Branch 4 → 21 not taken.
3 if (unlikely(!buf)) {
14 return false;
15 }
16
17 3 size_t plen = !!(flags & TCOPY_PRIMARY);
18 3 size_t clen = !!(flags & TCOPY_CLIPBOARD);
19 3 char *start = term_output_reserve_space(output, 16);
20 3 char *end = xmempcpy4(start, STRN("\033]52;"), "p", plen, "c", clen, STRN(";"));
21 3 output->count += (end - start);
22
23
2/2
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 2 times.
3 if (unlikely(text.length == 0)) {
24 1 goto out;
25 }
26
27 2 size_t remainder = text.length % 3;
28 2 size_t ilen = 0;
29 2 size_t olen = 0;
30
1/2
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 15 not taken.
2 if (text.length >= 3) {
31 2 ilen = text.length - remainder;
32 2 BUG_ON(ilen == 0);
33 2 BUG_ON(ilen % 3 != 0);
34 2 olen = base64_encode_block(text.data, ilen, buf, bufsize);
35 }
36
37
2/2
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 18 taken 1 time.
2 if (remainder) {
38 1 base64_encode_final(text.data + ilen, remainder, buf + olen);
39 1 olen += 4;
40 }
41
42 2 term_put_bytes(output, buf, olen);
43
44 3 out:
45 3 free(buf);
46 3 term_put_literal(output, "\033\\");
47 3 return true;
48 }
49