mirror of
https://github.com/fraillt/bitsery.git
synced 2026-06-08 08:13:56 +00:00
compile warnings, and usage improvements for VisualStudio
This commit is contained in:
@@ -84,7 +84,7 @@ TEST(AdapterIOStream, ReadingMoreThanAvailableReturnsZero) {
|
||||
}
|
||||
|
||||
//this is strange, but probably stringstream doesnt use any of the base methods that sets io_base::iostate flags
|
||||
TEST(AdapterIOStream, WhenReadingStringStreamThenErrorCodeAlwaysReturnsNoError) {
|
||||
TEST(AdapterIOStream, WhenReadingMoreThanAvailableThenDataOverflow) {
|
||||
//setup data
|
||||
uint8_t t1 = 111;
|
||||
|
||||
@@ -103,7 +103,9 @@ TEST(AdapterIOStream, WhenReadingStringStreamThenErrorCodeAlwaysReturnsNoError)
|
||||
EXPECT_THAT(r.error(), Eq(bitsery::ReaderError::NoError));
|
||||
EXPECT_THAT(r1, Eq(t1));
|
||||
r.readBytes<1>(r1);
|
||||
r.readBytes<1>(r1);
|
||||
EXPECT_THAT(r1, Eq(0));
|
||||
//should by overflow error, but it all iostate flags are set to false...
|
||||
EXPECT_THAT(r.error(), Eq(bitsery::ReaderError::NoError));
|
||||
EXPECT_THAT(r.isCompletedSuccessfully(), Eq(false));
|
||||
EXPECT_THAT(r.error(), Eq(bitsery::ReaderError::DataOverflow));
|
||||
|
||||
}
|
||||
@@ -56,19 +56,19 @@ using InverseReader = bitsery::AdapterReader<InputAdapter, InverseEndiannessConf
|
||||
TEST(DataEndianness, WhenWriteBytesThenBytesAreSwapped) {
|
||||
//fill initial values
|
||||
IntegralTypes src{};
|
||||
src.a = 0x1122334455667788;
|
||||
src.a = static_cast<int64_t>(0x1122334455667788);
|
||||
src.b = 0xBBCCDDEE;
|
||||
src.c = 0xCCDD;
|
||||
src.d = 0xDD;
|
||||
src.e = 0xEE;
|
||||
src.c = static_cast<int16_t>(0xCCDD);
|
||||
src.d = static_cast<uint8_t>(0xDD);
|
||||
src.e = static_cast<int8_t>(0xEE);
|
||||
|
||||
//fill expected result after swap
|
||||
IntegralTypes resInv{};
|
||||
resInv.a = 0x8877665544332211;
|
||||
resInv.a = static_cast<int64_t>(0x8877665544332211);
|
||||
resInv.b = 0xEEDDCCBB;
|
||||
resInv.c = 0xDDCC;
|
||||
resInv.d = 0xDD;
|
||||
resInv.e = 0xEE;
|
||||
resInv.c = static_cast<int16_t>(0xDDCC);
|
||||
resInv.d = static_cast<uint8_t>(0xDD);
|
||||
resInv.e = static_cast<int8_t>(0xEE);
|
||||
|
||||
//create and write to buffer
|
||||
Buffer buf{};
|
||||
@@ -136,7 +136,7 @@ TEST(DataEndianness, WhenWriteMoreThan1ByteValuesThenValuesAreSwapped) {
|
||||
template <typename T>
|
||||
constexpr size_t getBits(T v) {
|
||||
return bitsery::details::calcRequiredBits<T>({}, v);
|
||||
};
|
||||
}
|
||||
|
||||
struct IntegralUnsignedTypes {
|
||||
uint64_t a;
|
||||
|
||||
@@ -43,7 +43,7 @@ struct IntegralUnsignedTypes {
|
||||
template <typename T>
|
||||
constexpr size_t getBits(T v) {
|
||||
return bitsery::details::calcRequiredBits<T>({}, v);
|
||||
};
|
||||
}
|
||||
|
||||
// *** bits operations
|
||||
|
||||
@@ -285,6 +285,53 @@ TEST(DataBitsAndBytesOperations, WriteAndReadBytes) {
|
||||
|
||||
}
|
||||
|
||||
TEST(DataBitsAndBytesOperations, WriteAndReadBytesWithBitPackingWrapper) {
|
||||
//setup data
|
||||
IntegralTypes data;
|
||||
data.a = -4894541654564;
|
||||
data.b = 94545646;
|
||||
data.c = -8778;
|
||||
data.d = 200;
|
||||
data.e = -98;
|
||||
data.f[0] = 43;
|
||||
data.f[1] = -45;
|
||||
|
||||
//create and write to buffer
|
||||
Buffer buf{};
|
||||
Writer bw{buf};
|
||||
AdapterBitPackingWriter bpw{bw};
|
||||
bpw.writeBytes<4>(data.b);
|
||||
bpw.writeBytes<2>(data.c);
|
||||
bpw.writeBytes<1>(data.d);
|
||||
bpw.writeBytes<8>(data.a);
|
||||
bpw.writeBytes<1>(data.e);
|
||||
bpw.writeBuffer<1>(data.f, 2);
|
||||
bpw.flush();
|
||||
auto writtenSize = bpw.writtenBytesCount();
|
||||
|
||||
EXPECT_THAT(writtenSize, Eq(18));
|
||||
//read from buffer
|
||||
Reader br{InputAdapter{buf.begin(), writtenSize}};
|
||||
AdapterBitPackingReader bpr{br};
|
||||
IntegralTypes res{};
|
||||
bpr.readBytes<4>(res.b);
|
||||
bpr.readBytes<2>(res.c);
|
||||
bpr.readBytes<1>(res.d);
|
||||
bpr.readBytes<8>(res.a);
|
||||
bpr.readBytes<1>(res.e);
|
||||
bpr.readBuffer<1>(res.f, 2);
|
||||
EXPECT_THAT(bpr.error(), Eq(bitsery::ReaderError::NoError));
|
||||
//assert results
|
||||
|
||||
EXPECT_THAT(data.a, Eq(res.a));
|
||||
EXPECT_THAT(data.b, Eq(res.b));
|
||||
EXPECT_THAT(data.c, Eq(res.c));
|
||||
EXPECT_THAT(data.d, Eq(res.d));
|
||||
EXPECT_THAT(data.e, Eq(res.e));
|
||||
EXPECT_THAT(data.f, ContainerEq(res.f));
|
||||
|
||||
}
|
||||
|
||||
TEST(DataBitsAndBytesOperations, ReadWriteFncCanAcceptSignedData) {
|
||||
//setup data
|
||||
constexpr size_t DATA_SIZE = 3;
|
||||
|
||||
@@ -114,8 +114,22 @@ TEST(DataReadingErrors, WhenInitializingSessionsWhereSessionsDataOffsetIsCorrupt
|
||||
SessionsEnabledWriter bw{buf};
|
||||
bw.writeBytes<1>(uint8_t{1});
|
||||
bw.writeBytes<1>(uint8_t{1});
|
||||
bw.writeBytes<2>(uint16_t{10});
|
||||
bw.writeBytes<4>(uint32_t{10});
|
||||
SessionsEnabledReader br{InputAdapter{buf.begin(), bw.writtenBytesCount()}};
|
||||
br.beginSession();
|
||||
EXPECT_THAT(br.error(), Eq(bitsery::ReaderError::InvalidData));
|
||||
}
|
||||
|
||||
TEST(DataReadingErrors, WhenReadingNewSessionOutsideSessionThenInvalidData) {
|
||||
Buffer buf{};
|
||||
SessionsEnabledWriter bw{buf};
|
||||
bw.beginSession();
|
||||
bw.writeBytes<1>(uint8_t{1});
|
||||
bw.endSession();
|
||||
bw.flush();
|
||||
SessionsEnabledReader br{InputAdapter{buf.begin(), bw.writtenBytesCount()}};
|
||||
br.beginSession();
|
||||
br.endSession();
|
||||
br.beginSession();
|
||||
EXPECT_THAT(br.error(), Eq(bitsery::ReaderError::InvalidData));
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST(FlexibleSyntax, FundamentalTypesAndBool) {
|
||||
float tf = 485.042f;
|
||||
double_t td = -454184.48445;
|
||||
bool tb=true;
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().archive(ti,te,tf,td,tb);
|
||||
|
||||
//result
|
||||
|
||||
@@ -33,7 +33,7 @@ using Deserializer = bitsery::BasicDeserializer<bitsery::AdapterReaderBitPacking
|
||||
|
||||
TEST(SerializeBooleans, BoolAsBit) {
|
||||
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
bool t1{true};
|
||||
bool t2{false};
|
||||
bool res1;
|
||||
|
||||
@@ -163,7 +163,7 @@ TYPED_TEST(SerializeContainerDynamicSizeCompositeTypes, CustomFunctionThatDoNoth
|
||||
SerializationContext ctx{};
|
||||
using TValue = typename TestFixture::TValue;
|
||||
|
||||
auto emptyFnc = [](TValue &v) {};
|
||||
auto emptyFnc = [](TValue &) {};
|
||||
ctx.createSerializer().container(this->src, 1000, emptyFnc);
|
||||
ctx.createDeserializer().container(this->res, 1000, emptyFnc);
|
||||
|
||||
@@ -217,7 +217,7 @@ TYPED_TEST(SerializeContainerFixedSizeCompositeTypes, DefaultSerializationFuncti
|
||||
Container src{MyStruct1{0, 1}, MyStruct1{8, 9}, MyStruct1{11, 34}, MyStruct1{5134, 1532}};
|
||||
Container res{};
|
||||
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().container(src);
|
||||
ctx.createDeserializer().container(res);
|
||||
|
||||
@@ -232,7 +232,7 @@ TYPED_TEST(SerializeContainerFixedSizeCompositeTypes, CustomFunctionThatSerializ
|
||||
|
||||
using TValue = decltype(*std::begin(res));
|
||||
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
auto& ser = ctx.createSerializer();
|
||||
ser.container(src, [&ser](TValue &v) {
|
||||
char tmp{};
|
||||
|
||||
@@ -37,9 +37,8 @@ using BPDes = bitsery::BasicDeserializer<bitsery::AdapterReaderBitPackingWrapper
|
||||
TEST(SerializeExtensionEntropy, WhenEntropyEncodedThenOnlyWriteIndexUsingMinRequiredBits) {
|
||||
int32_t v = 4849;
|
||||
int32_t res;
|
||||
constexpr size_t N = 3;
|
||||
int32_t values[3] = {485,4849,89};
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().enableBitPacking([&v, &values](BPSer& ser) {
|
||||
ser.ext4b(v, Entropy<int32_t[3]>{values});
|
||||
});
|
||||
@@ -50,12 +49,12 @@ TEST(SerializeExtensionEntropy, WhenEntropyEncodedThenOnlyWriteIndexUsingMinRequ
|
||||
EXPECT_THAT(res, Eq(v));
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(1));
|
||||
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
ctx1.createSerializer().enableBitPacking([&v, &values](BPSer& ser) {
|
||||
ser.ext4b(v, Entropy<int32_t[3]>{values});
|
||||
});
|
||||
ctx1.createDeserializer().enableBitPacking([&res](BPDes& des) {
|
||||
des.ext(res, bitsery::ext::ValueRange<int32_t>{0, static_cast<int32_t>(N + 1)});
|
||||
des.ext(res, bitsery::ext::ValueRange<int32_t>{0, static_cast<int32_t>(3 + 1)});
|
||||
});
|
||||
EXPECT_THAT(res, Eq(2));
|
||||
}
|
||||
@@ -64,7 +63,7 @@ TEST(SerializeExtensionEntropy, WhenNoEntropyEncodedThenWriteZeroBitsAndValueOrO
|
||||
int16_t v = 8945;
|
||||
int16_t res;
|
||||
std::initializer_list<int> values{485,4849,89};
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().enableBitPacking([&v, &values](BPSer& ser) {
|
||||
ser.ext2b(v, Entropy<std::initializer_list<int>>{values});
|
||||
});
|
||||
@@ -84,12 +83,12 @@ TEST(SerializeExtensionEntropy, CustomTypeEntropyEncoded) {
|
||||
MyStruct1 values[N]{
|
||||
MyStruct1{12, 10}, MyStruct1{485, 454},
|
||||
MyStruct1{4849, 89}, MyStruct1{0, 1}};
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().enableBitPacking([&v, &values](BPSer& ser) {
|
||||
ser.ext(v, Entropy<MyStruct1[N]>{values});
|
||||
ser.ext(v, Entropy<MyStruct1[4]>{values});
|
||||
});
|
||||
ctx.createDeserializer().enableBitPacking([&res, &values](BPDes& des) {
|
||||
des.ext(res, Entropy<MyStruct1[N]>{values});
|
||||
des.ext(res, Entropy<MyStruct1[4]>{values});
|
||||
});
|
||||
EXPECT_THAT(res, Eq(v));
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(1));
|
||||
@@ -102,7 +101,7 @@ TEST(SerializeExtensionEntropy, CustomTypeNotEntropyEncoded) {
|
||||
std::initializer_list<MyStruct1> values {
|
||||
MyStruct1{12,10}, MyStruct1{485, 454},
|
||||
MyStruct1{4849,89}, MyStruct1{0,1}};
|
||||
SerializationContext ctx;
|
||||
SerializationContext ctx{};
|
||||
ctx.createSerializer().enableBitPacking([&v, &values](BPSer& ser) {
|
||||
ser.ext(v, Entropy<std::initializer_list<MyStruct1>>{values});
|
||||
});
|
||||
|
||||
@@ -46,10 +46,15 @@ struct DataV3 {
|
||||
|
||||
TEST(SerializeExtensionGrowable, WriteSessionsDataAtBufferEndAfterFlush) {
|
||||
BasicSerializationContext<SessionsEnabledConfig> ctx;
|
||||
ctx.createSerializer().ext(int8_t{}, Growable{}, [] (int8_t& v) { });
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(0));
|
||||
auto& ser = ctx.createSerializer();
|
||||
//session cannot be empty
|
||||
ser.ext(int8_t{}, Growable{}, [&ser] (int8_t& v) {
|
||||
ser.value1b(v);
|
||||
});
|
||||
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(1));
|
||||
ctx.bw->flush();
|
||||
EXPECT_THAT(ctx.getBufferSize(), Gt(0));
|
||||
EXPECT_THAT(ctx.getBufferSize(), Gt(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ TEST(SerializeExtensionStdQueue, QueueDefaultContainer) {
|
||||
t1.push(-4854);
|
||||
std::queue<int32_t> r1{};
|
||||
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
test(ctx1,t1, r1);
|
||||
EXPECT_THAT(t1, Eq(r1));
|
||||
}
|
||||
@@ -67,7 +67,7 @@ TEST(SerializeExtensionStdQueue, QueueVectorContainer) {
|
||||
t1.push(-4854);
|
||||
std::queue<int32_t, std::vector<int32_t>> r1{};
|
||||
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
test(ctx1,t1, r1);
|
||||
EXPECT_THAT(t1, Eq(r1));
|
||||
}
|
||||
@@ -78,7 +78,7 @@ TEST(SerializeExtensionStdQueue, PriorityQueueDefaultContainer) {
|
||||
t1.push(-4854);
|
||||
std::priority_queue<int32_t> r1{};
|
||||
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
test(ctx1,t1, r1);
|
||||
auto & ct1 = PriorityQueueCnt<int32_t, std::vector<int32_t>>::getContainer(t1);
|
||||
auto & cr1 = PriorityQueueCnt<int32_t, std::vector<int32_t>>::getContainer(r1);
|
||||
@@ -91,7 +91,7 @@ TEST(SerializeExtensionStdQueue, PriorityQueueDequeContainer) {
|
||||
t1.push(-44);
|
||||
std::priority_queue<int32_t, std::deque<int32_t>> r1{};
|
||||
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
test(ctx1,t1, r1);
|
||||
auto & ct1 = PriorityQueueCnt<int32_t, std::deque<int32_t>>::getContainer(t1);
|
||||
auto & cr1 = PriorityQueueCnt<int32_t, std::deque<int32_t>>::getContainer(r1);
|
||||
|
||||
@@ -43,10 +43,10 @@ struct X {
|
||||
|
||||
struct Y {
|
||||
int y{};
|
||||
int carr[3];
|
||||
std::array<int, 3> arr;
|
||||
std::vector<X> vx;
|
||||
std::string s;
|
||||
int carr[3]{};
|
||||
std::array<int, 3> arr{};
|
||||
std::vector<X> vx{};
|
||||
std::string s{};
|
||||
};
|
||||
struct Z { X x{}; Y y{}; };
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ bool SerializeDeserializeContainerSize(SerializationContext& ctx, const size_t s
|
||||
}
|
||||
|
||||
TEST(SerializeSize, WhenLengthLessThan128Then1Byte) {
|
||||
SerializationContext ctx1;
|
||||
SerializationContext ctx1{};
|
||||
EXPECT_TRUE(SerializeDeserializeContainerSize(ctx1, 127));
|
||||
EXPECT_THAT(ctx1.getBufferSize(), Eq(1));
|
||||
SerializationContext ctx2;
|
||||
|
||||
@@ -100,13 +100,14 @@ using Reader = bitsery::AdapterReader<InputAdapter, bitsery::DefaultConfig>;
|
||||
template <typename Config = bitsery::DefaultConfig>
|
||||
class BasicSerializationContext {
|
||||
public:
|
||||
Buffer buf;
|
||||
using TWriter = bitsery::AdapterWriter<OutputAdapter, Config>;
|
||||
using TReader = bitsery::AdapterReader<InputAdapter, Config>;
|
||||
std::unique_ptr<bitsery::BasicSerializer<TWriter>> ser;
|
||||
std::unique_ptr<bitsery::BasicDeserializer<TReader>> des;
|
||||
TWriter* bw;
|
||||
TReader* br;
|
||||
|
||||
Buffer buf{};
|
||||
std::unique_ptr<bitsery::BasicSerializer<TWriter>> ser{};
|
||||
std::unique_ptr<bitsery::BasicDeserializer<TReader>> des{};
|
||||
TWriter* bw{};
|
||||
TReader* br{};
|
||||
|
||||
bitsery::BasicSerializer<TWriter>& createSerializer() {
|
||||
if (!ser) {
|
||||
|
||||
@@ -110,10 +110,12 @@ TEST(SerializeText, CArraySerializesTextLength) {
|
||||
EXPECT_THAT(r1, ContainerEq(t1));
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
TEST(SerializeText, WhenCArrayNotNullterminatedThenAssert) {
|
||||
SerializationContext ctx;
|
||||
char16_t t1[CARR_LENGTH]{u"some text"};
|
||||
//make last character not nullterminated
|
||||
t1[CARR_LENGTH-1] = 'x';
|
||||
EXPECT_DEATH(ctx.createSerializer().text<2>(t1), "");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user