Skip to content

Commit

Permalink
Tests: Dummy PyMOLGlobals
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrettSJohnson committed Jan 30, 2024
1 parent f1d95e9 commit 4e3097f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
29 changes: 29 additions & 0 deletions layerCTest/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include "Test.h"
#include "TestCmdTest2.h"

#include "P.h"
#include "PyMOL.h"
#include "PyMOLGlobals.h"
#include "PyMOLOptions.h"

/**
* @pre GIL
* @return 0 on success, non-zero on error
Expand All @@ -25,6 +30,30 @@ PyObject *CmdTest2(PyObject *, PyObject *) {
}

namespace pymol {

PyMOLInstance::PyMOLInstance()
{
auto options = PyMOLOptions_New();
options->show_splash = false;
m_Inst = PyMOL_NewWithOptions(options);
PyMOLOptions_Free(options);
m_G = PyMOL_GetGlobals(m_Inst);
PInit(m_G, true);
PyMOL_Start(m_Inst);
}

PyMOLInstance::~PyMOLInstance()
{
PyMOL_Stop(m_Inst);
PFree(m_G);
PyMOL_Free(m_Inst);
}

PyMOLGlobals* PyMOLInstance::G() noexcept
{
return m_G;
}

namespace test {

TmpFILE::TmpFILE()
Expand Down
23 changes: 23 additions & 0 deletions layerCTest/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@
#include <catch2/catch.hpp>

namespace pymol {

/**
* Basic PyMOL Instance & Globals for C-testing purposes.
*/
class PyMOLInstance
{
public:
PyMOLInstance();
PyMOLInstance(const PyMOLInstance&) = delete;
PyMOLInstance& operator=(const PyMOLInstance&) = delete;
PyMOLInstance(PyMOLInstance&&) = delete;
PyMOLInstance& operator=(PyMOLInstance&&) = delete;
~PyMOLInstance();

/**
* @return PyMOLGlobals pointer
*/
PyMOLGlobals* G() noexcept;
private:
CPyMOL* m_Inst;
PyMOLGlobals* m_G;
};

namespace test {

// Checks whether obj is zero'd out (Struct of all PoD Types without non-default
Expand Down
62 changes: 62 additions & 0 deletions layerCTest/Test_Executive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "Test.h"

#include "Executive.h"
#include "ObjectVolume.h"

using namespace pymol;

#define TEST_SETUP \
PyMOLInstance pymol; \
auto G = pymol.G(); \
[[maybe_unused]] \
bool quiet = true;

#define TEST_SETUP_OBJ_ATOMLESS \
TEST_SETUP \
auto obj = new ObjectMolecule(G, false); \
obj->setName("M1"); \
ExecutiveManageObject(G, obj, false, quiet);


#define TEST_SETUP_OBJ \
TEST_SETUP \
ExecutivePseudoatom(G, "M1", "", "PS1", "PSD", "1", "P", "PSDO", \
"PS", -1.0f, 1, 0.0, 0.0, "", nullptr, -1, -3, 2, 1); \
auto obj = ExecutiveFindObjectByName(G, "M1");

TEST_CASE("ExecutiveManageObject", "[Executive]")
{
TEST_SETUP
auto obj = new ObjectMolecule(G, false);
obj->setName("M1");
ExecutiveManageObject(G, obj, false, quiet);
REQUIRE(true);
}

TEST_CASE("ExecutiveFindObjectByName", "[Executive]")
{
TEST_SETUP_OBJ_ATOMLESS
auto find = ExecutiveFindObjectByName(G, obj->Name);
REQUIRE(find == obj);
}

TEST_CASE("ExecutiveFindObject", "[Executive]")
{
TEST_SETUP_OBJ_ATOMLESS
auto find = ExecutiveFindObject<ObjectMolecule>(G, obj->Name);
REQUIRE(find == obj);
auto bad_find = ExecutiveFindObject<ObjectVolume>(G, obj->Name);
REQUIRE(bad_find == nullptr);
}

TEST_CASE("ExecutiveGetNames", "[Executive]")
{
TEST_SETUP_OBJ
auto type = 1; //objects
auto enabled_only = false;
auto selection = obj->Name;
auto names_result = ExecutiveGetNames(G, type, enabled_only, selection);
const auto& names = *names_result;
REQUIRE(names.size() == 1u);
REQUIRE(pymol::zstring_view(names[0]) == obj->Name);
}

0 comments on commit 4e3097f

Please sign in to comment.