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/ADT/STLExtras.h"
11 #include "llvm/Support/StreamingMemoryObject.h"
12 #include "gtest/gtest.h"
13 #include <string.h>
14
15 using namespace llvm;
16
17 namespace {
18 class NullDataStreamer : public DataStreamer {
GetBytes(unsigned char * buf,size_t len)19 size_t GetBytes(unsigned char *buf, size_t len) override {
20 memset(buf, 0, len);
21 return len;
22 }
23 };
24 }
25
TEST(StreamingMemoryObject,Test)26 TEST(StreamingMemoryObject, Test) {
27 auto DS = make_unique<NullDataStreamer>();
28 StreamingMemoryObject O(std::move(DS));
29 EXPECT_TRUE(O.isValidAddress(32 * 1024));
30 }
31
TEST(StreamingMemoryObject,TestSetKnownObjectSize)32 TEST(StreamingMemoryObject, TestSetKnownObjectSize) {
33 auto DS = make_unique<NullDataStreamer>();
34 StreamingMemoryObject O(std::move(DS));
35 uint8_t Buf[32];
36 EXPECT_EQ((uint64_t) 16, O.readBytes(Buf, 16, 0));
37 O.setKnownObjectSize(24);
38 EXPECT_EQ((uint64_t) 8, O.readBytes(Buf, 16, 16));
39 }
40