"Fossies" - the Fresh Open Source Software Archive 
Member "seafile-client-7.0.4/tests/test_utils.cpp" (19 Nov 2019, 4025 Bytes) of package /linux/www/seafile-client-7.0.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include "test_utils.h"
2 #include <QtTest/QtTest>
3 #include <algorithm> // std::sort
4
5 #include "../src/utils/utils.h"
6
7 namespace {
8
9 bool digitalCompareFileByName(const QString& a, const QString& b)
10 {
11 return digitalCompare(a, b) < 0 ? true : false;
12 }
13
14 } // namespace
15
16 void Utils::testReadableFileSize() {
17 QCOMPARE(::readableFileSize(0), QString("0B"));
18 QCOMPARE(::readableFileSize(1000), QString("1KB"));
19 QCOMPARE(::readableFileSize(1500), QString("2KB"));
20 QCOMPARE(::readableFileSize(1000000), QString("1.0MB"));
21 QCOMPARE(::readableFileSize(1230000), QString("1.2MB"));
22 QCOMPARE(::readableFileSize(1000 * 1000 * 1000), QString("1.0GB"));
23 QCOMPARE(::readableFileSize(1100 * 1000 * 1000), QString("1.1GB"));
24 }
25
26
27 void Utils::testIncludeUrlParams() {
28 QUrl urla(QString("http://example.com"));
29
30 QHash<QString, QString> params;
31 params.insert("simple", "c");
32 params.insert("withspecial", "a?b");
33 params.insert("withspace", "a b");
34 params.insert("username", "a123fx b");
35 params.insert("password", "!@#+-$%^12&*()qweqesaf\"';`~");
36 params.insert("withplus", "a+b");
37
38 QUrl urlb = ::includeQueryParams(urla, params);
39
40 QCOMPARE(urla.scheme(), urlb.scheme());
41 QCOMPARE(urla.host(), urlb.host());
42
43 Q_FOREACH (const QString& key, params.keys()) {
44 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
45 QString encoded_key = QUrl::toPercentEncoding(key);
46 QString encoded_value = QUrl::toPercentEncoding(params[encoded_key]);
47 QUrlQuery query = QUrlQuery(urlb.query());
48 QCOMPARE(query.queryItemValue(encoded_key, QUrl::FullyEncoded), encoded_value);
49 #else
50 QCOMPARE(urlb.queryItemValue(key), params[key]);
51 #endif
52 }
53 }
54
55 void Utils::testDigitalCompare() {
56 QList<QString> list;
57 list << "05 copy 2.ico" << "05 copy 3.ico"
58 << "05 copy.ico" << "05.ico"
59 << "34th TOPIK Papers - Advanced level 2.pdf"
60 << "34th TOPIK Papers - Advanced level.pdf"
61 << "A1/" << "B1/" << "a2/" << "b2/"
62 << "IMG_20140523_171911 - 副本.jpg"
63 << "IMG_20140523_171911.jpg"
64 << "MIT18_06SCF11_Ses3.1sum.pdf" << "Paraffin.exe"
65 << "Screen Shot 2016-08-13 at 11.42.35 PM.png"
66 << "Screen Shot 2016-09-02 at 4.47.12 PM.png"
67 << "WixDependencyExtension.dll"
68 << "darice - 副本 - 副本.cub"
69 << "darice - 副本.cub" << "darice.cub"
70 << "depends.chm" << "depends.exe"
71 << "dokan-build - 副本.log" << "dokan-build.log"
72 << "dokan-build copy 2 - 副本(2).log"
73 << "dokan-build copy 2 - 副本.log"
74 << "dokan-build copy 2.log"
75 << "dokan-build copy 3.log"
76 << "dokan-build copy.log"
77 << "heat.exe" << "heat.exe.config"
78 << "new copy.txt" << "new.txt"
79 << "require(1).js" << "require.js"
80 << "subfolder1/" << "untitled folder/"
81 << "whole-stage-codegen.pdf" << "wix.dll"
82 << "x copy 10.md" << "x copy.md"
83 << "x copy 2.md" << "x copy 3.md"
84 << "新建文本文档.txt"
85 << "新建文本文档 copy.txt"
86 << "新建文本文档 - 副本.txt"
87 << "新建文本文档(2).txt"
88 << "新建文本文档(3).txt";
89 std::sort(list.begin(), list.end(), digitalCompareFileByName);
90
91 QCOMPARE(::digitalCompare("9", "9"), 0);
92 QCOMPARE(::digitalCompare("aa9aa", "aa9aa"), 0);
93 QCOMPARE(::digitalCompare("99a99", "99a99"), 0);
94 QCOMPARE(::digitalCompare("9", "11"), -2);
95 QCOMPARE(::digitalCompare("1.9", "1.11"), -2);
96 QCOMPARE(::digitalCompare("1 9", "1 11"), -2);
97 QCOMPARE(::digitalCompare("1abc1", "1abc1.abc"), -1);
98 QCOMPARE(::digitalCompare("1.1.1.1.9", "1.1.1.1.11"), -2);
99 QCOMPARE(::digitalCompare("a9", "a11"), -2);
100 QCOMPARE(::digitalCompare("a9aaa", "a11aaa"), -2);
101 QCOMPARE(::digitalCompare("zzz9", "bbb11"), QString::compare("zzz9", "bbb11"));
102 QCOMPARE(::digitalCompare("pp9p", "pa11a"), QString::compare("pp9p", "pa11a"));
103 }
104
105 QTEST_APPLESS_MAIN(Utils)