3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Formatter/ByteSizeFormatter.hpp"
24 #include "Util/Macros.hpp"
25 #include "Util/StringUtil.hpp"
26 #include "TestUtil.hpp"
29 main(int argc
, char **argv
)
35 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 0);
36 ok1(StringIsEqual(buffer
, _T("0 B")));
38 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1);
39 ok1(StringIsEqual(buffer
, _T("1 B")));
41 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 9);
42 ok1(StringIsEqual(buffer
, _T("9 B")));
44 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10);
45 ok1(StringIsEqual(buffer
, _T("10 B")));
47 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345);
48 ok1(StringIsEqual(buffer
, _T("345 B")));
51 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024);
52 ok1(StringIsEqual(buffer
, _T("1.00 KB")));
54 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 + 512);
55 ok1(StringIsEqual(buffer
, _T("1.50 KB")));
57 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 9 * 1024);
58 ok1(StringIsEqual(buffer
, _T("9.00 KB")));
60 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10 * 1024);
61 ok1(StringIsEqual(buffer
, _T("10.0 KB")));
63 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345 * 1024);
64 ok1(StringIsEqual(buffer
, _T("345 KB")));
67 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024);
68 ok1(StringIsEqual(buffer
, _T("1.00 MB")));
70 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024 + 512 * 1024);
71 ok1(StringIsEqual(buffer
, _T("1.50 MB")));
73 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 9 * 1024 * 1024);
74 ok1(StringIsEqual(buffer
, _T("9.00 MB")));
76 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10 * 1024 * 1024);
77 ok1(StringIsEqual(buffer
, _T("10.0 MB")));
79 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345 * 1024 * 1024);
80 ok1(StringIsEqual(buffer
, _T("345 MB")));
83 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024 * 1024);
84 ok1(StringIsEqual(buffer
, _T("1.00 GB")));
87 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 0, true);
88 ok1(StringIsEqual(buffer
, _T("0B")));
90 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1, true);
91 ok1(StringIsEqual(buffer
, _T("1B")));
93 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10, true);
94 ok1(StringIsEqual(buffer
, _T("10B")));
96 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345, true);
97 ok1(StringIsEqual(buffer
, _T("345B")));
100 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024, true);
101 ok1(StringIsEqual(buffer
, _T("1.0K")));
103 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 + 512, true);
104 ok1(StringIsEqual(buffer
, _T("1.5K")));
106 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 9 * 1024, true);
107 ok1(StringIsEqual(buffer
, _T("9.0K")));
109 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10 * 1024, true);
110 ok1(StringIsEqual(buffer
, _T("10.0K")));
112 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345 * 1024, true);
113 ok1(StringIsEqual(buffer
, _T("345K")));
116 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024, true);
117 ok1(StringIsEqual(buffer
, _T("1.0M")));
119 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024 + 512 * 1024, true);
120 ok1(StringIsEqual(buffer
, _T("1.5M")));
122 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 9 * 1024 * 1024, true);
123 ok1(StringIsEqual(buffer
, _T("9.0M")));
125 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 10 * 1024 * 1024, true);
126 ok1(StringIsEqual(buffer
, _T("10.0M")));
128 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 345 * 1024 * 1024, true);
129 ok1(StringIsEqual(buffer
, _T("345M")));
132 FormatByteSize(buffer
, ARRAY_SIZE(buffer
), 1 * 1024 * 1024 * 1024, true);
133 ok1(StringIsEqual(buffer
, _T("1.0G")));
136 return exit_status();