/*      This function is used to determine the file size of 
 *      two input files
 *
 *      Inputs:
 *                  infilename1   the filename for input file 1
 *                  infilename2   the filename for input file 2
 *
 *      Return:
 *                  1   if the two files have the same size
 *                  0   if the two files have a different size
 */
int verifyDecompressedFile(char *infilename1, char *infilename2)
{
    unsigned int value1, value2;
    int counter1 = -1, counter2 = -1;
    InStream *in1, *in2;
    
    in1 = initInStream();                                              
    in2 = initInStream();                                              
    
    in1 = openInStream(infilename1, "rb+" , in1);                         
    in2 = openInStream(infilename2, "rb+" , in2);                      
    
    do
    {
        value1 = streamReadBits(in1, 8);
        counter1++;
    }while(!checkEndOfFile(in1) );

    do
    {
        value2 = streamReadBits(in2, 8);
        counter2++;
    }while(!checkEndOfFile(in2) );
    
    closeInStream(in1);                                           
    closeInStream(in2);   
    freeInStream(in1);                                           
    freeInStream(in2);        

    if( counter2 == counter1)
        return 1;
    else
        return 0;
}
void assertFile(char *Source, char *Target,int lineNumber)
{
	long unsigned int srcFileSize, targetFileSize, position  ;
	unsigned int srcData,targetData ,srcfileStatus = 0,targetFileStatus = 0;
	char ErrorMsg[1024] ={};
	
	InStream *src = initInStream();
	InStream *target = initInStream();
	
	src = openInStream(Source, "rb" , src);
    target = openInStream(Target, "rb" , target);
	
	fseek(src->file,0,SEEK_END);
	fseek(target->file,0,SEEK_END);
	
	srcFileSize = ftell(src->file);
	targetFileSize = ftell(target->file);
	
	UNITY_TEST_ASSERT_EQUAL_UINT32(srcFileSize,targetFileSize,lineNumber,"The target file size does not match the source file size!");
	
	rewind(src->file);
	rewind(target->file);
	
	
	while(1)
	{
		srcData = streamReadBits(src,8);
		targetData = streamReadBits(target,8);
		
		srcfileStatus = checkEndOfFile(src)	;
		targetFileStatus = checkEndOfFile(target);
		
		if(srcfileStatus)
		{
			closeInStream(src);
			freeInStream(src);
		}
		if(targetFileStatus)
		{
			closeInStream(target);
			freeInStream(target);
		}
		
		UNITY_TEST_ASSERT_EQUAL_UINT8(srcfileStatus,targetFileStatus,lineNumber,"Target file ended earlier or later than the source file!");
		
		if (srcData != targetData)
		{
			position = ftell(target->file);
			sprintf(ErrorMsg,"At position 0x%x, target data does not match source data!",position); 
			UNITY_TEST_ASSERT_EQUAL_UINT8(srcData,targetData,lineNumber,ErrorMsg);
		}
		
		if(srcfileStatus == 1 || targetFileStatus == 1)
			break;
	}
}
void test_LZ78_Compression_Variable_mode_given_input_file_sampleText_forCompresssion_2()
{
    InStream *in = initInStream();
    OutStream *out = initOutStream();
    Dictionary *dictionary = initDictionary(100);
    
    in = openInStream("test/support/Source/sampleText_forCompresssion_2.txt", "rb" , in);
    out = openOutStream("test/support/Compressed/Variable/sampleText_forCompresssion_Compressed_Variable_2.txt", "wb" , out);
      
    LZ78_Compressor(dictionary,in,out,Variable);
    
    TEST_ASSERT_EQUAL_STRING("A",dictionary->Entry[0].data);
    TEST_ASSERT_EQUAL_STRING("AA",dictionary->Entry[1].data);
    TEST_ASSERT_EQUAL_STRING("AAA",dictionary->Entry[2].data);
    TEST_ASSERT_EQUAL_STRING("AAA ",dictionary->Entry[3].data);
    TEST_ASSERT_EQUAL_STRING("B",dictionary->Entry[4].data);
    TEST_ASSERT_EQUAL_STRING("BB",dictionary->Entry[5].data);
    TEST_ASSERT_EQUAL_STRING("BBB",dictionary->Entry[6].data);
    TEST_ASSERT_EQUAL_STRING("BBBB",dictionary->Entry[7].data);
    TEST_ASSERT_EQUAL_STRING("C",dictionary->Entry[8].data);
    TEST_ASSERT_EQUAL_STRING("",dictionary->Entry[9].data);
    
    closeInStream(in);
    closeOutStream(out);
    freeInStream(in);
    freeOutStream(out);
    destroyDictionary(dictionary,100);
}
예제 #4
0
파일: test_InStream.c 프로젝트: poonjon/LZW
void test_streamReadBits_given_a_0x06_0x20_0x61_0x06_0xe0_should_return_98_97_110(){
	CEXCEPTION_T e;
  InStream *in;
  int result, result2, result3;
  tempCurrentByte = 0;
  Try{
    in = openInStream("test/data/InputTest_7.txt", "r");
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_CANNOT_OPEN_FILE, e);
  }

  Try{
    result = streamReadBits(in, 12);
    result2 = streamReadBits(in, 12);
    result3 = streamReadBits(in, 12);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
  }  
    
  TEST_ASSERT_EQUAL(4, in->bitIndex);
  TEST_ASSERT_EQUAL(0, in->currentByte);
  
  closeInStream(in);

  TEST_ASSERT_EQUAL(98, result);
  TEST_ASSERT_EQUAL(97, result2);
  TEST_ASSERT_EQUAL(110, result3);
}
예제 #5
0
void test_streamReadBits_given_a_0x804040_should_return_97_and_257(){
	CEXCEPTION_T e;
  InStream *in;
  int result, result2;

  Try{
    in = openInStream("test/data/InputTest_6.txt", "r");
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_CANNOT_OPEN_FILE, e);
  }

  Try{
    result = streamReadBits(in, 8);
    result2 = streamReadBits(in, 9);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
  }  
    
  TEST_ASSERT_EQUAL(1, in->bitIndex);
  TEST_ASSERT_EQUAL(0, in->currentByte);
  
  closeInStream(in);

  TEST_ASSERT_EQUAL(97, result);
  TEST_ASSERT_EQUAL(256, result2);
}
예제 #6
0
void test_streamReadBits_given_bitSize_16_storageType_int_should_extract_data_from_the_file()
{
    int storage;
    int i ;
    
    InStream *in = initInStream();
    in = openInStream("test/support/test_streamReadBits.txt", "rb" , in);

    storage = streamReadBits(in,16) ;
    
    TEST_ASSERT_EQUAL(0x4241,storage); /*Text file in little endian format*/
    closeInStream(in);
    freeInStream(in);
}
예제 #7
0
void test_streamReadBits_given_bitSize_64_storageType_string_should_extract_data_from_the_file()
{
    char storage[10] = {};
    int i ;
    InStream *in = initInStream();
    in = openInStream("test/support/test_streamReadBits.txt", "rb" , in);

    for ( i = 0 ; i < 8 ; i ++ )
        storage[i] = (char)streamReadBits(in,8) ;
    
    TEST_ASSERT_EQUAL_STRING("ABCDEFGH",storage);
    closeInStream(in);
    freeInStream(in);
}
예제 #8
0
파일: test_InStream.c 프로젝트: poonjon/LZW
void test_openInStream_given_existant_file_should_read_6(){
	CEXCEPTION_T e;
  InStream *in;
  int result;

  Try{
    in = openInStream("test/data/InputTest_2.txt", "r");
    result = fgetc(in->file);
    closeInStream(in);
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_CANNOT_OPEN_FILE, e);
  }

  TEST_ASSERT_EQUAL('6', result);
}
void test_LZ78_Compression_Variable_mode_given_input_file_libjansson_4_dll_()
{
    InStream *in = initInStream();
    OutStream *out = initOutStream();
    Dictionary *dictionary = initDictionary(4096);
    
    in = openInStream("test/support/Source/libjansson-4.dll", "rb" , in);
    out = openOutStream("test/support/Compressed/Variable/libjansson-4_Compressed_Variable.dll", "wb" , out);
      
    LZ78_Compressor(dictionary,in,out,Variable);

    closeInStream(in);
    closeOutStream(out);
    freeInStream(in);
    freeOutStream(out);
    destroyDictionary(dictionary,4096);
}
예제 #10
0
void test_openInStream_open_a_text_file_available_should_not_throw_error(void)
{
    CEXCEPTION_T ERR;
    
    InStream *in = initInStream();
    
    Try
	{
        in = openInStream("test/support/test_in.txt", "rb" , in);
        TEST_ASSERT_NOT_NULL(in);
        TEST_ASSERT_NOT_NULL(in->file);
        TEST_ASSERT_EQUAL("test/support/test_in.txt", in->filename);
    }
    Catch(ERR){
        TEST_ASSERT_EQUAL(ERR_FAILED_TO_OPEN, ERR);
		TEST_FAIL_MESSAGE("File not exist!");
    }
    closeInStream(in);
    freeInStream(in);
}
예제 #11
0
파일: test_InStream.c 프로젝트: poonjon/LZW
void test_streamReadBits_given_a_0x10_0x01_0x01_should_return_256_and_257(){
	CEXCEPTION_T e;
  InStream *in;
  int result, result2;
  tempCurrentByte = 0;
  Try{
    in = openInStream("test/data/InputTest_5.txt", "r");
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_CANNOT_OPEN_FILE, e);
  }

  result = streamReadBits(in, 12);
  result2 = streamReadBits(in, 12);
    
  TEST_ASSERT_EQUAL(0, in->bitIndex);
  TEST_ASSERT_EQUAL(0, in->currentByte);
  
  closeInStream(in);

  TEST_ASSERT_EQUAL(256, result);
  TEST_ASSERT_EQUAL(257, result2);
}
예제 #12
0
파일: test_InStream.c 프로젝트: poonjon/LZW
void test_streamReadBits_given_a_0x06_0x10_should_return_a(){
	CEXCEPTION_T e;
  InStream *in;
  int result;
  tempCurrentByte = 0;
  Try{
    in = openInStream("test/data/InputTest_3.txt", "r");
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_CANNOT_OPEN_FILE, e);
  }
  
  Try{
    result = streamReadBits(in, 12);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
  }
  
  TEST_ASSERT_EQUAL(4, in->bitIndex);
  TEST_ASSERT_EQUAL(0, in->currentByte);
  
  closeInStream(in);

  TEST_ASSERT_EQUAL('a', result);
}