llvm/clang/unittests/AST/ASTImporterVisibilityTest.cpp

//===- unittest/AST/ASTImporterTest.cpp - AST node import test ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Type-parameterized tests for the correct import of Decls with different
// visibility.
//
//===----------------------------------------------------------------------===//

// Define this to have ::testing::Combine available.
// FIXME: Better solution for this?
#define GTEST_HAS_COMBINE

#include "ASTImporterFixtures.h"

namespace clang {
namespace ast_matchers {

BindableMatcher;

// Type parameters for type-parameterized test fixtures.
struct GetFunPattern {};
struct GetVarPattern {};
struct GetClassPattern {};
struct GetEnumPattern {};
struct GetTypedefNamePattern {};
struct GetFunTemplPattern {};
struct GetVarTemplPattern {};
struct GetClassTemplPattern {};

// Values for the value-parameterized test fixtures.
// FunctionDecl:
const auto *ExternF =;
const auto *StaticF =;
const auto *AnonF =;
// VarDecl:
const auto *ExternV =;
const auto *StaticV =;
const auto *AnonV =;
// CXXRecordDecl:
const auto *ExternC =;
const auto *AnonC =;
// EnumDecl:
const auto *ExternE =;
const auto *AnonE =;
const auto *ExternEC =;
const auto *AnonEC =;
// TypedefNameDecl:
const auto *ExternTypedef =;
const auto *AnonTypedef =;
const auto *ExternUsing =;
const auto *AnonUsing =;
// FunctionTemplateDecl:
const auto *ExternFT =;
const auto *StaticFT =;
const auto *AnonFT =;
// VarTemplateDecl:
const auto *ExternVT =;
const auto *StaticVT =;
const auto *AnonVT =;
// ClassTemplateDecl:
const auto *ExternCT =;
const auto *AnonCT =;

// First value in tuple: Compile options.
// Second value in tuple: Source code to be used in the test.
ImportVisibilityChainParams;
// Fixture to test the redecl chain of Decls with the same visibility. Gtest
// makes it possible to have either value-parameterized or type-parameterized
// fixtures. However, we cannot have both value- and type-parameterized test
// fixtures. This is a value-parameterized test fixture in the gtest sense. We
// intend to mimic gtest's type-parameters via the PatternFactory template
// parameter. We manually instantiate the different tests with the each types.
template <typename PatternFactory>
class ImportVisibilityChain
    : public ASTImporterTestBase, public ImportVisibilityChainParams {};

// Manual instantiation of the fixture with each type.
ImportFunctionsVisibilityChain;
ImportVariablesVisibilityChain;
ImportClassesVisibilityChain;
ImportScopedEnumsVisibilityChain;
ImportFunctionTemplatesVisibilityChain;
ImportVariableTemplatesVisibilityChain;
ImportClassTemplatesVisibilityChain;

// Value-parameterized test for functions.
TEST_P(ImportFunctionsVisibilityChain, ImportChain) {}
// Value-parameterized test for variables.
TEST_P(ImportVariablesVisibilityChain, ImportChain) {}
// Value-parameterized test for classes.
TEST_P(ImportClassesVisibilityChain, ImportChain) {}
// Value-parameterized test for scoped enums.
TEST_P(ImportScopedEnumsVisibilityChain, ImportChain) {}
// Value-parameterized test for function templates.
TEST_P(ImportFunctionTemplatesVisibilityChain, ImportChain) {}
// Value-parameterized test for variable templates.
TEST_P(ImportVariableTemplatesVisibilityChain, ImportChain) {}
// Value-parameterized test for class templates.
TEST_P(ImportClassTemplatesVisibilityChain, ImportChain) {}

// Automatic instantiation of the value-parameterized tests.
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

// First value in tuple: Compile options.
// Second value in tuple: Tuple with informations for the test.
// Code for first import (or initial code), code to import, whether the `f`
// functions are expected to be linked in a declaration chain.
// One value of this tuple is combined with every value of compile options.
// The test can have a single tuple as parameter only.
ImportVisibilityParams;

template <typename PatternFactory>
class ImportVisibility
    : public ASTImporterTestBase,
      public ImportVisibilityParams {};
ImportFunctionsVisibility;
ImportVariablesVisibility;
ImportClassesVisibility;
ImportEnumsVisibility;
ImportScopedEnumsVisibility;
ImportTypedefNameVisibility;
ImportFunctionTemplatesVisibility;
ImportVariableTemplatesVisibility;
ImportClassTemplatesVisibility;

// FunctionDecl.
TEST_P(ImportFunctionsVisibility, ImportAfter) {}
TEST_P(ImportFunctionsVisibility, ImportAfterImport) {}
// VarDecl.
TEST_P(ImportVariablesVisibility, ImportAfter) {}
TEST_P(ImportVariablesVisibility, ImportAfterImport) {}
// CXXRecordDecl.
TEST_P(ImportClassesVisibility, ImportAfter) {}
TEST_P(ImportClassesVisibility, ImportAfterImport) {}
// EnumDecl.
TEST_P(ImportEnumsVisibility, ImportAfter) {}
TEST_P(ImportEnumsVisibility, ImportAfterImport) {}
TEST_P(ImportScopedEnumsVisibility, ImportAfter) {}
TEST_P(ImportScopedEnumsVisibility, ImportAfterImport) {}
// TypedefNameDecl.
TEST_P(ImportTypedefNameVisibility, ImportAfter) {}
TEST_P(ImportTypedefNameVisibility, ImportAfterImport) {}
// FunctionTemplateDecl.
TEST_P(ImportFunctionTemplatesVisibility, ImportAfter) {}
TEST_P(ImportFunctionTemplatesVisibility, ImportAfterImport) {}
// VarTemplateDecl.
TEST_P(ImportVariableTemplatesVisibility, ImportAfter) {}
TEST_P(ImportVariableTemplatesVisibility, ImportAfterImport) {}
// ClassTemplateDecl.
TEST_P(ImportClassTemplatesVisibility, ImportAfter) {}
TEST_P(ImportClassTemplatesVisibility, ImportAfterImport) {}

const bool ExpectLinkedDeclChain =;
const bool ExpectUnlinkedDeclChain =;

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
} // end namespace ast_matchers
} // end namespace clang