| 1 |
/* |
| 2 |
* Copyright (C) 2019 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <gtest/gtest.h> |
| 18 |
|
| 19 |
#include <matc/DirIncluder.h> |
| 20 |
|
| 21 |
using namespace utils; |
| 22 |
using namespace filamat; |
| 23 |
|
| 24 |
const utils::Path root = utils::Path(__FILE__).getParent(); |
| 25 |
|
| 26 |
// TODO: these tests are disabled as they fail on CI, which needs investigation. |
| 27 |
|
| 28 |
TEST(DirIncluder, DISABLED_IncludeNonexistent) { |
| 29 |
matc::DirIncluder includer; |
| 30 |
{ |
| 31 |
IncludeResult i { |
| 32 |
.includeName = CString("nonexistent.h") |
| 33 |
}; |
| 34 |
bool success = includer(CString(""), i); |
| 35 |
EXPECT_FALSE(success); |
| 36 |
} |
| 37 |
{ |
| 38 |
utils::CString includerFile((root + "Foo.h").getPath().c_str()); |
| 39 |
IncludeResult i { |
| 40 |
.includeName = CString("nonexistent.h") |
| 41 |
}; |
| 42 |
bool success = includer(includerFile, i); |
| 43 |
EXPECT_FALSE(success); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
TEST(DirIncluder, DISABLED_IncludeFile) { |
| 48 |
matc::DirIncluder includer; |
| 49 |
includer.setIncludeDirectory(root); |
| 50 |
|
| 51 |
IncludeResult result { |
| 52 |
.includeName = CString("Foo.h") |
| 53 |
}; |
| 54 |
bool success = includer(CString(""), result); |
| 55 |
|
| 56 |
EXPECT_TRUE(success); |
| 57 |
|
| 58 |
// The result's source should be set to the contents of the includer file. |
| 59 |
EXPECT_STREQ("// test include file", result.text.c_str()); |
| 60 |
|
| 61 |
// The result's name should be set to the full path to the header file. |
| 62 |
EXPECT_STREQ((root + "Foo.h").c_str(), result.name.c_str()); |
| 63 |
} |
| 64 |
|
| 65 |
TEST(DirIncluder, DISABLED_IncludeFileFromIncluder) { |
| 66 |
matc::DirIncluder includer; |
| 67 |
includer.setIncludeDirectory(root); |
| 68 |
|
| 69 |
utils::CString includerFile((root + "Dir/Baz.h").c_str()); |
| 70 |
|
| 71 |
IncludeResult result { |
| 72 |
.includeName = CString("Bar.h") |
| 73 |
}; |
| 74 |
bool success = includer(includerFile, result); |
| 75 |
|
| 76 |
EXPECT_STREQ("// Bar.h", result.text.c_str()); |
| 77 |
|
| 78 |
EXPECT_STREQ((root + "Dir/Bar.h").c_str(), result.name.c_str()); |
| 79 |
} |