File: Test.h

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 (97 lines) | stat: -rw-r--r-- 2,534 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once

#include <iostream>
#include <array>
#include <vector>
#include <functional>
#include <cstring>
#include <string>
#include <cmath>
#include "os_python.h"
#include "PConv.h"
#include "pymol/type_traits.h"
#include "pymol/algorithm.h"
#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
// values are 0)
template <typename T> static bool isStructZero(const T &obj) {
  const auto size = sizeof(T);
  std::array<char, size> buffer{};
  return std::memcmp(buffer.data(), &obj, size) == 0;
}

// Checks whether array arr is zeroed
template <typename T>
static bool isArrayZero(const T *arr, const std::size_t len) {
  auto bytelen = len * sizeof(T);
  std::vector<char> buffer(bytelen, 0);
  return std::memcmp(buffer.data(), arr, bytelen) == 0;
}

// Checks whether arrays are equal
template <typename T>
static bool isArrayEqual(const T *arr1, const T *arr2, const std::size_t len) {
  return std::equal(arr1, arr1 + len, arr2);
}

// Checks whether type has all special member functions
template <typename T> static bool isRegular()
{
  return std::is_default_constructible<T>::value &&
         std::is_copy_constructible<T>::value &&
         std::is_copy_assignable<T>::value &&
         std::is_move_constructible<T>::value &&
         std::is_move_assignable<T>::value &&
         std::is_destructible<T>::value;
         //std::is_nothrow_swappable<T>::value; C++17
}

// Checks whether ptr is equal to nullptr
template <typename T> static bool isNullptr(const T *ptr) {
  return ptr == nullptr;
}

class TmpFILE
{
  std::string tmpFilename;
public:
  TmpFILE();
  TmpFILE(const TmpFILE&) = delete;
  TmpFILE& operator=(const TmpFILE&) = delete;
  TmpFILE(TmpFILE&&) = default;
  TmpFILE& operator=(TmpFILE&&) = default;
  ~TmpFILE() {std::remove(tmpFilename.c_str()); }
  const char* getFilename() const { return tmpFilename.c_str(); }
  const std::string& getFilenameStr() const { return tmpFilename; }
};

}; // namespace test
}; // namespace pymol