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;
}
};
|