//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);
}
// test case when dictionary is not needed to be refresh, index is only 1
void test_LZ78_Decompression_Variable_given_input_1a1b_and_size_of_10_should_decompress_into_ab()
{
    int dictSize = 10;
    char *infilename = "anyfile_in.txt";
    char *outfilename = "anyfile_out.txt";
    Dictionary *dict;
    InStream in;
    OutStream out;
    
    // create test fixture
    initInStream_ExpectAndReturn(&in);
    initOutStream_ExpectAndReturn(&out);
    openInStream_ExpectAndReturn(infilename, "rb+" , &in, &in);                       
    openOutStream_ExpectAndReturn(outfilename, "wb+" , &out, &out); 
    streamReadBits_ExpectAndReturn(&in, 1, 1);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, (unsigned int)('a') );
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, (unsigned int)('a') , 8 );            //expect a
    streamReadBits_ExpectAndReturn(&in, 2, 2);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, (unsigned int)('b') );
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, (unsigned int)('a') , 8 );             //expect a
    streamWriteBits_Expect(&out, (unsigned int)('b') , 8 );             //expect b
    streamReadBits_ExpectAndReturn(&in, 2, 2);
    checkEndOfFile_ExpectAndReturn(&in, EOF);
    closeInStream_ExpectAndReturn(&in, &in);
    closeOutStream_ExpectAndReturn(&out , &out);
    freeInStream_Expect(&in);
    freeOutStream_Expect(&out);    
    
    LZ78_Decompression_Variable(&in, &out, dict, infilename, outfilename, dictSize);
}
Beispiel #3
0
void test_emitCode_given_index_257_should_translate_to_nan_and_output_nan(){
  Dictionary *dictionary = dictionaryNew(100);
  dictionary->entries[1].code = "nan";
  OutStream out;
  int index = 257;
  
  streamWriteBits_Expect(&out, 110, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 110, 8);
  
  emitCode(dictionary, index, &out);
}
Beispiel #4
0
/*
 * Input : 98, 97, 110, 257, 259
 *
 * Output : bananana
 *
 */
void test_lzwDecode_case_3_should_decode_into_bananana(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(4096);
  OutStream out;
  InStream in;
   
  streamReadBits_ExpectAndReturn(&in, 8, 98);
  streamWriteBits_Expect(&out, 98, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 97);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 110);
  streamWriteBits_Expect(&out, 110, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 257);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 110, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 259);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 110, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, -1);
  
  Try{
    lzwDecode(&in, dictionary, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
    TEST_ASSERT_EQUAL_STRING("ba", dictionary->entries[0].code);
    TEST_ASSERT_EQUAL_STRING("an", dictionary->entries[1].code);
    TEST_ASSERT_EQUAL_STRING("na", dictionary->entries[2].code);
    TEST_ASSERT_EQUAL_STRING("ana", dictionary->entries[3].code);
  }
}
Beispiel #5
0
void test_emitCode_given_index_256_should_translate_to_ab_and_output_a_b(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(100);
  dictionary->entries[0].code = "ab";
  OutStream out;
  int index = 256;
  
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 98, 8);
  
  Try{
    emitCode(dictionary, index, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_EXCEEDING_DICTIONARY_SIZE, e);
  }
}
// test case for binary input when dictionary is needed to be refresh 
void test_LZ78_Decompression_Variable_given_input_1_00_2_4f_1_00_and_size_of_1_should_decompress_into_00_00_4f_00()
{
    int dictSize = 2;
    char *infilename = "anyfile_in.txt";
    char *outfilename = "anyfile_out.txt";
    Dictionary *dict;
    InStream in;
    OutStream out;
    
    // create test fixture
    initInStream_ExpectAndReturn(&in);
    initOutStream_ExpectAndReturn(&out);
    openInStream_ExpectAndReturn(infilename, "rb+" , &in, &in);                       
    openOutStream_ExpectAndReturn(outfilename, "wb+" , &out, &out); 
    streamReadBits_ExpectAndReturn(&in, 1, 1);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, 0x00 );
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, 0x00 , 8 );            //expect 0x00
    streamReadBits_ExpectAndReturn(&in, 2, 2);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, 0x4f );
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, 0x00 , 8 );             //expect 0x00
    streamWriteBits_Expect(&out, 0x4f , 8 );             //expect 0x4f
    streamReadBits_ExpectAndReturn(&in, 1, 1);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, 0x00 );       
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, 0x00 , 8 );             //expect 0x00
    streamReadBits_ExpectAndReturn(&in, 2, EOF);
    checkEndOfFile_ExpectAndReturn(&in, 1);
    closeInStream_ExpectAndReturn(&in, &in);
    closeOutStream_ExpectAndReturn(&out , &out);
    freeInStream_Expect(&in);
    freeOutStream_Expect(&out);
    
    LZ78_Decompression_Variable(&in, &out, dict, infilename, outfilename, dictSize);
}
Beispiel #7
0
void test_emitCode_given_index_97_should_translate_to_a_and_output_a(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(100);
  OutStream out;
  int index = 97;
  
  streamWriteBits_Expect(&out, 97, 8);
  
  Try{
    emitCode(dictionary, index, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_EXCEEDING_DICTIONARY_SIZE, e);
  }
}
Beispiel #8
0
void test_lzwDecode_given_code_97_should_decode_into_a(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(100);
  OutStream out;
  InStream in;
   
  streamReadBits_ExpectAndReturn(&in, 8, 97);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, -1);
  
  Try{
    lzwDecode(&in, dictionary, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(END_OF_STREAM, e);
  }
}