Test-nullObject.C
Go to the documentation of this file.
1 #include "nullObject.H"
2 #include "IOstreams.H"
3 
4 using namespace Foam;
5 
7 {
8 
9 public:
10 
11  //- Null constructor
13  {}
14 };
15 
16 
17 int main()
18 {
19  // Test pointer and reference to a class
20 
21  SimpleClass* ptrToClass = new SimpleClass;
22  SimpleClass& refToClass(*ptrToClass);
23 
24  if (notNull(ptrToClass))
25  {
26  Info<< "Pass: ptrToClass is not null" << endl;
27  }
28  else
29  {
30  Info<< "FAIL: refToClass is null" << endl;
31  }
32 
33  if (notNull(refToClass))
34  {
35  Info<< "Pass: refToClass is not null" << endl;
36  }
37  else
38  {
39  Info<< "FAIL: refToClass is null" << endl;
40  }
41 
42 
43  // Test pointer and reference to the nullObject
44 
45  const SimpleClass* ptrToNull(NullObjectPtr<SimpleClass>());
46  const SimpleClass& refToNull(*ptrToNull);
47 
48  if (isNull(ptrToNull))
49  {
50  Info<< "Pass: ptrToNull is null" << endl;
51  }
52  else
53  {
54  Info<< "FAIL: ptrToNull is not null" << endl;
55  }
56 
57  if (isNull(refToNull))
58  {
59  Info<< "Pass: refToNull is null" << endl;
60  }
61  else
62  {
63  Info<< "FAIL: refToNull is not null" << endl;
64  }
65 
66  // Clean-up
67  delete ptrToClass;
68 
69  return 0;
70 }
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::notNull
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
SimpleClass::SimpleClass
SimpleClass()
Null constructor.
Definition: Test-nullObject.C:12
main
int main()
Definition: Test-nullObject.C:17
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Info
messageStream Info
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isNull
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:40
nullObject.H
SimpleClass
Definition: Test-nullObject.C:6