mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(big): add SBigFromUnsigned, SBigNew, and SBigToBinaryBuffer
This commit is contained in:
parent
630e6dbb1f
commit
7d5a157162
10 changed files with 211 additions and 0 deletions
48
test/Big.cpp
48
test/Big.cpp
|
|
@ -1,3 +1,4 @@
|
|||
#include "storm/Big.hpp"
|
||||
#include "storm/big/Ops.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
|
|
@ -66,3 +67,50 @@ TEST_CASE("MakeLarge", "[big]") {
|
|||
REQUIRE(value == 0x1122334400000000);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SBigFromUnsigned", "[big]") {
|
||||
SECTION("creates bigdata from 0") {
|
||||
BigData* num;
|
||||
SBigNew(&num);
|
||||
SBigFromUnsigned(num, 0);
|
||||
|
||||
CHECK(num->Primary().Count() == 1);
|
||||
CHECK(num->Primary()[0] == 0);
|
||||
}
|
||||
|
||||
SECTION("creates bigdata from 0x12345678") {
|
||||
BigData* num;
|
||||
SBigNew(&num);
|
||||
SBigFromUnsigned(num, 0x12345678);
|
||||
|
||||
CHECK(num->Primary().Count() == 1);
|
||||
CHECK(num->Primary()[0] == 0x12345678);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SBigToBinaryBuffer", "[big]") {
|
||||
SECTION("returns expected buffer for bigdata representing 0") {
|
||||
BigData* num;
|
||||
SBigNew(&num);
|
||||
SBigFromUnsigned(num, 0);
|
||||
|
||||
uint8_t buffer[4];
|
||||
uint32_t bytes;
|
||||
SBigToBinaryBuffer(num, buffer, sizeof(buffer), &bytes);
|
||||
|
||||
REQUIRE(bytes == 0);
|
||||
}
|
||||
|
||||
SECTION("returns expected buffer for bigdata representing 0x12345678") {
|
||||
BigData* num;
|
||||
SBigNew(&num);
|
||||
SBigFromUnsigned(num, 0x12345678);
|
||||
|
||||
uint8_t buffer[4];
|
||||
uint32_t bytes;
|
||||
SBigToBinaryBuffer(num, buffer, sizeof(buffer), &bytes);
|
||||
|
||||
CHECK(bytes == 4);
|
||||
CHECK(*reinterpret_cast<uint32_t*>(buffer) == 0x12345678);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue