File: limit.cc

package info (click to toggle)
snapper 0.10.6-1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,136 kB
  • sloc: cpp: 24,846; ansic: 1,466; sh: 1,410; makefile: 511; python: 127; ruby: 90
file content (85 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE snapper

#include <boost/test/unit_test.hpp>

#include <locale>

#include <snapper/Exception.h>
#include "../client/utils/Limit.h"
#include "../client/utils/HumanString.h"


using namespace std;
using namespace snapper;


string
test(const char* loc, const string& s)
{
    locale::global(locale(loc));

    Limit limit(0.5);
    limit.parse(s);

    locale::global(locale::classic());

    ostringstream tmp;
    tmp << limit;
    return tmp.str();
}


BOOST_AUTO_TEST_CASE(parse1)
{
    BOOST_CHECK_EQUAL(test("en_US.UTF-8", "0.10"), "0.1");
    BOOST_CHECK_EQUAL(test("de_DE.UTF-8", "0.10"), "0.1");
    BOOST_CHECK_EQUAL(test("fr_FR.UTF-8", "0.10"), "0.1");
}


BOOST_AUTO_TEST_CASE(parse2)
{
    BOOST_CHECK_EQUAL(test("en_US.UTF-8", "2.5 GiB"), "2.50 GiB");
    BOOST_CHECK_EQUAL(test("de_DE.UTF-8", "2.5 GiB"), "2.50 GiB");
    BOOST_CHECK_EQUAL(test("fr_FR.UTF-8", "2.5 GiB"), "2.50 GiB");

    BOOST_CHECK_EQUAL(test("en_US.UTF-8", "2.5 gib"), "2.50 GiB");
    BOOST_CHECK_EQUAL(test("en_US.UTF-8", "2.5 gb"), "2.50 GiB");
}


BOOST_AUTO_TEST_CASE(error1)
{
    BOOST_CHECK_THROW(test("de_DE.UTF-8", "0,5"), Exception);
}


BOOST_AUTO_TEST_CASE(error2)
{
    BOOST_CHECK_THROW(test("de_DE.UTF-8", "2,5 GiB"), Exception);
    BOOST_CHECK_THROW(test("fr_FR.UTF-8", "2,5 Gio"), Exception);
}


BOOST_AUTO_TEST_CASE(test1)
{
    MaxUsedLimit used_limit(0.5);

    BOOST_CHECK(used_limit.is_enabled());

    BOOST_CHECK(used_limit.is_satisfied(1 * TiB, 0.45 * TiB));
    BOOST_CHECK(!used_limit.is_satisfied(1 * TiB, 0.55 * TiB));
}


BOOST_AUTO_TEST_CASE(test2)
{
    MinFreeLimit free_limit(0.2);

    BOOST_CHECK(free_limit.is_enabled());

    BOOST_CHECK(free_limit.is_satisfied(1 * TiB, 0.25 * TiB));
    BOOST_CHECK(!free_limit.is_satisfied(1 * TiB, 0.15 * TiB));
}