-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathTest_IncludeScanner.cpp
116 lines (93 loc) · 2.75 KB
/
Test_IncludeScanner.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "IncludeScanner.hpp"
#include "MemAllocLinear.hpp"
#include "MemAllocHeap.hpp"
#include "TestHarness.hpp"
using namespace t2;
class IncludeScannerTest : public ::testing::Test
{
protected:
MemAllocHeap heap;
MemAllocLinear alloc;
protected:
void SetUp() override
{
HeapInit(&heap);
LinearAllocInit(&alloc, &heap, 10 * 1024 * 1024, "Test Allocator");
}
void TearDown() override
{
LinearAllocDestroy(&alloc);
HeapDestroy(&heap);
}
};
TEST_F(IncludeScannerTest, EmptyFile)
{
char data[1] = { '\0' };
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_EQ(nullptr, incs);
}
TEST_F(IncludeScannerTest, SingleIncludeNewline)
{
char data[] = "#include \"foo.h\"\n";
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_NE(nullptr, incs);
ASSERT_STREQ("foo.h", incs->m_String);
ASSERT_EQ(5, incs->m_StringLen);
ASSERT_EQ(false, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_EQ(nullptr, incs->m_Next);
}
TEST_F(IncludeScannerTest, NoClosingTerminator)
{
char data[] = "#include <bar.h\n";
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_EQ(nullptr, incs);
}
TEST_F(IncludeScannerTest, SingleIncludeNoNewLine)
{
char data[] = "#include <bar.h>";
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_NE(nullptr, data);
ASSERT_STREQ("bar.h", incs->m_String);
ASSERT_EQ(5, incs->m_StringLen);
ASSERT_EQ(true, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_EQ(nullptr, incs->m_Next);
}
TEST_F(IncludeScannerTest, MaxWhitespace)
{
char data[] = "\n\n # include <bar.h> \n\n";
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_NE(nullptr, data);
ASSERT_STREQ("bar.h", incs->m_String);
ASSERT_EQ(5, incs->m_StringLen);
ASSERT_EQ(true, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_EQ(nullptr, incs->m_Next);
}
TEST_F(IncludeScannerTest, MultiIncludes)
{
char data[] =
"#include <foo.h>\n"
"#include \"a.h\"\n"
"#include <foo/bar/baz.h>\n";
IncludeData* incs = ScanIncludesCpp(data, &alloc);
ASSERT_NE(nullptr, data);
ASSERT_STREQ("foo.h", incs->m_String);
ASSERT_EQ(5, incs->m_StringLen);
ASSERT_EQ(true, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_NE(nullptr, incs->m_Next);
incs = incs->m_Next;
ASSERT_STREQ("a.h", incs->m_String);
ASSERT_EQ(3, incs->m_StringLen);
ASSERT_EQ(false, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_NE(nullptr, incs->m_Next);
incs = incs->m_Next;
ASSERT_STREQ("foo/bar/baz.h", incs->m_String);
ASSERT_EQ(13, incs->m_StringLen);
ASSERT_EQ(true, incs->m_IsSystemInclude);
ASSERT_EQ(true, incs->m_ShouldFollow);
ASSERT_EQ(nullptr, incs->m_Next);
}