Coverage Report

Created: 2026-04-12 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/testsuite/testsuite-binary.c
Line
Count
Source
1
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
2
 */
3
4
#include "lib.h"
5
#include "mempool.h"
6
#include "imem.h"
7
#include "array.h"
8
#include "strfuncs.h"
9
#include "unlink-directory.h"
10
11
#include "sieve.h"
12
#include "sieve-common.h"
13
#include "sieve-script.h"
14
#include "sieve-binary.h"
15
#include "sieve-error.h"
16
17
#include "testsuite-common.h"
18
#include "testsuite-binary.h"
19
20
#include <sys/stat.h>
21
#include <sys/types.h>
22
23
/*
24
 * State
25
 */
26
27
static char *testsuite_binary_tmp = NULL;
28
29
/*
30
 * Initialization
31
 */
32
33
void testsuite_binary_init(void)
34
0
{
35
0
  testsuite_binary_tmp = i_strconcat(testsuite_tmp_dir_get(),
36
0
             "/binaries", NULL);
37
38
0
  if (mkdir(testsuite_binary_tmp, 0700) < 0) {
39
0
    i_fatal("failed to create temporary directory '%s': %m",
40
0
      testsuite_binary_tmp);
41
0
  }
42
0
}
43
44
void testsuite_binary_deinit(void)
45
0
{
46
0
  const char *error;
47
48
0
  if (unlink_directory(testsuite_binary_tmp, UNLINK_DIRECTORY_FLAG_RMDIR,
49
0
           &error) < 0) {
50
0
    i_warning("failed to remove temporary directory '%s': %s",
51
0
        testsuite_binary_tmp, error);
52
0
  }
53
54
0
  i_free(testsuite_binary_tmp);
55
0
}
56
57
void testsuite_binary_reset(void)
58
0
{
59
0
  testsuite_binary_init();
60
0
  testsuite_binary_deinit();
61
0
}
62
63
/*
64
 * Binary Access
65
 */
66
67
bool testsuite_binary_save(struct sieve_binary *sbin, const char *name)
68
0
{
69
0
  return (sieve_save_as(sbin,
70
0
            t_strdup_printf("%s/%s", testsuite_binary_tmp,
71
0
                sieve_binfile_from_name(name)),
72
0
            TRUE, 0600, NULL) > 0);
73
0
}
74
75
struct sieve_binary *testsuite_binary_load(const char *name)
76
0
{
77
0
  struct sieve_instance *svinst = testsuite_sieve_instance;
78
0
  struct sieve_binary *sbin;
79
80
0
  if (sieve_load(svinst, t_strdup_printf("%s/%s", testsuite_binary_tmp,
81
0
                 sieve_binfile_from_name(name)),
82
0
           &sbin, NULL) < 0)
83
0
    return NULL;
84
0
  return sbin;
85
0
}