-
Notifications
You must be signed in to change notification settings - Fork 256
/
test_edit.cc
160 lines (142 loc) · 3.55 KB
/
test_edit.cc
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#if defined(HAVE_MINGW)
#include "include/bareos.h"
#include "gtest/gtest.h"
#else
#include "gtest/gtest.h"
#include "include/bareos.h"
#endif
#include "lib/edit.h"
TEST(edit, format_1k)
{
ASSERT_STREQ(SizeAsSiPrefixFormat(1).c_str(), "1");
ASSERT_STREQ(SizeAsSiPrefixFormat(1024).c_str(), "1 k");
ASSERT_STREQ(SizeAsSiPrefixFormat(1048576).c_str(), "1 m");
ASSERT_STREQ(SizeAsSiPrefixFormat(1073741824).c_str(), "1 g");
ASSERT_STREQ(SizeAsSiPrefixFormat(1099511627776).c_str(), "1 t");
ASSERT_STREQ(SizeAsSiPrefixFormat(1125899906842624).c_str(), "1 p");
ASSERT_STREQ(SizeAsSiPrefixFormat(1152921504606846976).c_str(), "1 e");
ASSERT_STREQ(
SizeAsSiPrefixFormat(1152921504606846976 + 1125899906842624 +
1099511627776 + 1073741824 + 1048576 + 1024 + 1)
.c_str(),
"1 e 1 p 1 t 1 g 1 m 1 k 1");
}
// kibibyte
TEST(edit, k)
{
char str[] = "1 k";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1024);
}
// kilobyte
TEST(edit, kb)
{
char str[] = "1 kb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000);
}
TEST(edit, kB)
{
char str[] = "1 KB";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000);
}
// mebibyte
TEST(edit, m)
{
char str[] = "1 m";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1024 * 1024);
}
// megabyte
TEST(edit, mb)
{
char str[] = "1 mb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000 * 1000);
}
// gibibyte
TEST(edit, g)
{
char str[] = "1 g";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1024 * 1024 * 1024);
}
// gigabyte
TEST(edit, gb)
{
char str[] = "1 gb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000 * 1000 * 1000);
}
// tebibyte
TEST(edit, t)
{
char str[] = "1 t";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1099511627776);
}
// terabyte
TEST(edit, tb)
{
char str[] = "1 tb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000000000000);
}
// pebibyte
TEST(edit, p)
{
char str[] = "1 p";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1125899906842624);
}
// petabyte
TEST(edit, pb)
{
char str[] = "1 pb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000000000000000);
}
// exbibyte
TEST(edit, e)
{
char str[] = "1 e";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1152921504606846976);
}
// exabyte
TEST(edit, eb)
{
char str[] = "1 eb";
uint64_t retvalue = 0;
size_to_uint64(str, &retvalue);
ASSERT_EQ(retvalue, 1000000000000000000);
}