File: test.h

package info (click to toggle)
libept 1.2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 4,672 kB
  • sloc: cpp: 5,627; sh: 62; makefile: 17
file content (43 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef EPT_TEST_H
#define EPT_TEST_H

#include <ept/utils/tests.h>
#include <ept/config.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/error.h>
#include <apt-pkg/policy.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/progress.h>
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/init.h>
#include <cstdlib>

struct EnvOverride
{
    const char* name;
    bool old_value_set;
    std::string old_value;

    EnvOverride(const char* name, const char* value)
        : name(name)
    {
        const char* old = getenv(name);
        if (old)
        {
            old_value_set = true;
            old_value = old;
        } else
            old_value_set = false;
        setenv(name, value, 1);
    }
    ~EnvOverride()
    {
        if (old_value_set)
            setenv(name, old_value.c_str(), 1);
        else
            unsetenv(name);
    }
};

#endif