Exemplo n.º 1
0
// Verify data encoding
void check(atom test, atom::type_t type, atom::enc_t enc, size_t size)
{
    atom::type_t type_found;
    atom::enc_t enc_found;
    byte_vector test_bytes = test.encode_vector();
    atom copy;

    // Dump
    printf("Atom: ");
    test.print();

    // What's in the atom?
    type_found = test.get_type();
    printf("\nData Type: %s\n", atom_type_to_string(type_found));
    if (type != type_found)
    {
        printf("*** Failed (expected %s) ***\n", atom_type_to_string(type));
        exit(1);
    }

    // How is it encoded?
    enc_found = test.get_enc();
    printf("Encoding: %s\n", atom_enc_to_string(enc_found));
    if (enc != enc_found)
    {
        printf("*** Failed (expected %s) ***\n", atom_enc_to_string(enc));
        exit(1);
    }

    // Debug
    dump(test_bytes);

    // Check total size
    if (test.get_header_size() + size != test_bytes.size())
    {
        printf("*** Failed (expected %u bytes) ***\n",
               (unsigned int)(test.get_header_size() + size));
        exit(1);
    }

    // Reconstruct atom
    printf("Testing reconstructed copy ...\n");
    copy.decode_vector(test_bytes);
    if (test != copy)
    {
        printf("*** Failed (decoded object differs) ***\n");
        exit(1);
    }

    // Bump the counter
    test_count++;
}