//test case when dictionary is not full for decompression when index contain all zeroes only void test_Decompression_given_1a1b1c_and_when_dictionary_is_not_full_should_decompress_correctly_into_abc() { int value; OutStream out; Dictionary *dict = initDictionary(10); //create dictionary value = AddDataToDictionary(dict, 1 , (unsigned int)('a') ); assert(value != 0); value = AddDataToDictionary(dict, 1 , (unsigned int)('b') ); assert(value != 0); value = AddDataToDictionary(dict, 1 , (unsigned int)('c') ); assert(value != 0); //create test fixture streamWriteBits_Expect(&out, (unsigned int)('a'), 8); //expect a here streamWriteBits_Expect(&out, (unsigned int)('b'), 8); //expect b here streamWriteBits_Expect(&out, (unsigned int)('c'), 8); //expect c here //run Decompression(&out, 1 , (unsigned int)('a'), dict); Decompression(&out, 1 , (unsigned int)('b'), dict); Decompression(&out, 1 , (unsigned int)('c'), dict); }
int main(int argc, char * argv[]) { fprintf(stdout, "This is bsc, Block Sorting Compressor. Version 3.0.0. 26 August 2011.\n"); fprintf(stdout, "Copyright (c) 2009-2011 Ilya Grebnov <*****@*****.**>.\n\n"); #if defined(_OPENMP) && defined(__INTEL_COMPILER) kmp_set_warnings_off(); #endif ProcessCommandline(argc, argv); if (bsc_init(paramEnableLargePages ? LIBBSC_FEATURE_LARGEPAGES : LIBBSC_FEATURE_NONE) != LIBBSC_NO_ERROR) { fprintf(stderr, "\nInternal program error, please contact the author!\n"); exit(2); } switch (*argv[1]) { case 'e' : case 'E' : Compression(argv); break; case 'd' : case 'D' : Decompression(argv); break; default : ShowUsage(); } return 0; }
U8 *Compression::Decompression(const char *from, int &lenght) { U8 *out = NULL; int lenghtComp; SDL_RWops *src = ged_SDL_RWFromFile(from, "rb"); if(!src) return NULL; lenght = SDL_ReadLE32( src ); lenghtComp = SDL_ReadLE32( src ); out = new U8[lenght]; if(lenghtComp < lenght) { U8 *in = new U8[lenghtComp]; SDL_RWread(src, in, lenghtComp, 1); Decompression(in, lenghtComp, out, lenght, false); delete [] in; } else { SDL_RWread(src, out, lenght, 1); lenght; } SDL_RWclose(src); return out; }
int main(int argc, char ** argv){ int fd_in, fd_out; if(argc != 4){ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } if(argv[1][0] != '-'){ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } if(argv[1][1] == 'c'){ //Quand on veut compresser un fichier if((fd_in = open(argv[2],O_RDONLY)) == -1){ perror("open fd_in"); exit(1); } if((fd_out = open(argv[3],O_WRONLY|O_CREAT|O_TRUNC,0600)) == -1){ perror("open fd_out"); exit(2); } Compression(fd_in,fd_out); }else if(argv[1][1] == 'd'){ //Quand on veut decompresser un fichier if((fd_in = open(argv[2],O_RDONLY)) == -1){ perror("open fd_in"); exit(1); } if((fd_out = open(argv[3],O_WRONLY|O_CREAT|O_TRUNC,0600)) == -1){ perror("open fd_out"); exit(2); } Decompression(fd_in,fd_out); }else{ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } return EXIT_SUCCESS; }
bool Compression::Decompression(SDL_RWops* src, unsigned int lenghtComp, void *out, unsigned int lenght) { if(lenghtComp < lenght) { U8 *in = new U8[lenghtComp]; SDL_RWread(src, in, lenghtComp, 1); bool res = Decompression(in, lenghtComp, out, lenght, false); #ifdef _DEBUG if(!res) { GLOUTPUT("*** Decompression error (%ld, %ld)\n", lenghtComp, lenght); } #endif delete [] in; return res; } return false; }
int main(int argc, char *argv[]) { int source = 0, target = 0, funcsion = 0, i; clock_t start, end; if (argc < 6) { printf("\n程序参数输入有误!\n\n"); Instruction(argv[0]); return EXIT_FAILURE; } start = clock(); //参数解析 for (i = 1; i < 6; ++i) { if (!strcmp(argv[i], "-c")) { funcsion = i; } else if (!strcmp(argv[i], "-s")) { if (i != 5) { source = i + 1; } else { printf("参数输入有误!\n\n"); Instruction(argv[0]); return EXIT_FAILURE; } } else if (!strcmp(argv[i], "-t")) { if (i != 5) { target = i + 1; } else { printf("参数输入有误!\n\n"); return EXIT_FAILURE; } } else if (!strcmp(argv[i], "-d")) { funcsion = i; } } if ((!strcmp(argv[funcsion], "-c")) && source != 0 && target != 0) { if (Compression(argv[source], argv[target]) == 0) { printf("压缩失败!\n"); return EXIT_FAILURE; } else { end = clock(); printf("压缩时间:%lf秒\n\n",((double)end - start) / CLOCKS_PER_SEC); } } else if ((!strcmp(argv[funcsion], "-d")) && source != 0 && target != 0) { if (Decompression(argv[source], argv[target]) == 0) { printf("解压缩失败!\n"); return EXIT_FAILURE; } else { end = clock(); printf("解压成功!\n"); printf("解压缩时间:%lf秒\n\n",((double)end - start) / CLOCKS_PER_SEC); } } else { printf("命令错误!\n"); Instruction(argv[0]); } return EXIT_SUCCESS; }