Beispiel #1
0
void invoke_object(uint32_t max_symbols,
                   uint32_t max_symbol_size,
                   uint32_t multiplier)
{

    typedef kodo::object_encoder<ObjectData, Encoder, Partitioning>
        object_encoder;

    typedef kodo::object_decoder<Decoder, Partitioning>
        object_decoder;

    typedef Partitioning partitioning;

    uint32_t object_size = rand_nonzero(max_symbols*max_symbol_size*multiplier);

    dummy_object_data data(object_size);
    partitioning p(max_symbols, max_symbol_size, object_size);

    typename Encoder::factory encoder_factory(max_symbols, max_symbol_size);
    typename Decoder::factory decoder_factory(max_symbols, max_symbol_size);

    object_encoder obj_encoder(encoder_factory, data);
    object_decoder obj_decoder(decoder_factory, obj_encoder.object_size());

    EXPECT_EQ(p.blocks(), obj_encoder.encoders());
    EXPECT_EQ(p.blocks(), obj_decoder.decoders());

    EXPECT_TRUE(obj_encoder.encoders() == obj_decoder.decoders());

    EXPECT_EQ(p.object_size(), obj_decoder.object_size());
    EXPECT_EQ(p.object_size(), obj_decoder.object_size());

    for(uint32_t i = 0; i < obj_encoder.encoders(); ++i)
    {
        typename Encoder::pointer encoder = obj_encoder.build(i);
        typename Decoder::pointer decoder = obj_decoder.build(i);

        EXPECT_EQ(p.symbols(i), encoder->symbols());
        EXPECT_EQ(p.symbols(i), decoder->symbols());

        EXPECT_EQ(p.symbol_size(i), encoder->symbol_size());
        EXPECT_EQ(p.symbol_size(i), decoder->symbol_size());

        EXPECT_EQ(p.block_size(i), encoder->block_size());
        EXPECT_EQ(p.block_size(i), decoder->block_size());

        EXPECT_EQ(p.byte_offset(i), encoder->byte_offset());

        EXPECT_EQ(p.bytes_used(i), encoder->bytes_used());
        EXPECT_EQ(p.bytes_used(i), decoder->bytes_used());
    }

}
Beispiel #2
0
void invoke_random_annex_partial(uint32_t max_symbols,
                                 uint32_t max_symbol_size,
                                 uint32_t multiplier)
{

    uint32_t object_size = max_symbols * max_symbol_size * multiplier;
    object_size -= (rand() % object_size);

    uint32_t annex_size = kodo::max_annex_size(
        max_symbols, max_symbol_size, object_size);

    if(annex_size > 0)
    {
        // Randomize the actual annex size
        annex_size -= (rand() % annex_size);
    }

    typedef kodo::random_annex_encoder<Encoder, Partitioning>
        random_annex_encoder;

    typedef kodo::random_annex_decoder<Decoder, Partitioning>
        random_annex_decoder;

    std::vector<uint8_t> data_in = random_vector(object_size);
    std::vector<uint8_t> data_out(object_size, '\0');

    typename Encoder::factory encoder_factory(max_symbols, max_symbol_size);
    typename Decoder::factory decoder_factory(max_symbols, max_symbol_size);

    random_annex_encoder obj_encoder(
        annex_size, encoder_factory, sak::storage(data_in));

    random_annex_decoder obj_decoder(
        annex_size, decoder_factory, obj_encoder.object_size());

    EXPECT_TRUE(obj_encoder.encoders() >= 1);
    EXPECT_TRUE(obj_decoder.decoders() >= 1);
    EXPECT_TRUE(obj_encoder.encoders() == obj_decoder.decoders());

    uint32_t bytes_used = 0;

    for(uint32_t i = 0; i < obj_encoder.encoders(); ++i)
    {
        typename Encoder::pointer encoder = obj_encoder.build(i);
        typename random_annex_decoder::pointer_type decoder =
            obj_decoder.build(i);

        if(kodo::is_systematic_encoder(encoder))
            kodo::set_systematic_off(encoder);

        EXPECT_TRUE(encoder->block_size() >= encoder->bytes_used());
        EXPECT_TRUE(decoder->block_size() >= decoder->bytes_used());

        EXPECT_TRUE(encoder->block_size() == decoder->block_size());
        EXPECT_TRUE(encoder->bytes_used() == decoder->bytes_used());
        EXPECT_TRUE(encoder->payload_size() == decoder->payload_size());

        std::vector<uint8_t> payload(encoder->payload_size());

        while(!decoder->is_complete())
        {
            encoder->encode( &payload[0] );
            decoder->decode( &payload[0] );
        }

        sak::mutable_storage storage = sak::storage(
            &data_out[0] + bytes_used, decoder->bytes_used());

        decoder.unwrap()->copy_symbols(storage);

        bytes_used += decoder->bytes_used();
    }

    EXPECT_EQ(bytes_used, object_size);
    EXPECT_TRUE(std::equal(data_in.begin(),
                           data_in.end(),
                           data_out.begin()));

}