ref: f8d65f9f1c74b101cccfdc08250e31c5e554b899
parent: 8626465772e8dd47dfc7e5f0319f6458d3be5335
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Aug 20 04:29:02 EDT 2024
adds db test
--- /dev/null
+++ b/test/db
@@ -1,0 +1,2 @@
+test five=5 ten=10 half=0.5 str=hello
+secondtest abc='a b c' def='d "e f' ghi='g ''h i'
--- /dev/null
+++ b/test/mkfile
@@ -1,0 +1,8 @@
+</$objtype/mkfile
+
+TEST=\
+ tdb\
+
+</sys/src/cmd/mktest
+
+6.tdb: tdb.6 ../db.6
--- /dev/null
+++ b/test/tdb.c
@@ -1,0 +1,77 @@
+#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);
+}