* Move the include resolution functionality to matp - matp::MaterialParser now has a function resolveIncludes that returns a pair of status and resolve string. - all the include resolution classes are moved to matp private src. - matp::resolveIncludes is renamed to matp::resolveIncludesRecursively and only used internally. - added insertLineDirectives and insertLineDirectiveChecks in Config; add those in the CommandlineConfig. - moved output format to public use. Note: MaterialParser::resolveIncludes could take a includer instead of the materialFilePath, but i decided to go with the materialFilePath because the most common use case is resolving from the file's directory. This allows the parser to just create the default DirIncluder internally, and we don't need to expose it publicly. * add const to the buffer param
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
/*
|
|
* Copyright (C) 2019 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "DirIncluder.h"
|
|
|
|
using namespace utils;
|
|
using namespace matp;
|
|
|
|
const utils::Path root = utils::Path(__FILE__).getParent();
|
|
|
|
// TODO: these tests are disabled as they fail on CI, which needs investigation.
|
|
|
|
TEST(DirIncluder, DISABLED_IncludeNonexistent) {
|
|
DirIncluder includer;
|
|
{
|
|
IncludeResult i {
|
|
.includeName = CString("nonexistent.h")
|
|
};
|
|
bool success = includer(CString(""), i);
|
|
EXPECT_FALSE(success);
|
|
}
|
|
{
|
|
utils::CString includerFile((root + "Foo.h").getPath().c_str());
|
|
IncludeResult i {
|
|
.includeName = CString("nonexistent.h")
|
|
};
|
|
bool success = includer(includerFile, i);
|
|
EXPECT_FALSE(success);
|
|
}
|
|
}
|
|
|
|
TEST(DirIncluder, DISABLED_IncludeFile) {
|
|
DirIncluder includer;
|
|
includer.setIncludeDirectory(root);
|
|
|
|
IncludeResult result {
|
|
.includeName = CString("Foo.h")
|
|
};
|
|
bool success = includer(CString(""), result);
|
|
|
|
EXPECT_TRUE(success);
|
|
|
|
// The result's source should be set to the contents of the includer file.
|
|
EXPECT_STREQ("// test include file", result.text.c_str());
|
|
|
|
// The result's name should be set to the full path to the header file.
|
|
EXPECT_STREQ((root + "Foo.h").c_str(), result.name.c_str());
|
|
}
|
|
|
|
TEST(DirIncluder, DISABLED_IncludeFileFromIncluder) {
|
|
DirIncluder includer;
|
|
includer.setIncludeDirectory(root);
|
|
|
|
utils::CString includerFile((root + "Dir/Baz.h").c_str());
|
|
|
|
IncludeResult result {
|
|
.includeName = CString("Bar.h")
|
|
};
|
|
bool success = includer(includerFile, result);
|
|
|
|
EXPECT_STREQ("// Bar.h", result.text.c_str());
|
|
|
|
EXPECT_STREQ((root + "Dir/Bar.h").c_str(), result.name.c_str());
|
|
}
|