llvm.org GIT mirror llvm / 22bd547
Re-enable BinaryStreamTest.StreamReaderObject. This was failing because I was using memcmp to compare two objects that included padding bytes, which were uninitialized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296681 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
1 changed file(s) with 18 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
4545
4646 namespace {
4747
48 class DiscontiguousStream : public WritableBinaryStream {
48 class BrokenStream : public WritableBinaryStream {
4949 public:
50 DiscontiguousStream(MutableArrayRef Data, endianness Endian,
50 BrokenStream(MutableArrayRef Data, endianness Endian,
5151 uint32_t Align)
5252 : Data(Data), PartitionIndex(alignDown(Data.size() / 2, Align)),
5353 Endian(Endian) {}
168168 for (uint32_t I = 0; I < NumEndians; ++I) {
169169 auto InByteStream =
170170 llvm::make_unique(InputData, Endians[I]);
171 auto InBrokenStream = llvm::make_unique<DiscontiguousStream>(
171 auto InBrokenStream = llvm::make_unique<BrokenStream>(
172172 BrokenInputData, Endians[I], Align);
173173
174174 Streams[I * 2].Input = std::move(InByteStream);
183183 for (uint32_t I = 0; I < NumEndians; ++I) {
184184 Streams[I * 2].Output =
185185 llvm::make_unique(OutputData, Endians[I]);
186 Streams[I * 2 + 1].Output = llvm::make_unique<DiscontiguousStream>(
186 Streams[I * 2 + 1].Output = llvm::make_unique<BrokenStream>(
187187 BrokenOutputData, Endians[I], Align);
188188 }
189189 }
192192 for (uint32_t I = 0; I < NumEndians; ++I) {
193193 Streams[I * 2].Output =
194194 llvm::make_unique(InputData, Endians[I]);
195 Streams[I * 2 + 1].Output = llvm::make_unique<DiscontiguousStream>(
195 Streams[I * 2 + 1].Output = llvm::make_unique<BrokenStream>(
196196 BrokenInputData, Endians[I], Align);
197197 }
198198 }
201201 for (uint32_t I = 0; I < NumEndians; ++I) {
202202 Streams[I * 2].Input =
203203 llvm::make_unique(OutputData, Endians[I]);
204 Streams[I * 2 + 1].Input = llvm::make_unique<DiscontiguousStream>(
204 Streams[I * 2 + 1].Input = llvm::make_unique<BrokenStream>(
205205 BrokenOutputData, Endians[I], Align);
206206 }
207207 }
503503 }
504504 }
505505
506 TEST_F(BinaryStreamTest, DISABLED_StreamReaderObject) {
506 TEST_F(BinaryStreamTest, StreamReaderObject) {
507507 struct Foo {
508508 int X;
509509 double Y;
510510 char Z;
511
512 bool operator==(const Foo &Other) const {
513 return X == Other.X && Y == Other.Y && Z == Other.Z;
514 }
511515 };
512516
513517 std::vector Foos;
514518 Foos.push_back({-42, 42.42, 42});
515519 Foos.push_back({100, 3.1415, static_cast(-89)});
520 Foos.push_back({200, 2.718, static_cast(-12) });
516521
517522 const uint8_t *Bytes = reinterpret_cast(&Foos[0]);
518523
519 initializeInput(makeArrayRef(Bytes, 2 * sizeof(Foo)), alignof(Foo));
524 initializeInput(makeArrayRef(Bytes, 3 * sizeof(Foo)), alignof(Foo));
520525
521526 for (auto &Stream : Streams) {
522527 // 1. Reading object pointers.
523528 BinaryStreamReader Reader(*Stream.Input);
524529 const Foo *FPtrOut = nullptr;
525530 const Foo *GPtrOut = nullptr;
531 const Foo *HPtrOut = nullptr;
526532 ASSERT_NO_ERROR(Reader.readObject(FPtrOut));
527533 ASSERT_NO_ERROR(Reader.readObject(GPtrOut));
534 ASSERT_NO_ERROR(Reader.readObject(HPtrOut));
528535 EXPECT_EQ(0U, Reader.bytesRemaining());
529 EXPECT_EQ(0, ::memcmp(&Foos[0], FPtrOut, sizeof(Foo)));
530 EXPECT_EQ(0, ::memcmp(&Foos[1], GPtrOut, sizeof(Foo)));
536 EXPECT_EQ(Foos[0], *FPtrOut);
537 EXPECT_EQ(Foos[1], *GPtrOut);
538 EXPECT_EQ(Foos[2], *HPtrOut);
531539 }
532540 }
533541