[% USE format -%]
[% indented = format('%-15s %s') -%]
#include <pslib.h>
#include <[% pkg_name %].h>
#include <stdlib.h>
#include <string.h>

#define MAX_STRING_LENGTH 1024

int main ()
{
[% FOREACH table = tables -%]
    {
        psMetadata      *md;
        [% indented(table.object_name, "*object") %];

        md = psMetadataAlloc();
[% FOREACH item = table.columns -%]
[% IF item.type == "S32" or item.type == "F32" or item.type == "F64" -%]
        if (!psMetadataAdd[% item.type %](md, PS_LIST_TAIL, "[% item.name %]", 0, NULL, [% item.test %])) {
[% ELSIF item.type == "STR" -%]
        if (!psMetadataAddStr(md, PS_LIST_TAIL, "[% item.name %]", 0, NULL, [% item.test %])) {
[% ELSIF item.type == "BOOL" -%]
        if (!psMetadataAdd(md, PS_LIST_TAIL, "[% item.name %]", PS_DATA_BOOL, NULL, [% item.test %])) {
[% END -%]
            psFree(md);
            exit(EXIT_FAILURE);
        }
[% END -%]

        object = [% table.namespace %]ObjectFromMetadata(md);
        if (!object) {
            psFree(md);
            exit(EXIT_FAILURE);
        }

        psFree(md);

[% FOREACH item = table.columns -%]
[% IF item.type == "S32" or item.type == "F32" or item.type == "F64" or item.type == "BOOL" -%]
        if (!object->[% item.name %] == [% item.test %]) {
[% ELSIF item.type == "STR" -%]
        if (strncmp(object->[% item.name %], [% item.test %], MAX_STRING_LENGTH)) {
[% END -%]
            psFree(object);
            exit(EXIT_FAILURE);
        }
[% END -%]

        psFree(object);
    }

[% END -%]
    exit(EXIT_SUCCESS);
}
