int testDeserialization()
{
    char context[12];

    struct DHTModule module = {
        .name = "TestModule",
        .context = context,
        .deserialize = deserialize
    };

    char buffer[512];
    struct Allocator* allocator = BufferAllocator_new(buffer, 512);
    struct Reader* reader = ArrayReader_new(control, strlen(control), allocator);

    struct DHTModuleRegistry* reg = DHTModules_deserialize(reader, allocator);
    DHTModules_register(&module, reg);

    context[11] = '\0';

    printf("Deserialization output is: %s\n", context);

    return memcmp(context, "Hello World", 11);
}

int main()
{
    return
        testSerialization()
      | testDeserialization();
}
Ejemplo n.º 2
0
bool MetavoxelTests::run() {
    
    qDebug() << "Running transmission tests...";
    qDebug();
    
    // seed the random number generator so that our tests are reproducible
    srand(0xBAAAAABE);

    // create two endpoints with the same header
    QByteArray datagramHeader("testheader");
    Endpoint alice(datagramHeader), bob(datagramHeader);
    
    alice.setOther(&bob);
    bob.setOther(&alice);
    
    // perform a large number of simulation iterations
    const int SIMULATION_ITERATIONS = 10000;
    for (int i = 0; i < SIMULATION_ITERATIONS; i++) {
        if (alice.simulate(i) || bob.simulate(i)) {
            return true;
        }
    }
    
    qDebug() << "Sent" << highPriorityMessagesSent << "high priority messages, received" << highPriorityMessagesReceived;
    qDebug() << "Sent" << unreliableMessagesSent << "unreliable messages, received" << unreliableMessagesReceived;
    qDebug() << "Sent" << reliableMessagesSent << "reliable messages, received" << reliableMessagesReceived;
    qDebug() << "Sent" << streamedBytesSent << "streamed bytes, received" << streamedBytesReceived;
    qDebug() << "Sent" << datagramsSent << "datagrams with" << bytesSent << "bytes, received" <<
        datagramsReceived << "with" << bytesReceived << "bytes";
    qDebug() << "Created" << sharedObjectsCreated << "shared objects, destroyed" << sharedObjectsDestroyed;
    qDebug() << "Performed" << objectMutationsPerformed << "object mutations";
    qDebug();
    
    qDebug() << "Running serialization tests...";
    qDebug();
    
    if (testSerialization(Bitstream::HASH_METADATA) || testSerialization(Bitstream::FULL_METADATA)) {
        return true;
    }
    
    qDebug() << "All tests passed!";
    
    return false;
}
Ejemplo n.º 3
0
void
EventTest::testSerialization() {
    Event* toTest = new EventTestTestEvent();
    testSerialization(toTest, EventTestTestEvent::getEventTestTestEventType());
    delete toTest;
}
Ejemplo n.º 4
0
 void run()
 {
     testSerialization();
     testParseJSONArray();
     testParseJSONArrayWithInvalidChildrenObjects();
 }