Epetra Package Browser (Single Doxygen Collection) Development
test/Object/cxx_main.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 //
00004 //               Epetra: Linear Algebra Services Package
00005 //                 Copyright 2011 Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 
00043 // Epetra_Object Test routine
00044 
00045 #include "Epetra_Object.h"
00046 #ifdef EPETRA_MPI
00047 #include "Epetra_MpiComm.h"
00048 #include <mpi.h>
00049 #else
00050 #include "Epetra_SerialComm.h"
00051 #endif
00052 
00053 #include "../epetra_test_err.h"
00054 #include "Epetra_Version.h"
00055 
00056 int main(int argc, char *argv[]) {
00057 
00058   int ierr = 0;
00059 #ifdef EPETRA_MPI
00060   MPI_Init(&argc,&argv);
00061   Epetra_MpiComm comm( MPI_COMM_WORLD );
00062 
00063 #else
00064   Epetra_SerialComm comm;
00065 #endif
00066 
00067   bool verbose = false;
00068 
00069   // Check if we should print results to standard out
00070   if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
00071 
00072   if (verbose && comm.MyPID()==0)
00073     cout << Epetra_Version() << endl << endl;
00074 
00075   // I'm alive !!!
00076   if (verbose) cout << comm <<endl;
00077 
00078   Epetra_Object obj;
00079 
00080   // Test Epetra_Object label and the method to get the label attribute
00081   const char* ObjLabel = obj.Label();
00082   const char* ObjLabel1 = "Epetra::Object";
00083   if (verbose) cout << endl << endl << "This should say " << ObjLabel1 << ": " << ObjLabel << endl << endl << endl;
00084   EPETRA_TEST_ERR(strcmp(ObjLabel1,ObjLabel),ierr);
00085 
00086   // Test Epetra_Object SetLabel attribute set method
00087   const char* NewObjLabel = "New name for Epetra_Object";
00088   obj.SetLabel(NewObjLabel);
00089   const char* NewObjLabel1 = obj.Label();
00090   if (verbose) cout << endl << "This should say " << NewObjLabel << ": " << NewObjLabel1 << endl << endl << endl;
00091   EPETRA_TEST_ERR(strcmp(NewObjLabel1,NewObjLabel),ierr);
00092 
00093   // Test GetRacebackMode and SetTracebackMode methods
00094   EPETRA_TEST_ERR(!(obj.GetTracebackMode()==DefaultTracebackMode),ierr);
00095   if (verbose) cout << endl <<"Default Traceback Mode value = " << obj.GetTracebackMode() << endl;
00096 
00097   obj.SetTracebackMode(DefaultTracebackMode-1);
00098   if (verbose) cout << "Set Traceback Mode value to one less than default = " << obj.GetTracebackMode() << endl << endl;
00099   Epetra_Object obj0;
00100   EPETRA_TEST_ERR(!(obj0.GetTracebackMode()==DefaultTracebackMode-1),ierr);
00101 
00102   // Test constructors other than the default
00103   Epetra_Object obj1(1); // pass only TracebackMode
00104   int TbM = obj1.GetTracebackMode();
00105   if (verbose) cout << endl << endl << "This should say 1: " << TbM << endl << endl;
00106   EPETRA_TEST_ERR(!(1==TbM),ierr);
00107 
00108   Epetra_Object obj2(NewObjLabel); // pass only a label
00109   const char* NewObjLabel2 = obj2.Label();
00110   if (verbose) cout << endl << endl << "This should say " << NewObjLabel << ": " << NewObjLabel2 << endl << endl << endl;
00111   EPETRA_TEST_ERR(strcmp(NewObjLabel2,NewObjLabel),ierr);
00112 
00113   Epetra_Object obj3(NewObjLabel,1); // pass a label and a TracebackMode
00114   const char* NewObjLabel3 = obj3.Label();
00115   int TbM1 = obj3.GetTracebackMode();
00116   if (verbose) cout << endl << "This should say " << NewObjLabel << "," << "1: " << NewObjLabel3 << "," << TbM1 << endl << endl << endl;
00117   EPETRA_TEST_ERR(strcmp(NewObjLabel3,NewObjLabel),ierr);
00118   EPETRA_TEST_ERR(!(1==TbM1),ierr);
00119 
00120   Epetra_Object obj4(obj3); // copy constructor
00121   const char* NewObjLabel4 = obj4.Label();
00122   int TbM2 = obj4.GetTracebackMode();
00123   if (verbose) cout << endl << "This should say " << NewObjLabel << "," << "1: " << NewObjLabel4 << "," << TbM2 << endl << endl << endl;
00124   EPETRA_TEST_ERR(strcmp(NewObjLabel4,NewObjLabel),ierr);
00125   EPETRA_TEST_ERR(!(1==TbM2),ierr);
00126 
00127 
00128 #ifdef EPETRA_MPI
00129   MPI_Finalize();
00130 #endif
00131   return ierr;
00132 }
00133 
00134 /*
00135   end of file main.cc
00136 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines