ref: 13590f759547f4ef544b251f2966b4ed2d82038c
dir: /test/tdb.c/
#include <u.h> #include <libc.h> #include "../db.h" #define LIST(DO) \ DO(five, INT, int, nil) \ DO(ten, INT, int, nil) \ DO(half, FLOAT, double, nil) \ DO(str, STRING, char*, nil) typedef struct Data Data; struct Data { LIST(STRUCT) }; Data data; Sdata serdata[] = { LIST(SDATA) ENDSDATA }; void main(int, char**) { Db *db; Dpack *dv; Dtuple *tp; db = opendb("db"); dv = getdpack(db, "test"); deserialize(dv, &data, serdata); if (data.five != 5) fprint(2, "five != 5 (%d)\n", data.five); if (data.ten != 10) fprint(2, "ten != 10 (%d)\n", data.ten); if (data.half != 0.5) fprint(2, "half != 0.5 (%f)\n", data.half); if (strcmp(data.str, "hello") != 0) fprint(2, "str != 'hello' (%s)\n", data.str); data.five = 50; data.ten = 100; data.half = 0.05; data.str = "bye'bye"; serialize(dv, &data, serdata); for (tp = dv->tuple; tp; tp = tp->next) { if (strcmp(tp->key, "five") == 0) { if (strcmp(tp->value, "50") != 0) fprint(2, "s: five != 50 (%s)\n", tp->value); continue; } if (strcmp(tp->key, "ten") == 0) { if (strcmp(tp->value, "100") != 0) fprint(2, "s: ten != 100 (%s)\n", tp->value); continue; } if (strcmp(tp->key, "half") == 0) { if (strcmp(tp->value, "0.050000") != 0) fprint(2, "s: half != 0.05 (%s)\n", tp->value); continue; } if (strcmp(tp->key, "str") == 0) { if (strcmp(tp->value, "bye'bye") != 0) fprint(2, "s: str != 'bye' (%s)\n", tp->value); continue; } fprint(2, "s: %s = %s\n", tp->key, tp->value); } writedb(db, "dbout"); exits(nil); }