dte test coverage


Directory: ./
File: src/terminal/osc52.c
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 1 1 100.0%
Branches: 10 12 83.3%

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/macros.h"
7
8 3 bool term_osc52_copy(TermOutputBuffer *output, const char *text, size_t text_len, bool clipboard, bool primary)
9 {
10 3 BUG_ON(!clipboard && !primary);
11 3 size_t bufsize = (text_len / 3 * 4) + 4;
12 3 char *buf = malloc(bufsize);
13
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (unlikely(!buf)) {
14 return false;
15 }
16
17 3 term_put_literal(output, "\033]52;");
18
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (primary) {
19 2 term_put_byte(output, 'p');
20 }
21
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (clipboard) {
22 2 term_put_byte(output, 'c');
23 }
24 3 term_put_byte(output, ';');
25
26
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (unlikely(text_len == 0)) {
27 1 goto out;
28 }
29
30 2 size_t remainder = text_len % 3;
31 2 size_t ilen = 0;
32 2 size_t olen = 0;
33
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (text_len >= 3) {
34 2 ilen = text_len - remainder;
35 2 BUG_ON(ilen == 0);
36 2 BUG_ON(ilen % 3 != 0);
37 2 olen = base64_encode_block(text, ilen, buf, bufsize);
38 }
39
40
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (remainder) {
41 1 base64_encode_final(text + ilen, remainder, buf + olen);
42 1 olen += 4;
43 }
44
45 2 term_put_bytes(output, buf, olen);
46
47 3 out:
48 3 free(buf);
49 3 term_put_literal(output, "\033\\");
50 3 return true;
51 }
52