62 lines · cpp
1//===- SymbolicFileTest.cpp - Tests for SymbolicFile.cpp ------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/Object/SymbolicFile.h"10#include "llvm/ADT/STLExtras.h"11#include "llvm/Support/raw_ostream.h"12#include "llvm/TargetParser/Host.h"13#include "gmock/gmock.h"14#include "gtest/gtest.h"15#include <sstream>16 17TEST(Object, DataRefImplOstream) {18 std::string s;19 llvm::raw_string_ostream OS(s);20 llvm::object::DataRefImpl Data;21 Data.d.a = 0xeeee0000;22 Data.d.b = 0x0000ffff;23 24 static_assert(sizeof Data.p == sizeof(uint64_t) ||25 sizeof Data.p == sizeof(uint32_t),26 "Test expected pointer type to be 32 or 64-bit.");27 28 char const *Expected;29 30 if (sizeof Data.p == sizeof(uint64_t)) {31 Expected = llvm::sys::IsLittleEndianHost32 ? "(0xffffeeee0000 (0xeeee0000, 0x0000ffff))"33 : "(0xeeee00000000ffff (0xeeee0000, 0x0000ffff))";34 }35 else {36 Expected = "(0xeeee0000 (0xeeee0000, 0x0000ffff))";37 }38 39 OS << Data;40 41 EXPECT_EQ(Expected, s);42}43 44struct ProxyContent {45 unsigned Index = 0;46 ProxyContent(unsigned Index) : Index(Index) {};47 void moveNext() { ++Index; }48 49 bool operator==(const ProxyContent &Another) const {50 return Index == Another.Index;51 }52};53 54TEST(Object, ContentIterator) {55 using Iter = llvm::object::content_iterator<ProxyContent>;56 auto Sequence = llvm::make_range(Iter(0u), Iter(10u));57 auto EvenSequence = llvm::make_filter_range(58 Sequence, [](auto &&PC) { return PC.Index % 2 == 0; });59 60 EXPECT_THAT(EvenSequence, testing::ElementsAre(0u, 2u, 4u, 6u, 8u));61}62