1 // Copyright 2012 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "includes_normalize.h"
24 TEST(IncludesNormalize, Simple) {
25 EXPECT_EQ("b", IncludesNormalize::Normalize("a\\..\\b", NULL));
26 EXPECT_EQ("b", IncludesNormalize::Normalize("a\\../b", NULL));
27 EXPECT_EQ("a/b", IncludesNormalize::Normalize("a\\.\\b", NULL));
28 EXPECT_EQ("a/b", IncludesNormalize::Normalize("a\\./b", NULL));
35 _getcwd(buf, sizeof(buf));
36 vector<string> parts = IncludesNormalize::Split(string(buf), '\\');
37 return parts[parts.size() - 1];
42 TEST(IncludesNormalize, WithRelative) {
43 string currentdir = GetCurDir();
44 EXPECT_EQ("c", IncludesNormalize::Normalize("a/b/c", "a/b"));
45 EXPECT_EQ("a", IncludesNormalize::Normalize(IncludesNormalize::AbsPath("a"),
47 EXPECT_EQ(string("../") + currentdir + string("/a"),
48 IncludesNormalize::Normalize("a", "../b"));
49 EXPECT_EQ(string("../") + currentdir + string("/a/b"),
50 IncludesNormalize::Normalize("a/b", "../c"));
51 EXPECT_EQ("../../a", IncludesNormalize::Normalize("a", "b/c"));
52 EXPECT_EQ(".", IncludesNormalize::Normalize("a", "a"));
55 TEST(IncludesNormalize, Case) {
56 EXPECT_EQ("b", IncludesNormalize::Normalize("Abc\\..\\b", NULL));
57 EXPECT_EQ("BdEf", IncludesNormalize::Normalize("Abc\\..\\BdEf", NULL));
58 EXPECT_EQ("A/b", IncludesNormalize::Normalize("A\\.\\b", NULL));
59 EXPECT_EQ("a/b", IncludesNormalize::Normalize("a\\./b", NULL));
60 EXPECT_EQ("A/B", IncludesNormalize::Normalize("A\\.\\B", NULL));
61 EXPECT_EQ("A/B", IncludesNormalize::Normalize("A\\./B", NULL));
64 TEST(IncludesNormalize, Join) {
66 EXPECT_EQ("", IncludesNormalize::Join(x, ':'));
68 EXPECT_EQ("alpha", IncludesNormalize::Join(x, ':'));
71 EXPECT_EQ("alpha:beta:gamma", IncludesNormalize::Join(x, ':'));
74 TEST(IncludesNormalize, Split) {
75 EXPECT_EQ("", IncludesNormalize::Join(IncludesNormalize::Split("", '/'),
77 EXPECT_EQ("a", IncludesNormalize::Join(IncludesNormalize::Split("a", '/'),
80 IncludesNormalize::Join(
81 IncludesNormalize::Split("a/b/c", '/'), ':'));
84 TEST(IncludesNormalize, ToLower) {
85 EXPECT_EQ("", IncludesNormalize::ToLower(""));
86 EXPECT_EQ("stuff", IncludesNormalize::ToLower("Stuff"));
87 EXPECT_EQ("stuff and things", IncludesNormalize::ToLower("Stuff AND thINGS"));
88 EXPECT_EQ("stuff 3and thin43gs",
89 IncludesNormalize::ToLower("Stuff 3AND thIN43GS"));
92 TEST(IncludesNormalize, DifferentDrive) {
94 IncludesNormalize::Normalize("p:\\vs08\\stuff.h", "p:\\vs08"));
96 IncludesNormalize::Normalize("P:\\Vs08\\stuff.h", "p:\\vs08"));
97 EXPECT_EQ("p:/vs08/stuff.h",
98 IncludesNormalize::Normalize("p:\\vs08\\stuff.h", "c:\\vs08"));
99 EXPECT_EQ("P:/vs08/stufF.h",
100 IncludesNormalize::Normalize("P:\\vs08\\stufF.h", "D:\\stuff/things"));
101 EXPECT_EQ("P:/vs08/stuff.h",
102 IncludesNormalize::Normalize("P:/vs08\\stuff.h", "D:\\stuff/things"));
103 EXPECT_EQ("P:/wee/stuff.h",
104 IncludesNormalize::Normalize("P:/vs08\\../wee\\stuff.h",
105 "D:\\stuff/things"));
108 TEST(IncludesNormalize, LongInvalidPath) {
109 const char kLongInputString[] =
110 "C:\\Program Files (x86)\\Microsoft Visual Studio "
111 "12.0\\VC\\INCLUDEwarning #31001: The dll for reading and writing the "
112 "pdb (for example, mspdb110.dll) could not be found on your path. This "
113 "is usually a configuration error. Compilation will continue using /Z7 "
114 "instead of /Zi, but expect a similar error when you link your program.";
115 // Too long, won't be canonicalized, but just don't crash.
116 EXPECT_EQ(kLongInputString,
117 IncludesNormalize::Normalize(kLongInputString, NULL));
119 const char kExactlyMaxPath[] =
146 std::string forward_slashes(kExactlyMaxPath);
147 std::replace(forward_slashes.begin(), forward_slashes.end(), '\\', '/');
148 // Make sure a path that's exactly _MAX_PATH long is canonicalized.
149 EXPECT_EQ(forward_slashes,
150 IncludesNormalize::Normalize(kExactlyMaxPath, NULL));