Hello_Test.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 // 
00004 //                     New_Package Example Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #include "Epetra_SerialComm.h"
00030 #include "Newp_Hello.h"
00031 #include <sstream>
00032 
00033 #ifdef HAVE_MPI
00034 #include "mpi.h"
00035 #endif
00036 
00037 int main(int argc, char *argv[]){
00038 
00039 #ifdef HAVE_MPI
00040   MPI_Init(&argc, &argv);
00041 #endif
00042 
00043   using namespace std;
00044 
00045   // Get an Epetra_Comm
00046   Epetra_SerialComm epetra_serial_comm;
00047   Epetra_Comm * epetra_comm;
00048   epetra_comm = dynamic_cast<Epetra_Comm*>(&epetra_serial_comm);
00049 
00050   //Create an ostream that Newp_Hello can write to and that we can read from
00051   stringbuf string_buf;
00052   streambuf * stream_buf;
00053   stream_buf = dynamic_cast<streambuf*>(&string_buf);
00054   iostream io_stream(stream_buf);
00055   ostream * o_stream;
00056   o_stream = dynamic_cast<ostream*>(&io_stream);
00057   
00058   //Create a Newp_Hello to test
00059   Newp_Hello new_package_hello(*epetra_comm);
00060   new_package_hello.Print(*o_stream);
00061 
00062   //Read from the io_stream
00063   char temp[83];
00064   io_stream.getline(temp, 83, 0);
00065     
00066   char * expected = "This will print out one line for each of the 1 processes \n\nHello.  I am process 0\n";
00067 
00068   if(strcmp(temp, expected) != 0){
00069     cout << "Test Failed!" << endl << "     Got::" << strlen(temp) << "::" << temp << "::" << endl << "Expected::" << strlen(expected) << "::" << expected << "::" << endl;
00070     return 1;
00071   }
00072   cout << "Test passed!" << endl;
00073   #ifdef EPETRA_MPI
00074   MPI_Finalize();
00075   #endif
00076   return 0;
00077 }

Generated on Thu Sep 18 12:37:03 2008 for New_Package Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1