OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/err.h" | 6 #include "tools/gn/err.h" |
7 #include "tools/gn/label.h" | 7 #include "tools/gn/label.h" |
8 #include "tools/gn/value.h" | 8 #include "tools/gn/value.h" |
9 #include "tools/gn/visibility.h" | 9 #include "tools/gn/visibility.h" |
10 | 10 |
11 TEST(Visibility, CanSeeMe) { | 11 TEST(Visibility, CanSeeMe) { |
12 Value list(NULL, Value::LIST); | 12 Value list(NULL, Value::LIST); |
13 list.list_value().push_back(Value(NULL, "//rec/*")); // Recursive. | 13 list.list_value().push_back(Value(NULL, "//rec/*")); // Recursive. |
14 list.list_value().push_back(Value(NULL, "//dir:*")); // One dir. | 14 list.list_value().push_back(Value(NULL, "//dir:*")); // One dir. |
15 list.list_value().push_back(Value(NULL, "//my:name")); // Exact match. | 15 list.list_value().push_back(Value(NULL, "//my:name")); // Exact match. |
16 | 16 |
17 Err err; | 17 Err err; |
18 Visibility vis; | 18 Visibility vis; |
19 ASSERT_TRUE(vis.Set(SourceDir("//"), list, &err)); | 19 base::FilePath source_root("/source/root"); |
| 20 ASSERT_TRUE(vis.Set(source_root, SourceDir("//"), list, &err)); |
20 | 21 |
21 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); | 22 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); |
22 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//my/"), "notname"))); | 23 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//my/"), "notname"))); |
23 | 24 |
24 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//my/"), "name"))); | 25 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//my/"), "name"))); |
25 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/"), "anything"))); | 26 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/"), "anything"))); |
26 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/a/"), "anything"))); | 27 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/a/"), "anything"))); |
27 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/b/"), "anything"))); | 28 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//rec/b/"), "anything"))); |
28 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//dir/"), "anything"))); | 29 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//dir/"), "anything"))); |
29 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//dir/a/"), "anything"))); | 30 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//dir/a/"), "anything"))); |
30 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//directory/"), "anything"))); | 31 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//directory/"), "anything"))); |
31 } | 32 } |
32 | 33 |
33 TEST(Visibility, Public) { | 34 TEST(Visibility, Public) { |
34 Err err; | 35 Err err; |
35 Visibility vis; | 36 Visibility vis; |
| 37 base::FilePath source_root("/source/root"); |
36 | 38 |
37 Value list(NULL, Value::LIST); | 39 Value list(NULL, Value::LIST); |
38 list.list_value().push_back(Value(NULL, "*")); | 40 list.list_value().push_back(Value(NULL, "*")); |
39 ASSERT_TRUE(vis.Set(SourceDir("//"), list, &err)); | 41 ASSERT_TRUE(vis.Set(source_root, SourceDir("//"), list, &err)); |
40 | 42 |
41 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); | 43 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); |
42 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//"), ""))); | 44 EXPECT_TRUE(vis.CanSeeMe(Label(SourceDir("//"), ""))); |
43 } | 45 } |
44 | 46 |
45 TEST(Visibility, Private) { | 47 TEST(Visibility, Private) { |
46 Err err; | 48 Err err; |
47 Visibility vis; | 49 Visibility vis; |
48 ASSERT_TRUE(vis.Set(SourceDir("//"), Value(NULL, Value::LIST), &err)); | 50 base::FilePath source_root("/source/root"); |
| 51 ASSERT_TRUE(vis.Set(source_root, SourceDir("//"), Value(NULL, Value::LIST), |
| 52 &err)); |
49 | 53 |
50 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); | 54 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//random/"), "thing"))); |
51 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//"), ""))); | 55 EXPECT_FALSE(vis.CanSeeMe(Label(SourceDir("//"), ""))); |
52 } | 56 } |
OLD | NEW |