Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test/Object/cxx_main.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Epetra: Linear Algebra Services Package
5 // Copyright 2011 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 
43 // Epetra_Object Test routine
44 
45 #include "Epetra_Object.h"
46 #ifdef EPETRA_MPI
47 #include "Epetra_MpiComm.h"
48 #include <mpi.h>
49 #else
50 #include "Epetra_SerialComm.h"
51 #endif
52 
53 #include "../epetra_test_err.h"
54 #include "Epetra_Version.h"
55 
56 int main(int argc, char *argv[]) {
57 
58  int ierr = 0;
59 #ifdef EPETRA_MPI
60  MPI_Init(&argc,&argv);
61  Epetra_MpiComm comm( MPI_COMM_WORLD );
62 
63 #else
64  Epetra_SerialComm comm;
65 #endif
66 
67  bool verbose = false;
68 
69  // Check if we should print results to standard out
70  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
71 
72  if (verbose && comm.MyPID()==0)
73  cout << Epetra_Version() << endl << endl;
74 
75  // I'm alive !!!
76  if (verbose) cout << comm <<endl;
77 
78  Epetra_Object obj;
79 
80  // Test Epetra_Object label and the method to get the label attribute
81  const char* ObjLabel = obj.Label();
82  const char* ObjLabel1 = "Epetra::Object";
83  if (verbose) cout << endl << endl << "This should say " << ObjLabel1 << ": " << ObjLabel << endl << endl << endl;
84  EPETRA_TEST_ERR(strcmp(ObjLabel1,ObjLabel),ierr);
85 
86  // Test Epetra_Object SetLabel attribute set method
87  const char* NewObjLabel = "New name for Epetra_Object";
88  obj.SetLabel(NewObjLabel);
89  const char* NewObjLabel1 = obj.Label();
90  if (verbose) cout << endl << "This should say " << NewObjLabel << ": " << NewObjLabel1 << endl << endl << endl;
91  EPETRA_TEST_ERR(strcmp(NewObjLabel1,NewObjLabel),ierr);
92 
93  // Test GetRacebackMode and SetTracebackMode methods
95  if (verbose) cout << endl <<"Default Traceback Mode value = " << obj.GetTracebackMode() << endl;
96 
98  if (verbose) cout << "Set Traceback Mode value to one less than default = " << obj.GetTracebackMode() << endl << endl;
99  Epetra_Object obj0;
101 
102  // Test constructors other than the default
103  Epetra_Object obj1(1); // pass only TracebackMode
104  int TbM = obj1.GetTracebackMode();
105  if (verbose) cout << endl << endl << "This should say 1: " << TbM << endl << endl;
106  EPETRA_TEST_ERR(!(1==TbM),ierr);
107 
108  Epetra_Object obj2(NewObjLabel); // pass only a label
109  const char* NewObjLabel2 = obj2.Label();
110  if (verbose) cout << endl << endl << "This should say " << NewObjLabel << ": " << NewObjLabel2 << endl << endl << endl;
111  EPETRA_TEST_ERR(strcmp(NewObjLabel2,NewObjLabel),ierr);
112 
113  Epetra_Object obj3(NewObjLabel,1); // pass a label and a TracebackMode
114  const char* NewObjLabel3 = obj3.Label();
115  int TbM1 = obj3.GetTracebackMode();
116  if (verbose) cout << endl << "This should say " << NewObjLabel << "," << "1: " << NewObjLabel3 << "," << TbM1 << endl << endl << endl;
117  EPETRA_TEST_ERR(strcmp(NewObjLabel3,NewObjLabel),ierr);
118  EPETRA_TEST_ERR(!(1==TbM1),ierr);
119 
120  Epetra_Object obj4(obj3); // copy constructor
121  const char* NewObjLabel4 = obj4.Label();
122  int TbM2 = obj4.GetTracebackMode();
123  if (verbose) cout << endl << "This should say " << NewObjLabel << "," << "1: " << NewObjLabel4 << "," << TbM2 << endl << endl << endl;
124  EPETRA_TEST_ERR(strcmp(NewObjLabel4,NewObjLabel),ierr);
125  EPETRA_TEST_ERR(!(1==TbM2),ierr);
126 
127 
128 #ifdef EPETRA_MPI
129  MPI_Finalize();
130 #endif
131  return ierr;
132 }
133 
134 /*
135  end of file main.cc
136 */
#define EPETRA_TEST_ERR(a, b)
virtual void SetLabel(const char *const Label)
Epetra_Object Label definition using char *.
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
int MyPID() const
Return my process ID.
Epetra_MpiComm: The Epetra MPI Communication Class.
std::string Epetra_Version()
virtual const char * Label() const
Epetra_Object Label access funtion.
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:57
Epetra_SerialComm: The Epetra Serial Communication Class.
static int GetTracebackMode()
Get the value of the Epetra_Object error report mode.
int main(int argc, char *argv[])
const int DefaultTracebackMode