File: Test.cpp

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (82 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>

#ifndef _WIN32
#include <stdlib.h>
#include <unistd.h>
#endif

#include <fstream>
#include <iostream>
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#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
 */
PyObject *CmdTest2(PyObject *, PyObject *) {
  int argc = 1;
  char argv0[] = "pymol";
  char *argv[] = {argv0};
  auto result = Catch::Session().run(argc, argv);
  return PyLong_FromLong(result);
}

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()
{
#ifdef _WIN32
    tmpFilename.resize(L_tmpnam_s);
    tmpnam_s(&tmpFilename[0], tmpFilename.size());
    tmpFilename.resize(strlen(tmpFilename.c_str()));

    // file 'touch'
    std::ofstream(tmpFilename);
#else
    tmpFilename = P_tmpdir;

    if (!tmpFilename.empty() && tmpFilename.back() != '/') {
      tmpFilename += '/';
    }

    tmpFilename.append("tmppymoltestXXXXXX");

    close(mkstemp(&tmpFilename[0]));
#endif
}

} // namespace test
} // namespace pymol