Exemplo n.º 1
0
/*
 * Input : 97, 256, 257, 97
 *
 * Output : aaaaaaa
 *
 */
void test_lzwDecode_case_2_should_decode_into_aaaaaaa(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(4096);
  OutStream out;
  InStream in;
   
  streamReadBits_ExpectAndReturn(&in, 8, 97);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 256);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 257);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 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);
    TEST_ASSERT_EQUAL_STRING("aa", dictionary->entries[0].code);
    TEST_ASSERT_EQUAL_STRING("aaa", dictionary->entries[1].code);
    TEST_ASSERT_EQUAL_STRING("aaaa", dictionary->entries[2].code);
  }
}
// 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);
}
Exemplo n.º 3
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);
  }
}
Exemplo n.º 4
0
/*
 * Input : 98, 97, 110, 257, 97, 95, 258, 258, 256
 *
 * Output : banana_nanaba
 *
 */
void test_lzwDecode_case_4_should_decode_into_banana_nanaba(){
  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, 97);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 95);
  streamWriteBits_Expect(&out, 95, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 258);
  streamWriteBits_Expect(&out, 110, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 258);
  streamWriteBits_Expect(&out, 110, 8);
  streamWriteBits_Expect(&out, 97, 8);
  streamReadBits_ExpectAndReturn(&in, 9, 256);
  streamWriteBits_Expect(&out, 98, 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);
    TEST_ASSERT_EQUAL_STRING("a_", dictionary->entries[4].code);
    TEST_ASSERT_EQUAL_STRING("_n", dictionary->entries[5].code);
    TEST_ASSERT_EQUAL_STRING("nan", dictionary->entries[6].code);
    TEST_ASSERT_EQUAL_STRING("nab", dictionary->entries[7].code);
  }
}
Exemplo n.º 5
0
void test_lzwDecode_given_code_98_97_110_should_decode_into_ban(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(100);
  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, -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);
  }
}
Exemplo n.º 6
0
/*
 * Input : -1
 *
 * Output : Should throw
 *
 */
void test_lzwDecode_case_6_should_throw_invalid_index_error(){
  CEXCEPTION_T e;
  Dictionary *dictionary = dictionaryNew(4096);
  OutStream out;
  InStream in;
   
  streamReadBits_ExpectAndReturn(&in, 8, -1);
  
  Try{
    lzwDecode(&in, dictionary, &out);
  }Catch(e){
    TEST_ASSERT_EQUAL(ERR_INVALID_INDEX, e);
  }
}
// test case for binary input when dictionary is not needed to be refresh 
void test_LZ78_Decompression_Variable_given_input_1_00_2_4f_3_00_and_size_of_10_should_decompress_into_00_00_4f_00_4f_00()
{
    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, 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, 2, 3);
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamReadBits_ExpectAndReturn(&in, 8, 0x00 );       
    checkEndOfFile_ExpectAndReturn(&in, 0);
    streamWriteBits_Expect(&out, 0x00 , 8 );             //expect 0x00
    streamWriteBits_Expect(&out, 0x4f , 8 );             //expect 0x4f
    streamWriteBits_Expect(&out, 0x00 , 8 );             //expect 0x00
    streamReadBits_ExpectAndReturn(&in, 3, 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);
}