Skip to content

Commit 28425b6

Browse files
committed
BioByteArray: add tests for new methods
1 parent 60aefea commit 28425b6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/test_biobytearray.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class test_biobytearray: public QObject
1919
void add();
2020
void bio_ro();
2121
void bio_wr();
22+
void bio_BN();
23+
void bio_base64UrlEncode();
2224
};
2325

2426
void test_biobytearray::set()
@@ -62,5 +64,36 @@ void test_biobytearray::bio_wr()
6264
QCOMPARE(ba.size(), sizeof "Suppengrüneinlage" -1);
6365
}
6466

67+
void test_biobytearray::bio_BN()
68+
{
69+
BIGNUM *bn = nullptr;
70+
BN_hex2bn(&bn, "1234567890abcdef");
71+
BioByteArray ba(bn, 64);
72+
BioByteArray bb(bn, 80);
73+
74+
QCOMPARE(ba.byteArray().size(), 8);
75+
QCOMPARE(ba.byteArray(), QByteArray::fromHex("1234567890abcdef"));
76+
QCOMPARE(bb.byteArray().size(), 10);
77+
QCOMPARE(bb.byteArray(), QByteArray::fromHex("00001234567890abcdef"));
78+
79+
BN_hex2bn(&bn, "7FFFFFFF");
80+
BioByteArray bc(bn);
81+
QCOMPARE(bc.byteArray().size(), 4);
82+
QCOMPARE(bc.byteArray(), QByteArray::fromHex("7fffffff"));
83+
84+
BN_hex2bn(&bn, "80000000");
85+
BioByteArray bd(bn);
86+
QCOMPARE(bd.byteArray().size(), 5);
87+
QCOMPARE(bd.byteArray(), QByteArray::fromHex("0080000000"));
88+
}
89+
90+
void test_biobytearray::bio_base64UrlEncode()
91+
{
92+
BioByteArray ba("Suppe");
93+
QCOMPARE(ba.base64UrlEncode(), QString("U3VwcGU"));
94+
BioByteArray bb(QByteArray::fromBase64("abc+def/ghijAA=="));
95+
QCOMPARE(bb.base64UrlEncode(), QString("abc-def_ghijAA"));
96+
}
97+
6598
QTEST_MAIN(test_biobytearray)
6699
#include "test_biobytearray.moc"

0 commit comments

Comments
 (0)