This source file includes following definitions.
- TEST
#include "courgette/encoded_program.h"
#include "courgette/streams.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(EncodedProgramTest, Test) {
courgette::EncodedProgram* program = new courgette::EncodedProgram();
uint32 base = 0x00900000;
program->set_image_base(base);
EXPECT_TRUE(program->DefineRel32Label(5, 0));
EXPECT_TRUE(program->DefineAbs32Label(7, 4));
program->EndLabels();
EXPECT_TRUE(program->AddOrigin(0));
EXPECT_TRUE(program->AddAbs32(7));
EXPECT_TRUE(program->AddRel32(5));
courgette::SinkStreamSet sinks;
EXPECT_TRUE(program->WriteTo(&sinks));
delete program;
courgette::SinkStream sink;
bool can_collect = sinks.CopyTo(&sink);
EXPECT_TRUE(can_collect);
const void* buffer = sink.Buffer();
size_t length = sink.Length();
courgette::SourceStreamSet sources;
bool can_get_source_streams = sources.Init(buffer, length);
EXPECT_TRUE(can_get_source_streams);
courgette::EncodedProgram *encoded2 = new courgette::EncodedProgram();
bool can_read = encoded2->ReadFrom(&sources);
EXPECT_TRUE(can_read);
courgette::SinkStream assembled;
bool can_assemble = encoded2->AssembleTo(&assembled);
EXPECT_TRUE(can_assemble);
delete encoded2;
const void* assembled_buffer = assembled.Buffer();
size_t assembled_length = assembled.Length();
EXPECT_EQ(8U, assembled_length);
static const uint8 golden[] = {
0x04, 0x00, 0x90, 0x00,
0xF8, 0xFF, 0xFF, 0xFF
};
EXPECT_EQ(0, memcmp(assembled_buffer, golden, 8));
}