Rafael Espindola | 945d7f5 | 2014-11-21 05:15:41 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/StreamingMemoryObject.cpp - unit tests -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Support/StreamingMemoryObject.h" |
| 11 | #include "gtest/gtest.h" |
Rafael Espindola | 945d7f5 | 2014-11-21 05:15:41 +0000 | [diff] [blame] | 12 | #include <string.h> |
| 13 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | namespace { |
| 17 | class NullDataStreamer : public DataStreamer { |
| 18 | size_t GetBytes(unsigned char *buf, size_t len) override { |
| 19 | memset(buf, 0, len); |
| 20 | return len; |
| 21 | } |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | TEST(StreamingMemoryObject, Test) { |
| 26 | auto *DS = new NullDataStreamer(); |
| 27 | StreamingMemoryObject O(DS); |
| 28 | EXPECT_TRUE(O.isValidAddress(32 * 1024)); |
| 29 | } |
Derek Schuff | fcfd5ae | 2015-05-21 19:40:19 +0000 | [diff] [blame^] | 30 | |
| 31 | TEST(StreamingMemoryObject, TestSetKnownObjectSize) { |
| 32 | auto *DS = new NullDataStreamer(); |
| 33 | StreamingMemoryObject O(DS); |
| 34 | uint8_t Buf[32]; |
| 35 | EXPECT_EQ((uint64_t) 16, O.readBytes(Buf, 16, 0)); |
| 36 | O.setKnownObjectSize(24); |
| 37 | EXPECT_EQ((uint64_t) 8, O.readBytes(Buf, 16, 16)); |
| 38 | } |