aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/IR/DebugInfoTest.cpp
blob: 1fa851e39ae98f4b616b553713c5e0460951fc28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//===- llvm/unittest/IR/DebugInfo.cpp - DebugInfo tests -------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/DebugInfo.h"
#include "gtest/gtest.h"

using namespace llvm;

namespace llvm {

static void PrintTo(const StringRef &S, ::std::ostream *os) {
  *os << "(" << (const void *)S.data() << "," << S.size() << ") = '";
  for (auto C : S)
    if (C)
      *os << C;
    else
      *os << "\\00";
  *os << "'";
}
static void PrintTo(const DIHeaderFieldIterator &I, ::std::ostream *os) {
  PrintTo(I.getCurrent(), os);
  *os << " in ";
  PrintTo(I.getHeader(), os);
}

} // end namespace llvm

namespace {

#define MAKE_FIELD_ITERATOR(S)                                                 \
  DIHeaderFieldIterator(StringRef(S, sizeof(S) - 1))
TEST(DebugInfoTest, DIHeaderFieldIterator) {
  ASSERT_EQ(DIHeaderFieldIterator(), DIHeaderFieldIterator());

  ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR(""));
  ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR(""));
  ASSERT_EQ("", *DIHeaderFieldIterator(""));

  ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff"));
  ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff"));
  ASSERT_EQ("stuff", *DIHeaderFieldIterator("stuff"));

  ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("st\0uff"));
  ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("st\0uff"));
  ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("st\0uff"));
  ASSERT_EQ("st", *MAKE_FIELD_ITERATOR("st\0uff"));
  ASSERT_EQ("uff", *++MAKE_FIELD_ITERATOR("st\0uff"));

  ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff\0"));
  ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff\0"));
  ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("stuff\0"));
  ASSERT_EQ("stuff", *MAKE_FIELD_ITERATOR("stuff\0"));
  ASSERT_EQ("", *++MAKE_FIELD_ITERATOR("stuff\0"));

  ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("\0stuff"));
  ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("\0stuff"));
  ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("\0stuff"));
  ASSERT_EQ("", *MAKE_FIELD_ITERATOR("\0stuff"));
  ASSERT_EQ("stuff", *++MAKE_FIELD_ITERATOR("\0stuff"));
}

} // end namespace