proj home

Files   Classes   Functions   Hierarchy  

systemcallstest.cpp

Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <fstream>
00003 #include <iostream>
00004 using namespace std;
00005 
00006 #include <print.h>
00007 #include <systemcalls.h>
00008 #include <systemcallstest.h>
00009 #include <typedefs.h>
00010 
00011 string systemcallstest::doc[] = 
00012 {
00013   "",
00014   "Printing local directory.",
00015   "Running a perl tool.",
00016   "Running a perl tool and redirecting output to a file.",
00017   "Using systemcall, running a perl tool.",
00018   "Unit test systemcalls"
00019 };
00020 
00021 
00022 
00023 void systemcallstest::developmenttest01()
00024 {
00025   system("pwd");
00026 }
00027 
00028 void systemcallstest::developmenttest02()
00029 {
00030   string s1="perl ../makefilebuildtool/extractheaders.pl ../vrml/vrmlshape.h";
00031 
00032   system(s1.c_str());
00033 }
00034 
00035 void systemcallstest::developmenttest03()
00036 {
00037   string s1="perl ../makefilebuildtool/extractheaders.pl ../vrml/vrmlshape.h";
00038   string filename("tempheaders.txt");
00039   s1 += " > ";
00040   s1 += filename;
00041 
00042   system(s1.c_str());
00043 
00044   ifstream in(filename.c_str());
00045 
00046   string str;
00047   vector<string> lines;
00048   while (in)
00049   {
00050     getline(in,str);
00051     if (str.length() > 0)
00052       lines.push_back(str);
00053   }
00054 
00055   for (uint i=0; i<lines.size(); ++i)
00056   {
00057     cout << "*" << lines[i] << "*" << endl;
00058   }
00059 }
00060 
00061 void systemcallstest::developmenttest04()
00062 {
00063   systemcalls sys01
00064   (
00065     "perl ../makefilebuildtool/extractheaders.pl ../vrml/vrmlshape.h",
00066     "tempheaders.txt"
00067   );
00068 
00069   cout << "Doing the system call" << endl;
00070   sys01.eval();
00071 
00072   cout<< "Printing the output." << endl;
00073  
00074 
00075   for (uint i=0; i<sys01.lines.size(); ++i)
00076   {
00077     cout << "*" << sys01.lines[i] << "*-" << endl;
00078   }
00079 }
00080 
00081 int systemcallstest::unittest01()
00082 {
00083   {
00084     cout << "TEST 1.1" << endl;
00085     systemcalls sys
00086     (
00087       "find . -name \"*.z\"",
00088       "/tmp/temp.txt"
00089     );
00090 
00091     cout << SHOW(sys.exitstatus) << endl;
00092     sys.eval();
00093     cout << SHOW(sys.exitstatus) << endl;
00094     cout << print(sys.lines,"\n") << endl;
00095 
00096     assertreturnOS(sys.exitstatus==0);
00097   }
00098 /*
00099 
00100   {
00101     cout << "TEST 1.2" << endl;
00102     systemcalls sys
00103     (
00104       "nonexistantcommand",
00105       "/tmp/temp.txt"
00106     );
00107     sys.eval();
00108     cout << SHOW(sys.exitstatus) << endl;
00109     assertreturnOS(!sys.isvalid());
00110   }
00111 
00112   {
00113     cout << "TEST 1.3" << endl;
00114     string text=systemcallseval("echo `date +%Y`").output();
00115     cout << text << endl;
00116   }
00117 
00118   {
00119     cout << "TETS 1.4 1.5 1.6 demonstrate difficulty with exit codes" << endl;
00120     cout << "  The exit status is not being captured, but can be explicitly output through bash's $?" << endl;
00121 
00122     cout << "TEST 1.4" << endl;
00123     systemcalls sys("make -f fku; echo \<exitstatus\>$?\</exitstatus\>","temp01.txt");
00124     sys.combine=true;
00125     sys.eval();
00126     string text = sys.output();
00127     cout << SHOW3(text) << endl;
00128   }
00129 
00130   {
00131     cout << "TEST 1.5" << endl;
00132     systemcalls sys("make -f fku 2>./temp02.txt; echo \<exitstatus\>$?\</exitstatus\>","temp01.txt");
00133 //    sys.combine=true;
00134     sys.eval();
00135     cout << SHOW(sys.exitstatus) << endl;
00136     assertreturnOS(sys.exitstatus==0); // status associated with echo
00137     string text = sys.output();
00138     cout << SHOW3(text) << endl;
00139   }
00140 
00141   {
00142     cout << "TEST 1.6" << endl;
00143     systemcalls sys("make -f fku","temp01.txt");
00144     sys.combine=true;
00145     sys.eval();
00146     cout << SHOW(sys.exitstatus) << endl;
00147     assertreturnOS(sys.exitstatus!=0); // The file make is trying to compile does not exist.
00148     string text = sys.output();
00149     cout << SHOW3(text) << endl;
00150   }
00151 */
00152     
00153   return 0;
00154 }
00155 
00156   
00157 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8