[parchive2-cvs] library/src/tests/parchive2 test_parchive2.cc,1.16,1.17
Status: Pre-Alpha
Brought to you by:
coppit
|
From: <na...@us...> - 2003-05-07 06:08:54
|
Update of /cvsroot/parchive2/library/src/tests/parchive2
In directory sc8-pr-cvs1:/tmp/cvs-serv11936
Modified Files:
test_parchive2.cc
Log Message:
rewrote the whole test file for Parchive2... Jeff will finish it tomorrow
Index: test_parchive2.cc
===================================================================
RCS file: /cvsroot/parchive2/library/src/tests/parchive2/test_parchive2.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** test_parchive2.cc 7 May 2003 01:53:30 -0000 1.16
--- test_parchive2.cc 7 May 2003 06:08:51 -0000 1.17
***************
*** 8,11 ****
--- 8,12 ----
#include "slice/slice.h"
#include "slice/file_slice.h"
+ #include "tests/tests.h"
#include "creator_information/creator_information.h"
#include "file/file.h"
***************
*** 14,17 ****
--- 15,21 ----
#include "parchive2/parchive2.h"
#include <iostream>
+ #include <unistd.h>
+ #include <fstream>
+ #include <stdio.h>
using namespace std;
***************
*** 32,36 ****
list<Slice*> Create_File_Slices(list<File> file_list) const
{
! return Parchive2::Create_File_Slices(file_list);
}
--- 36,41 ----
list<Slice*> Create_File_Slices(list<File> file_list) const
{
! list<Slice*> back = Parchive2::Create_File_Slices(file_list);
! return back;
}
***************
*** 84,273 ****
int main()
{
- // Constructor
- cout << "Parchive2:Constructor: BEGIN" << endl;
- Parchive2_Tester p;
! cout << "Parchive2:Constructor: SUCCESS" << endl;
! // Constructor 2
! cout << "Parchive2:Constructor2: BEGIN" << endl;
! string str = "test";
! Parchive2_Tester p2;
! cout << "Parchive2:Constructor2:SUCCESS"<<endl;
!
! // Get_Creator_Information
! cout << "Parchive2:Get_Creator_Information: BEGIN" <<endl;
! string client = "";
! Creator_Information c(client);
! c = p.Get_Creator_Information();
! if (c.Get_Client_ID() == ""){
! cout << "Parchive2:Get_Creator_Information: FAILED"<<endl;
! return 1;
! } else
! cout << "Parchive2:Get_Creator_Information: SUCCESS"<<endl;
!
! //Get_Data_File_Information
! cout << "Parchive2:Get_Data_File_Information: NOT IMPLEMENTED" <<endl;
! //list<File> ufile = p.Get_Data_File_Information();
!
! //if(!sizeof(ufile))
! // cout <<"Parchive2:Get_Data_File_Information: SUCCESS" <<endl;
! //else
! // cout <<"Parchive2:Get_Data_File_Information: FAILED" <<endl;
! // Create_File_Slices
! cout << "Parchive2:Create_File_Slices: BEGIN" << endl;
! list<Slice*> dslice;
! //File dum("dummyfile.txt","/dummy");
! cout <<"Can't open File" <<endl;
! list<File> xpointer;
! //xpointer.push_back(dum);
!
! dslice = p.Create_File_Slices(xpointer);
! if (!sizeof(dslice))
! {
! cout << "Parchive2:Create_File_Slices: FAILED" << endl;
! return 1;
! }
! else
! cout << "Parchive2:Create_File_Slices: SUCCESS" << endl;
! // Make_Data_Files
! cout << "Parchive2:Make_Data_Files: NOT IMPLEMENTED" << endl;
! //list<File> dfile;
! // dfile.clear();
! //dfile = p.Make_Data_Files("/dummy");
! //if (!sizeof(dfile))
! // cout << "Parchive2:Make_Data_Files: SUCCESS" << endl;
! //else
! // cout << "Parchive2:Make_Data_Files: FAILED" << endl;
!
! // Make_Parity_Files
! cout << "Parchive2:Make_Parity_Files: BEGIN" << endl;
! list<File> pfile;
! pfile.clear();
! pfile = p.Make_Parity_Files("/dummy");
! if (!sizeof(pfile))
! {
! cout << "Parchive2:Make_Parity_Files: FAILED" << endl;
! return 1;
}
- else
- cout << "Parchive2:Make_Parity_Files: SUCCESS" << endl;
!
!
! // Set_Slice_Size and Get_Slice_Size
! cout <<"Parchive2:Set_Slice_Size and Get_Slice_Size: BEGIN"<<endl;
! p.Set_Slice_Size(5);
! int n = p.Get_Slice_Size();
! if (n==5)
! cout <<"Parchive2:Set_Slice_Size and Get_Slice_Size:SUCCESS"<<endl;
! else
{
! cout <<"Parchive2:Set_Slice_Size and Get_Slice_Size:FAILED"<<endl;
! return 1;
}
!
!
! // Set_Protected_Files
! cout << "Parchive2:Set_Protected_Files:BEGIN" << endl;
! File s1("filename1", "path1");
! File s2("filename2", "path2");
! File s3("filename3", "path3");
! list<File> spointer;
! spointer.push_back(s1);
! spointer.push_back(s2);
! spointer.push_back(s3);
! p.Set_Protected_Files(spointer);
! cout<<"Parchive2:Set_Protected_Files:SUCCESS" << endl;
! //cout <<"Parchive2:Set_Protected_Files:FAILED"<<endl;
! // Set_Unprotected_Files
! cout << "Parchive2:Set_Unprotected_Files:BEGIN" << endl;
! File e1("filename1","path1");
! File e2("filename2","path2");
! File e3("filename3","path3");
! list<File> epointer;
! epointer.push_back(e1);
! epointer.push_back(e2);
! epointer.push_back(e3);
! p.Set_Unprotected_Files(epointer);
! cout<<"Parchive2:Set_Unprotected_Files:SUCCESS" <<endl;
! //cout <<"Parchive2:Set_Unprotected_Files:FAILED"<<endl;
!
! // Find_Valid_Existing_Protected_Files
! cout << "Parchive2:Find_Valid_Existing_Protected_Files:NOT IMPLEMENTED" << endl;
! //list<File> Find_Valid_Existing_Protected_Files();
!
!
! // Find_Valid_Existing_Unprotected_Files
! cout << "Parchive2:Find_Valid_Existing_Unprotected_Files:NOT IMPLEMENTED" << endl;
! // list<File> Find_Valid_Existing_Unprotected_Files();
! // Make_Packets_From File
! cout << "Parchive2:Make_Packets_From_Files:BEGIN"<<endl;
! list <Packet*> dpacket;
! list<File> Flist;
!
! File somefile("dummyfile.txt","/dummy");
! Flist.push_back(somefile);
! dpacket = p.Make_Packets_From_Files(Flist);
! if (!sizeof(dpacket))
{
! cout << "Parchive2:Make_Packets_From_Files: FAILED" << endl;
! return 1;
}
! else
! cout << "Parchive2:Make_Packets_From_Files: SUCCESS" << endl;
!
!
! //Check_Data_Files
! cout << "Parchive2:Check_Data_Files:BEGIN"<<endl;
! list<File> inbase1;
! map<string,bool> torf;
! bool torf2;
! p.Check_Data_Files(inbase1,torf, torf2);
! cout <<"Parchive2:Check_Data_Files:SUCCESS"<<endl;
!
! //Recover_Data_Files
! cout << "Parchive2:Recover_Data_Files:BEGIN"<<endl;
! list<File> inbase;
! string indirect = "/dummy";
! cout <<"Parchive2:Recover_Data_Files:SUCCESS"<<endl;
!
! //Ignore_Case
! cout << "Parchive2:IgnoreCase:NOT IMPLEMENTED"<<endl;
! //Create_Parity_Files
! cout << "Parchive2:Create_Parity_Files:BEGIN"<<endl;
! list<File> protfiles;
! list<File> unprotfiles;
! string destindirect = "/dummy";
! string base = "dum";
! p.Create_Parity_Files(protfiles, unprotfiles, destindirect, base);
! cout <<"Parchive2:Create_Parity_Files:SUCCESS"<<endl;
! // Create_Parchive_Files
! cout << "Parchive2:Create_Parchive_Files: BEGIN" << endl;
! list<File> hfile;
! hfile.clear();
! hfile = p.Create_Parchive_Files("/dummy","dum");
! if (!sizeof(hfile))
! cout << "Parchive2:Create_Parchive_Files: SUCCESS" << endl;
! else
{
! cout << "Parchive2:Create_Parchive_Files: FAILED" << endl;
! return 1;
}
return 0;
}
--- 89,278 ----
int main()
{
! //default constructor
! {
! Parchive2_Tester first_par;
! Parchive2_Tester second_par;
! compare(first_par.Get_Slice_Size(),second_par.Get_Slice_Size());
! compare(first_par.Get_Creator_Information(),second_par.Get_Creator_Information());
!
! cerr<<"PASS: Parchive2: default constructor"<<endl;
! }
! //overloaded constructor
! {
+ string in_creator_info = "PAR2 Tester";
! Parchive2_Tester my_par2(in_creator_info);
! Creator_Information back_creator_info(my_par2.Get_Creator_Information());
! compare(back_creator_info,in_creator_info); //sanity check
!
! cerr<<"PASS: Parchive2: overloaded constructor and Get_Creator_Information()"<<endl;
}
+ //make a little file
+ ofstream out;
+ out.open("parchive2_tester_file");
! char str_passed_in[] = "Parchive2 is going to fly... parchive2 is going to fly";
! out<<str_passed_in;
! out.close(); //write file and close it
!
! //Create_File_Slices
{
! string ici = "PAR2 TESTER";
!
! Parchive2_Tester* my_par2 = new Parchive2_Tester(ici);
!
! Parchive2_Tester* my_par2_copy = new Parchive2_Tester(ici);
!
! File fd_in("parchive2_tester_file","tests/parchive2/");
!
! string path = fd_in.Get_Path();
!
! cout<<"the path string is: "<<path;
!
! list<File> original_file_list;
!
! original_file_list.push_back(fd_in);
!
! list<Slice*> back_file_slices1;
!
! back_file_slices1 = my_par2->Create_File_Slices(original_file_list);
!
! list<Slice*> back_file_slices2 = my_par2_copy->Create_File_Slices(original_file_list);
!
! compare(back_file_slices1.size(),back_file_slices2.size());
!
! //we must do a for loop comparing each slice because it wont
! //work with the overloaded == operator... stl got confused
! list<Slice*>::iterator slice_it1 = back_file_slices1.begin();
!
! list<Slice*>::iterator slice_it2 = back_file_slices2.begin();
!
! for(;
! slice_it1 != back_file_slices1.end();
! slice_it1++,slice_it2++)
! {
! compare(*slice_it1,*slice_it2);
! }
!
! cerr<<"PASS: Parchive2: Create_File_Slices"<<endl;
!
}
! //Make_Packets_From_Files
! {
! string ici = "PAR2 TESTER";
! Parchive2_Tester* my_par2 = new Parchive2_Tester(ici);
! Parchive2_Tester* my_par2_copy = new Parchive2_Tester(ici);
!
! File fd_in("parchive2_tester_file","tests/parchive2/");
! string path = fd_in.Get_Path();
! cout<<"the path string is: "<<path;
!
! list<File> original_file_list;
! original_file_list.push_back(fd_in);
! list<Packet*> back_file_packets1;
!
! back_file_packets1 = my_par2->Make_Packets_From_Files(original_file_list);
!
! list<Packet*> back_file_packets2;
!
! back_file_packets2 = my_par2_copy->Make_Packets_From_Files(original_file_list);
!
! compare(back_file_packets1.size(),back_file_packets2.size());
!
! list<Packet*>::iterator packet_it1 = back_file_packets1.begin();
!
! list<Packet*>::iterator packet_it2 = back_file_packets2.begin();
!
! for(;
! packet_it1 != back_file_packets1.end();
! packet_it1++,packet_it2++)
! {
! compare(*packet_it1,*packet_it2);
! }
!
! cerr<<"PASS: Parchive2: Make_Packets_From_Files"<<endl;
! }
!
! //Make_Parity_Files
{
! string ici = "PAR2 TESTER";
!
! Parchive2_Tester* my_par2 = new Parchive2_Tester(ici);
!
! Parchive2_Tester* my_par2_copy = new Parchive2_Tester(ici);
!
! list<File> back_files_list1;
!
! back_files_list1 = my_par2->Make_Parity_Files("/doesntexist");
!
! list<File> back_files_list2;
!
! back_files_list2 = my_par2_copy->Make_Parity_Files("/doesnotexist");
!
! compare(back_files_list1.size(),0); //since the file doesn't exist
! compare(back_files_list2.size(),0);
!
! list<File>::iterator file_it1 = back_files_list1.begin();
!
! list<File>::iterator file_it2 = back_files_list2.begin();
!
! for(;
! file_it1 != back_files_list1.end();
! file_it1++,file_it2++)
! {
! compare(*file_it1,*file_it2);
! }
!
! cerr<<"PASS: Parchive2: Make_Parity_Files"<<endl;
}
! //Create_Parchive_Files
! {
! string ici = "PAR2 TESTER";
!
! Parchive2_Tester p2tester(ici);
! list<File> files_back = p2tester.Create_Parchive_Files("/doesntexist","stuff");
! compare(files_back.size(),0);
! files_back = p2tester.Create_Parchive_Files("tests/parchive2/","parchive2_tester_file");
! compare((files_back.size() > 0),true);
!
! cerr<<"PASS: Parchive2: Create_Parchive_Files"<<endl;
!
! }
! //set slice size and get slice size
{
! string ici = "PAR2 TEST";
!
! Parchive2_Tester p2tester(ici);
!
! int size = 20;
!
! p2tester.Set_Slice_Size(size);
!
! compare(p2tester.Get_Slice_Size(),size);
!
! cerr<<"PASS: Parchive2: Set_Slice_Size()"<<endl;
}
+
+
+
+
+ unlink("parchive2_tester_file");
+
return 0;
}
|