This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nemomobile/staging
A bit more functionality and new soversion
- Loading branch information
Showing
10 changed files
with
229 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <qtaround/util.hpp> | ||
#include <qtaround/os.hpp> | ||
#include <tut/tut.hpp> | ||
#include "tests_common.hpp" | ||
#include <qtaround/util.hpp> | ||
|
||
#include <QDebug> | ||
#include <QVariant> | ||
|
||
namespace os = qtaround::os; | ||
namespace error = qtaround::error; | ||
namespace util = qtaround::util; | ||
|
||
namespace tut | ||
{ | ||
|
||
struct misc_test | ||
{ | ||
virtual ~misc_test() | ||
{ | ||
} | ||
}; | ||
|
||
typedef test_group<misc_test> tf; | ||
typedef tf::object object; | ||
tf vault_misc_test("misc"); | ||
|
||
enum test_ids { | ||
tid_visit = 1 | ||
, tid_zip | ||
, tid_parsebytes | ||
, tid_error | ||
}; | ||
|
||
template<> template<> | ||
void object::test<tid_visit>() | ||
{ | ||
QVariantMap src = { | ||
{"b1", true}, | ||
{"m1", map({{"s1", "Str 1"}})}, | ||
{"l1", list({false, "List str"})} | ||
}; | ||
QStringList expected = {"///" | ||
, "QString//QString/b1/bool/true" | ||
, "QString//QString/l1" | ||
, "QString//QString/m1" | ||
, "QString/l1/int/0/bool/false" | ||
, "QString/l1/int/1/QString/List str" | ||
, "QString/m1/QString/s1/QString/Str 1"}; | ||
|
||
QStringList dst; | ||
auto fn = [&dst](QVariant const &ctx, QVariant const &key | ||
, QVariant const &data) { | ||
auto k = str(key); | ||
QStringList v; | ||
v << ctx.typeName() << str(ctx) << key.typeName() << k; | ||
if (!(hasType(data, QMetaType::QVariantMap) | ||
|| hasType(data, QMetaType::QVariantList))) | ||
v << data.typeName() << str(data); | ||
dst << v.join("/"); | ||
return k; | ||
}; | ||
util::visit(fn, src, QVariant()); | ||
dst.sort(); | ||
expected.sort(); | ||
ensure_eq("Visited items", dst, expected); | ||
} | ||
|
||
template<> template<> | ||
void object::test<tid_zip>() | ||
{ | ||
QStringList l1, l2; | ||
l1 << "A"; | ||
l2 << "a"; | ||
auto res = util::zip(l1, l2); | ||
ensure_eq("Single item", res.size(), 1); | ||
l1 << "B"; | ||
res = util::zip(l1, l2); | ||
ensure_eq("2 items, 2nd empty", res.size(), 2); | ||
l2 << "b"; | ||
res = util::zip(l1, l2); | ||
ensure_eq("2 items", res.size(), 2); | ||
l2 << "c"; | ||
res = util::zip(l1, l2); | ||
ensure_eq("2 items, w/o 3rd", res.size(), 2); | ||
|
||
} | ||
|
||
template<> template<> | ||
void object::test<tid_parsebytes>() | ||
{ | ||
double res = util::parseBytes("10"); | ||
ensure_eq("plain bytes", res, 10); | ||
res = util::parseBytes("10K"); | ||
ensure_eq("10K", res, 1024 * 10); | ||
res = util::parseBytes("20Kb"); | ||
ensure_eq("10Kb", res, 1024 * 20); | ||
res = util::parseBytes("30kib"); | ||
ensure_eq("30Kb", res, 1024 * 30); | ||
res = util::parseBytes(" 40 kb "); | ||
ensure_eq("40K", res, 1024 * 40); | ||
|
||
ensure_throws<error::Error>("10 k b", &util::parseBytes, " 10 k b ", "b", 1024); | ||
|
||
res = util::parseBytes("50mb"); | ||
ensure_eq("50mb", res, 1024 * 1024 * 50); | ||
|
||
res = util::parseBytes("60Mib", "b", 1000); | ||
ensure_eq("60Mib", res, 1000 * 1000 * 60); | ||
|
||
res = util::parseBytes("70mb", "mb"); | ||
ensure_eq("70mb", res, 70); | ||
|
||
res = util::parseBytes("1024kb", "mb"); | ||
ensure_eq("1mb", res, 1); | ||
|
||
res = util::parseBytes("1024kb", "GB"); | ||
ensure_eq("1024kb=xGb", res, 1. / 1024.); | ||
} | ||
|
||
template<> template<> | ||
void object::test<tid_error>() | ||
{ | ||
try { | ||
error::raise({{"a", 1}, {"b", 2}}); | ||
} catch (error::Error const &e) { | ||
ensure_ne(AT, S_(e.what()), ""); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters