00001 00005 #include "common/log.h" 00006 #include "test/io/output/SimpleOutputTester.hpp" 00007 #include "io/StreamRepr.hpp" 00008 #include "io/FILERepr.hpp" 00009 #include "io/FDRepr.hpp" 00010 #include "io/output/normal/SimpleOutput.hpp" 00011 #include "io/output/normal/BufferedNormalOutput.hpp" 00012 00013 #include <iostream> 00014 00015 void SimpleOutputTester::usageSimpleOutput() 00016 { 00017 std::cerr << "\nUsage: simple_output_test file_repr writer "; 00018 std::cerr << "ouput_file set_size lowlevel_buffer_size highlevel_buffer_size [random_seed]"<<std::endl; 00019 std::cerr << " file_repr\t {filedes, FILE, stream}"<<std::endl; 00020 std::cerr << " writer\t {simple, buffered}"; 00021 std::cerr << " The size of the low level buffer will be lowlevel_buffer_size."<<std::endl; 00022 std::cerr << " The size of the high level buffer (in case of buffered writer) "; 00023 std::cerr << " will be highlevel_buffer_size."<<std::endl; 00024 } 00025 00026 void SimpleOutputTester::doTest( 00027 int argc, char *argv[]) throw(std::ios_base::failure) 00028 { 00029 if ( argc < 7 ) 00030 usageSimpleOutput(); 00031 else 00032 { 00033 unsigned int set_size = atoi(argv[4]); 00034 log_info(0,"The size of the itemset is set to %d.", set_size); 00035 std::streamsize lowlevel_buffer_size = atoi(argv[5]); 00036 log_info(0,"Low level buffer size is set to %d.", lowlevel_buffer_size); 00037 std::streamsize highlevel_buffer_size = atoi(argv[6]); 00038 log_info(0,"High level buffer size is set to %d.", highlevel_buffer_size); 00039 int rand_seed; 00040 if(argc < 8) 00041 rand_seed = static_cast<int>(time(0)); 00042 else 00043 rand_seed = atoi(argv[7]); 00044 srand(rand_seed); 00045 log_info(0,"The random seed is set to %d.", rand_seed); 00046 00047 if( strcmp(argv[2],"simple") == 0 ) 00048 { 00049 log_info(0,"Simple writer is selected for test."); 00050 log_info(0,"High level buffer size parameter is ignored."); 00051 if(strcmp(argv[1],"stream") == 0) 00052 { 00053 SimpleOutput::params_t par; 00054 par.file_name = argv[3]; 00055 par.mode = FileReprBase::WRITE; 00056 par.file_buffer_size = lowlevel_buffer_size; 00057 SimpleOutput o_manager(&par); 00058 writeAllSubsets( 00059 o_manager, set_size, rand_seed ); 00060 } 00061 else 00062 std::cerr<<"\nOnly stream file representation is implemented for simple writer ;("<<std::endl; 00063 } 00064 else if( strcmp(argv[2],"buffered") == 0 ) 00065 { 00066 log_info(0,"Buffered writer is selected for test."); 00067 if( strcmp(argv[1],"filedes") == 0 ) 00068 { 00069 log_info(0,"filedes is selected as a file representation."); 00070 makeBufferedWriter< BufferedNormalOutput< OutputBase<FDRepr> > >( 00071 argv[3], lowlevel_buffer_size, highlevel_buffer_size, set_size, rand_seed ); 00072 } 00073 else if( strcmp(argv[1],"FILE") == 0 ) 00074 { 00075 log_info(0,"FILE* is selected as a file representation."); 00076 makeBufferedWriter< BufferedNormalOutput< OutputBase<FILERepr> > >( 00077 argv[3], lowlevel_buffer_size, highlevel_buffer_size, set_size, rand_seed ); 00078 } 00079 else if( strcmp(argv[1],"stream") == 0 ) 00080 { 00081 log_info(0,"std::ofstream is selected as a file representation."); 00082 makeBufferedWriter< BufferedNormalOutput< OutputBase<StreamRepr> > >( 00083 argv[3], lowlevel_buffer_size, highlevel_buffer_size, set_size,rand_seed ); 00084 } 00085 else 00086 usageSimpleOutput(); 00087 } 00088 else 00089 usageSimpleOutput(); 00090 } 00091 }