-
Notifications
You must be signed in to change notification settings - Fork 3
/
filename_test.cc
136 lines (114 loc) · 3.79 KB
/
filename_test.cc
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2006 Google Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Author: [email protected] (Phil Sung)
#include "gtagsunit.h"
#include "filename.h"
#include "symboltable.h"
namespace {
TEST(FilenameTest, SymbolTableConstructor) {
SymbolTable table;
Filename f1("tools/tags/file.cc", &table);
EXPECT_EQ("tools/tags/file.cc", f1.Str());
Filename f2("tools/tags/", &table);
EXPECT_EQ("tools/tags/", f2.Str());
}
TEST(FilenameTest, SymbolTableCopyConstructor) {
SymbolTable table;
// Check that copy constructor works and that data is actually
// copied, not aliased
Filename* f1(new Filename("tools/tags/file.cc", &table));
Filename* f2(new Filename(*f1));
delete f1;
EXPECT_EQ("tools/tags/file.cc", f2->Str());
delete f2;
}
TEST(FilenameTest, NoSymbolTableConstructor) {
Filename f1("tools/tags/file.cc");
EXPECT_EQ("tools/tags/file.cc", f1.Str());
Filename f2("tools/tags/");
EXPECT_EQ("tools/tags/", f2.Str());
}
TEST(FilenameTest, NoSymbolTableCopyConstructor) {
// Check that copy constructor works and that data is actually
// copied, not aliased
Filename* f1(new Filename("tools/tags/file.cc"));
Filename* f2(new Filename(*f1));
delete f1;
EXPECT_EQ("tools/tags/file.cc", f2->Str());
delete f2;
}
TEST(FilenameTest, RemoveDotDirectories) {
SymbolTable table;
Filename f1("./tools/tags/./file.cc", &table);
EXPECT_EQ("tools/tags/file.cc", f1.Str());
}
TEST(FilenameTest, RootDirectory) {
SymbolTable table;
Filename f1(".", &table);
EXPECT_EQ(".", f1.Str());
Filename f2("./.", &table);
EXPECT_EQ(".", f1.Str());
}
TEST(FilenameTest, DirectoryDistance) {
SymbolTable table;
Filename f1(".", &table);
Filename f2("a1/a2/b1/b2/b3/file.cc", &table);
Filename f3("a1/a2/c1/c2/c3/c4/file.cc", &table);
EXPECT_EQ(5, f2.DistanceTo(f1));
EXPECT_EQ(5, f1.DistanceTo(f2));
EXPECT_EQ(7, f2.DistanceTo(f3));
EXPECT_EQ(7, f3.DistanceTo(f2));
}
TEST(FilenameTest, LessthanOperator) {
SymbolTable table;
Filename f1("tools/tags/file.cc", &table);
Filename f2("tools/tags/file.h", &table);
EXPECT_TRUE(f1 < f2);
EXPECT_FALSE(f2 < f1);
Filename f3("tools/tags/file.c");
Filename f4("tools/tags/file.cc");
EXPECT_TRUE(f3 < f4);
EXPECT_FALSE(f4 < f3);
Filename f5("tools/tags/file.cc", &table);
Filename f6("tools/tags/file.h");
EXPECT_TRUE(f5 < f6);
EXPECT_FALSE(f6 < f5);
}
TEST(FilenameTest, EqualityOperator) {
SymbolTable table;
Filename f1("tools/tags/file.cc", &table);
Filename f2("tools/tags/file.cc");
Filename f3("tools/tags/file.h", &table);
// f1 ought to not equal f2 for our test to be meaningful
EXPECT_NE(&f1, &f2);
EXPECT_TRUE(f1 == f1);
EXPECT_TRUE(f1 == f2);
EXPECT_TRUE(f1 != f3);
EXPECT_TRUE(f2 != f3);
}
TEST(FilenameTest, Basename) {
SymbolTable table;
Filename f1("tools/tags/file.cc", &table);
EXPECT_STREQ(f1.Basename(), "file.cc");
Filename f2("tools/tags/", &table);
EXPECT_STREQ(f2.Basename(), "tags");
Filename f3(".");
EXPECT_EQ(f3.Basename(), static_cast<const char*>(NULL));
Filename f4("////", &table);
EXPECT_EQ(f4.Basename(), static_cast<const char*>(NULL));
}
} // namespace