File: obtest.h

package info (click to toggle)
openbabel 2.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 75,308 kB
  • ctags: 41,952
  • sloc: cpp: 321,252; ansic: 89,228; python: 7,262; perl: 6,418; pascal: 793; sh: 194; xml: 97; ruby: 55; makefile: 47; java: 23
file content (71 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download | duplicates (3)
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
#include <iostream>
#include <cstdlib>

#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
#include <openbabel/shared_ptr.h>

#ifdef _MSC_VER
#define FUNCTION_SIGNATURE __FUNCSIG__
#else
#define FUNCTION_SIGNATURE __PRETTY_FUNCTION__
#endif

/*inline*/ void report_error(const char* msg, const char* file, int line, const char* func_name, bool require = false)
{
    std::cout << file << ":" << line << ": " << msg << " (FAIL)" << std::endl;
    if (require)
      exit(-1);
}

template <typename T1, typename T2>
void ob_compare(T1 a, T2 b, const char *expr, const char *file, int line, const char *func_name)
{
  if (!(a == b))
    std::cout << file << ":" << line << ": " << expr << " [" << a << " == " << b << "] (FAIL)" << std::endl;
}

#define OB_ASSERT(exp) \
  ( (exp) ? static_cast<void>(0) : report_error(#exp, __FILE__, __LINE__, FUNCTION_SIGNATURE, false) )

#define OB_REQUIRE(exp) \
  ( (exp) ? static_cast<void>(0) : report_error(#exp, __FILE__, __LINE__, FUNCTION_SIGNATURE, true) )

const char* ob_expr(const char *expr) { return expr; }
#define OB_EXPR(expr) ob_expr(#expr)

#define OB_COMPARE(a,b) \
  ob_compare(a, b, OB_EXPR( a == b ), __FILE__, __LINE__, FUNCTION_SIGNATURE)



// some utility functions
typedef shared_ptr<OpenBabel::OBMol> OBMolPtr;

struct OBTestUtil
{
  static std::string GetFilename(const std::string &filename)
  {
    std::string path = TESTDATADIR + filename;
    return path;
  }

  static OBMolPtr ReadFile(const std::string &filename)
  {
    std::string file = GetFilename(filename);

    std::ifstream ifs;
    ifs.open(file.c_str());
    OB_REQUIRE( ifs );

    OpenBabel::OBConversion conv;
    OpenBabel::OBFormat *format = conv.FormatFromExt(file.c_str());
    OB_REQUIRE(format);
    OB_REQUIRE(conv.SetInFormat(format));

    OBMolPtr mol(new OpenBabel::OBMol);
    OB_REQUIRE(conv.Read(mol.get(), &ifs));

    return mol;
  }
};