blob: e86aa9cae51e80e00fbe897516ccf3326a9c95ef [file] [log] [blame]
Rafael Espindola945d7f52014-11-21 05:15:41 +00001//===- 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
Rafael Espindola1aabf982015-06-16 23:29:49 +000010#include "llvm/ADT/STLExtras.h"
Rafael Espindola945d7f52014-11-21 05:15:41 +000011#include "llvm/Support/StreamingMemoryObject.h"
12#include "gtest/gtest.h"
Rafael Espindola945d7f52014-11-21 05:15:41 +000013#include <string.h>
14
15using namespace llvm;
16
17namespace {
18class NullDataStreamer : public DataStreamer {
19 size_t GetBytes(unsigned char *buf, size_t len) override {
20 memset(buf, 0, len);
21 return len;
22 }
23};
24}
25
26TEST(StreamingMemoryObject, Test) {
Rafael Espindola1aabf982015-06-16 23:29:49 +000027 auto DS = make_unique<NullDataStreamer>();
28 StreamingMemoryObject O(std::move(DS));
Rafael Espindola945d7f52014-11-21 05:15:41 +000029 EXPECT_TRUE(O.isValidAddress(32 * 1024));
30}
Derek Schufffcfd5ae2015-05-21 19:40:19 +000031
32TEST(StreamingMemoryObject, TestSetKnownObjectSize) {
Rafael Espindola1aabf982015-06-16 23:29:49 +000033 auto DS = make_unique<NullDataStreamer>();
34 StreamingMemoryObject O(std::move(DS));
Derek Schufffcfd5ae2015-05-21 19:40:19 +000035 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}