MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
test_moosemodule.cpp File Reference
#include "Python.h"
#include <iostream>
#include <cstring>
#include "../basecode/header.h"
#include "../basecode/Id.h"
#include "../basecode/ObjId.h"
#include "../shell/Shell.h"
#include "moosemodule.h"
#include "../utility/utility.h"
+ Include dependency graph for test_moosemodule.cpp:

Go to the source code of this file.

Functions

void test_moosemodule ()
 
void test_to_py ()
 

Function Documentation

void test_moosemodule ( )

Definition at line 138 of file test_moosemodule.cpp.

References test_to_py().

Referenced by MODINIT().

139 {
140  test_to_py();
141 }
void test_to_py()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void test_to_py ( )

Definition at line 62 of file test_moosemodule.cpp.

References ObjId::data(), Shell::doCreate(), Shell::doDelete(), ObjId::id, and to_py().

Referenced by test_moosemodule().

63  {
64 #ifdef DO_UNIT_TESTS
65  // conversion of double
66  PyObject * pv;
67  double dv = 10.0;
68  pv = to_py((void*)&dv, 'd');
69  assert(pv != NULL);
70  assert(PyFloat_AsDouble(pv) == dv);
71  Py_XDECREF(pv);
72  cout << "." << flush;
73 
74  // conversion of long
75  long lv = 1000000000;
76  pv = to_py((void*)&lv, 'l');
77  assert(pv != NULL);
78  assert(PyLong_AsLong(pv) == lv);
79  Py_XDECREF(pv);
80  cout << "." << flush;
81 
82  // conversion of int
83  int iv = 10;
84  pv = to_py((void*)&iv, 'i');
85  assert(pv != NULL);
86  assert(PyInt_AsLong(pv) == iv);
87  Py_XDECREF(pv);
88  cout << "." << flush;
89 
90  // conversion of float
91  float fv = 7e-3;
92  pv = to_py((void*)&fv, 'f');
93  assert(pv != NULL);
94  assert(PyFloat_AsDouble(pv) == fv);
95  Py_XDECREF(pv);
96  cout << "." << flush;
97 
98  // string char-array
99  string sv = "hello world";
100  // C++ string
101  pv = to_py((void*)&sv, 's');
102  assert(pv != NULL);
103  assert(strcmp(PyString_AsString(pv), sv.c_str()) == 0);
104  Py_XDECREF(pv);
105  cout << "." << flush;
106 
107  // Id
108  Shell * shell = reinterpret_cast< Shell * >(ObjId( Id(), 0).data());
109  Id id = shell->doCreate("Neutral", Id(), "n", 1);
110  pv = to_py((void*)&id, 'x');
111  assert(pv != NULL);
112  assert(((_Id*)pv)->id_ == id);
113  Py_XDECREF(pv);
114  cout << "." << flush;
115 
116  // ObjId
117  ObjId oid(id, 0);
118  pv = to_py((void*)&oid, 'y');
119  assert(pv != NULL);
120  assert(((_ObjId*)pv)->oid_.id == oid.id);
121  //Harsha: commeted this line to compile moose in debug mode
122  //assert(((_ObjId*)pv)->oid_.dataId == oid.dataId);
123  Py_XDECREF(pv);
124  cout << "." << flush;
125 
126  // Incorrect type code
127  pv = to_py((void*)&oid, '9');
128  assert(pv == NULL);
129  PyErr_Clear();
130  cout << "." << flush;
131  shell->doDelete(id);
132 
133 #endif
134  }
char * data() const
Definition: ObjId.cpp:113
Definition: ObjId.h:20
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
Definition: Shell.cpp:181
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
PyObject * to_py(void *obj, char typecode)
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function: