Skip to content

[core] Move TClass tests to core/meta #19586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/clingutils/res/TClingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#ifndef ROOT_TMetaUtils
#define ROOT_TMetaUtils

#include "RConversionRuleParser.h"

#include <functional>
#include <set>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cctype>

#include "RConfigure.h"
#include "RConversionRuleParser.h"
#include <ROOT/RConfig.hxx>
#include <ROOT/FoundationUtils.hxx>
#include "Rtypes.h"
Expand Down
2 changes: 1 addition & 1 deletion core/clingutils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if(NOT builtin_clang)
link_directories("${LLVM_LIBRARY_DIR}")
endif()

ROOT_ADD_UNITTEST_DIR(Core RIO ${CLING_LIBRARIES} $<TARGET_OBJECTS:ClingUtils>)
ROOT_ADD_UNITTEST_DIR(Core ${CLING_LIBRARIES} $<TARGET_OBJECTS:ClingUtils>)
35 changes: 13 additions & 22 deletions core/clingutils/test/TClingUtilsTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
*************************************************************************/

#include <TClingUtils.h>
#include <TClass.h>
#include <TInterpreter.h>

// This test must under no circumstances include other ROOT headers. It must not call into Cling, TInterpreter, TClass.
// It is meant for unit testing of TClingUtils and statically links ClingUtils and Cling/Clang/LLVM libraries. If the
// test was to do any of the above, there would be two copies of functions around (in libCling.so and the test binary)
// with not much guarantees which ones are called at which moment.

#include <DllImport.h>
#include <ROOT/FoundationUtils.hxx>

#include "gtest/gtest.h"

#include <fstream>
#include <deque>

TEST(TClingUtilsTests, GetCppName)
{
Expand Down Expand Up @@ -89,24 +92,12 @@ TEST(TClingUtilsTests, GetRealPath)
#endif // not R__WIN32
}

TEST(TClingUtilsTests, CollectionSizeof)
{
// https://its.cern.ch/jira/browse/ROOT-9889
EXPECT_EQ(sizeof(std::deque<short>), TClass::GetClass("std::deque<short>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned short>), TClass::GetClass("std::deque<unsigned short>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<int>), TClass::GetClass("std::deque<int>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned int>), TClass::GetClass("std::deque<unsigned int>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<long>), TClass::GetClass("std::deque<long>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned long>), TClass::GetClass("std::deque<unsigned long>")->GetClassSize());
}
// Forward-declare gCling to not include TInterpreter.h just for checking that the interpreter has not been initialized.
class TInterpreter;
R__EXTERN TInterpreter *gCling;

TEST(TClingUtilsTests, ReSubstTemplateArg)
{
// #18811
gInterpreter->Declare("template <typename T> struct S {};"
"template <typename T1, typename T2> struct Two { using value_type = S<T2>; };"
"template <typename T> struct One { Two<int, int>::value_type *t; };");
class InterpreterCheck : public testing::Environment {
void TearDown() override { ASSERT_EQ(gCling, nullptr); }
};

auto c = TClass::GetClass("One<std::string>");
c->BuildRealData();
}
testing::Environment *gInterpreterCheck = testing::AddGlobalTestEnvironment(new InterpreterCheck);
1 change: 1 addition & 0 deletions core/dictgen/src/XMLReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "XMLReader.h"
#include "RConversionRuleParser.h"
#include "SelectionRules.h"
#include "TClingUtils.h"

Expand Down
1 change: 1 addition & 0 deletions core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "rootclingCommandLineOptionsHelp.h"

#include "RConfigure.h"
#include "RConversionRuleParser.h"
#include <ROOT/RConfig.hxx>
#include <ROOT/FoundationUtils.hxx>
#include "snprintf.h"
Expand Down
24 changes: 24 additions & 0 deletions core/meta/test/testTClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "gtest/gtest.h"

#include <deque>

TEST(TClass, DictCheck)
{
gInterpreter->ProcessLine(".L stlDictCheck.h+");
Expand Down Expand Up @@ -80,3 +82,25 @@ TEST(TClass, ConsistentSTLLookup)
auto second = first->GetActualClass(&map);
EXPECT_EQ(first, second);
}

TEST(TClass, CollectionSizeof)
{
// https://its.cern.ch/jira/browse/ROOT-9889
EXPECT_EQ(sizeof(std::deque<short>), TClass::GetClass("std::deque<short>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned short>), TClass::GetClass("std::deque<unsigned short>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<int>), TClass::GetClass("std::deque<int>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned int>), TClass::GetClass("std::deque<unsigned int>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<long>), TClass::GetClass("std::deque<long>")->GetClassSize());
EXPECT_EQ(sizeof(std::deque<unsigned long>), TClass::GetClass("std::deque<unsigned long>")->GetClassSize());
}

TEST(TClass, ReSubstTemplateArg)
{
// #18811
gInterpreter->Declare("template <typename T> struct S {};"
"template <typename T1, typename T2> struct Two { using value_type = S<T2>; };"
"template <typename T> struct One { Two<int, int>::value_type *t; };");

auto c = TClass::GetClass("One<std::string>");
c->BuildRealData();
}
1 change: 1 addition & 0 deletions core/metacling/src/TClingCallbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "TClingCallbacks.h"

#include <DllImport.h> // for R__EXTERN
#include <ROOT/FoundationUtils.hxx>

#include "cling/Interpreter/DynamicLibraryManager.h"
Expand Down
Loading