Skip to content

Commit

Permalink
Updated tests to Qt6
Browse files Browse the repository at this point in the history
Signed-off-by: peach280 <vaishnavibhandari.128@gmail.com>
  • Loading branch information
peach280 committed Jan 14, 2025
1 parent 38071a5 commit c3b9130
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
31 changes: 26 additions & 5 deletions avogadro/core/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ static std::vector<std::string> CustomElementSymbols;
static std::vector<std::string> CustomElementNames;

// Match carbon's radii
static double CustomElementCovalentRadius = element_covalent[6];
static double CustomElementVDWRadius = element_VDW[6];

static std::vector<double> CustomElementCovalentRadii;
static std::vector<double> CustomElementVDWRadii;
inline std::string encodeCustomElement(unsigned char atomicNumber)
{
std::string result;
Expand Down Expand Up @@ -101,6 +100,8 @@ class InitializeCustomElementTables
{
CustomElementSymbols.resize(CustomElementCount);
CustomElementNames.resize(CustomElementCount);
CustomElementCovalentRadii.resize(CustomElementCount, element_covalent[6]);
CustomElementVDWRadii.resize(CustomElementCount, element_VDW[6]);
std::string suffix;
for (unsigned char i = CustomElementMin; i <= CustomElementMax; ++i) {
suffix = encodeCustomElement(i);
Expand All @@ -113,7 +114,19 @@ class InitializeCustomElementTables
} CustomElementTableInitializer;

} // end anon namespace
void setCustomElementCovalentRadius(unsigned char atomicNumber, double radius)
{
if (isCustomElement(atomicNumber)) {
CustomElementCovalentRadii[atomicNumber - CustomElementMin] = radius;
}
}

void setCustomElementVDWRadius(unsigned char atomicNumber, double radius)
{
if (isCustomElement(atomicNumber)) {
CustomElementVDWRadii[atomicNumber - CustomElementMin] = radius;
}
}
unsigned char Elements::elementCount()
{
return element_count;
Expand Down Expand Up @@ -204,6 +217,8 @@ unsigned char Elements::guessAtomicNumber(const std::string& inputStr)

const char* Elements::name(unsigned char atomicNumber)
{
if (atomicNumber == 0)
return "Centroid";
if (atomicNumber < element_count)
return element_names[atomicNumber];
else if (isCustomElement(atomicNumber))
Expand All @@ -214,6 +229,8 @@ const char* Elements::name(unsigned char atomicNumber)

const char* Elements::symbol(unsigned char atomicNumber)
{
if (atomicNumber == 0)
return "Cen";
if (atomicNumber < element_count)
return element_symbols[atomicNumber];
else if (isCustomElement(atomicNumber))
Expand All @@ -224,6 +241,8 @@ const char* Elements::symbol(unsigned char atomicNumber)

double Elements::mass(unsigned char atomicNumber)
{
if (atomicNumber == 0)
return 0.0;
if (atomicNumber < element_count)
return element_masses[atomicNumber];
else
Expand All @@ -232,10 +251,12 @@ double Elements::mass(unsigned char atomicNumber)

double Elements::radiusVDW(unsigned char atomicNumber)
{
if (atomicNumber == 0)
return 0.0;
if (atomicNumber < element_count)
return element_VDW[atomicNumber];
else if (isCustomElement(atomicNumber))
return CustomElementVDWRadius;
return CustomElementVDWRadii[atomicNumber - CustomElementMin];
else
return element_VDW[0];
}
Expand All @@ -245,7 +266,7 @@ double Elements::radiusCovalent(unsigned char atomicNumber)
if (atomicNumber < element_count)
return element_covalent[atomicNumber];
else if (isCustomElement(atomicNumber))
return CustomElementCovalentRadius;
return CustomElementCovalentRadii[atomicNumber - CustomElementMin];
else
return element_covalent[0];
}
Expand Down
5 changes: 5 additions & 0 deletions avogadro/core/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <string>

namespace Avogadro::Core {
void setCustomElementCovalentRadius(unsigned char atomicNumber, double radius);


void setCustomElementVDWRadius(unsigned char atomicNumber, double radius);


const unsigned char element_count = 119; //!< from 0 to 118

Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ mark_as_advanced(AVOGADRO_DATA_ROOT)
# Add the tests for each module.
add_subdirectory(core)
add_subdirectory(io)
if(USE_QT AND QT_VERSION EQUAL 5)
if(USE_QT)
add_subdirectory(qtgui)
endif()
if(USE_OPENGL)
add_subdirectory(rendering)
if(USE_QT AND USE_VTK AND TEST_QTGL AND QT_VERSION EQUAL 5)
if(USE_QT AND USE_VTK AND TEST_QTGL)
add_subdirectory(qtopengl)
endif()
endif()
4 changes: 2 additions & 2 deletions tests/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}"
"${AvogadroLibs_BINARY_DIR}/avogadro/molequeue"
"${AvogadroLibs_SOURCE_DIR}/tests/core")

find_package(Qt5 COMPONENTS Widgets Network Test REQUIRED)
find_package(Qt6 COMPONENTS Widgets Network Test REQUIRED)

# Pull in MoleQueue for QtJson
find_package(MoleQueue REQUIRED NO_MODULE)
Expand Down Expand Up @@ -50,7 +50,7 @@ endforeach()
# Add a single executable for all of our tests.
add_executable(AvogadroQtGuiTests ${testSrcs})
target_link_libraries(AvogadroQtGuiTests Avogadro::QtGui Avogadro::MoleQueue
MoleQueueClient ${GTEST_BOTH_LIBRARIES} ${EXTRA_LINK_LIB} Qt5::Widgets Qt5::Test)
MoleQueueClient ${GTEST_BOTH_LIBRARIES} ${EXTRA_LINK_LIB} Qt6::Widgets Qt6::Test)

# Now add all of the tests, using the gtest_filter argument so that only those
# cases are run in each test invocation.
Expand Down
2 changes: 1 addition & 1 deletion tests/qtgui/filebrowsewidgettest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(FileBrowseWidgetTest, setFileName)

FileBrowseWidget widget;

QSignalSpy spy(&widget, SIGNAL(fileNameChanged(QString)));
QSignalSpy spy(&widget, &FileBrowseWidget::fileNameChanged);
widget.setFileName("some file");
EXPECT_EQ(1, spy.count());
EXPECT_STREQ("some file", qPrintable(spy.front().front().toString()));
Expand Down
27 changes: 16 additions & 11 deletions tests/qtgui/generichighlightertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ class GenericHighlighterHtml : public GenericHighlighter
current = current.next()) {
const QTextLayout* layout(current.layout());

foreach (const QTextLayout::FormatRange& range,
layout->additionalFormats()) {
const int startIdx = current.position() + range.start - selectionStart;
const int endIdx = startIdx + range.length;
if (endIdx <= 0 || startIdx >= endOfDocument)
continue;
tempCursor.setPosition(qMax(startIdx, 0));
tempCursor.setPosition(qMin(endIdx, endOfDocument),
QTextCursor::KeepAnchor);
tempCursor.setCharFormat(range.format);
}
// Assuming 'layout' is a valid QTextLayout pointer and 'tempCursor' is a QTextCursor
QList<QTextLayout::FormatRange> formats = layout->formats(); // Get the current formats

for (const QTextLayout::FormatRange& range : formats) {
const int startIdx = current.position() + range.start - selectionStart;
const int endIdx = startIdx + range.length;

// Check if the range is valid
if (endIdx <= 0 || startIdx >= endOfDocument)
continue;

// Set the cursor position and apply the character format
tempCursor.setPosition(qMax(startIdx, 0));
tempCursor.setPosition(qMin(endIdx, endOfDocument), QTextCursor::KeepAnchor);
tempCursor.setCharFormat(range.format);
}
}

// Reset the user states since they are not interesting
Expand Down
2 changes: 1 addition & 1 deletion tests/qtgui/inputgeneratortest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(InputGeneratorTest, exercise)
// Create a set of input options by setting defaults
QJsonObject inputOptions;
QJsonObject options;
foreach (const QString& optionName, userOptions.keys()) {
for (const QString& optionName : userOptions.keys()) {
EXPECT_TRUE(userOptions[optionName].isObject());
QJsonObject option(userOptions[optionName].toObject());
QString optionType(option["type"].toString());
Expand Down

0 comments on commit c3b9130

Please sign in to comment.