2023-01-29 11:48:18 -06:00
|
|
|
#include "storm/Big.hpp"
|
2023-01-23 22:10:24 -06:00
|
|
|
#include "storm/big/Ops.hpp"
|
|
|
|
|
#include "test/Test.hpp"
|
|
|
|
|
|
|
|
|
|
TEST_CASE("ExtractLowPart", "[big]") {
|
|
|
|
|
SECTION("extracts low part of 0") {
|
|
|
|
|
uint64_t value = 0;
|
|
|
|
|
auto low = ExtractLowPart(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0);
|
|
|
|
|
REQUIRE(value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("extracts low part of 0x12345678") {
|
|
|
|
|
uint64_t value = 0x12345678;
|
|
|
|
|
auto low = ExtractLowPart(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0x12345678);
|
|
|
|
|
REQUIRE(value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("extracts low part of 0xAAAABBBBCCCCDDDD") {
|
|
|
|
|
uint64_t value = 0xAAAABBBBCCCCDDDD;
|
|
|
|
|
auto low = ExtractLowPart(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0xCCCCDDDD);
|
|
|
|
|
REQUIRE(value == 0xAAAABBBB);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("ExtractLowPartSx", "[big]") {
|
|
|
|
|
SECTION("extracts low part of 0") {
|
|
|
|
|
uint64_t value = 0;
|
|
|
|
|
auto low = ExtractLowPartSx(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0);
|
|
|
|
|
REQUIRE(value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("extracts low part of 0x12345678") {
|
|
|
|
|
uint64_t value = 0x12345678;
|
|
|
|
|
auto low = ExtractLowPartSx(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0x12345678);
|
|
|
|
|
REQUIRE(value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("extracts low part of 0xAAAABBBBCCCCDDDD") {
|
|
|
|
|
uint64_t value = 0xAAAABBBBCCCCDDDD;
|
|
|
|
|
auto low = ExtractLowPartSx(value);
|
|
|
|
|
|
|
|
|
|
REQUIRE(low == 0xCCCCDDDD);
|
|
|
|
|
REQUIRE(value == 0xFFFFFFFFAAAABBBB);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("MakeLarge", "[big]") {
|
|
|
|
|
SECTION("creates uint64_t out of 0xAABBCCDD and 0x11223344") {
|
|
|
|
|
uint64_t value = MakeLarge(0xAABBCCDD, 0x11223344);
|
|
|
|
|
|
|
|
|
|
REQUIRE(value == 0x11223344AABBCCDD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("creates uint64_t out of 0 and 0x11223344") {
|
|
|
|
|
uint64_t value = MakeLarge(0x00000000, 0x11223344);
|
|
|
|
|
|
|
|
|
|
REQUIRE(value == 0x1122334400000000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-29 11:48:18 -06:00
|
|
|
|
|
|
|
|
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);
|
2023-01-29 20:14:01 -06:00
|
|
|
|
|
|
|
|
SBigDel(num);
|
2023-01-29 11:48:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SECTION("creates bigdata from 0x12345678") {
|
|
|
|
|
BigData* num;
|
|
|
|
|
SBigNew(&num);
|
|
|
|
|
SBigFromUnsigned(num, 0x12345678);
|
|
|
|
|
|
|
|
|
|
CHECK(num->Primary().Count() == 1);
|
|
|
|
|
CHECK(num->Primary()[0] == 0x12345678);
|
2023-01-29 20:14:01 -06:00
|
|
|
|
|
|
|
|
SBigDel(num);
|
2023-01-29 11:48:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2023-01-29 20:14:01 -06:00
|
|
|
|
|
|
|
|
SBigDel(num);
|
2023-01-29 11:48:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2023-01-29 20:14:01 -06:00
|
|
|
|
|
|
|
|
SBigDel(num);
|
2023-01-29 11:48:18 -06:00
|
|
|
}
|
|
|
|
|
}
|