aboutsummaryrefslogtreecommitdiffstats
path: root/wrap-json.test.result
diff options
context:
space:
mode:
authorjobol <jose.bollo@iot.bzh>2018-05-14 11:23:23 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:12:02 +0100
commitbfb135e978673215dc9045d5d26106b613fc84c8 (patch)
tree4496c6834362e381dabfe00db7c0d8685f97d77c /wrap-json.test.result
parent359e7863f524eeb3eae39bf0c5f77917487b984a (diff)
wrap-json: Record result of tests
Signed-off-by: jobol <jose.bollo@iot.bzh>
Diffstat (limited to 'wrap-json.test.result')
-rw-r--r--wrap-json.test.result405
1 files changed, 405 insertions, 0 deletions
diff --git a/wrap-json.test.result b/wrap-json.test.result
new file mode 100644
index 0000000..b7acbb5
--- /dev/null
+++ b/wrap-json.test.result
@@ -0,0 +1,405 @@
+pack("n")
+ SUCCESS null
+
+pack("b", 1)
+ SUCCESS true
+
+pack("b", 0)
+ SUCCESS false
+
+pack("i", 1)
+ SUCCESS 1
+
+pack("I", (uint64_t)0x123456789abcdef)
+ SUCCESS 81985529216486895
+
+pack("f", 3.14)
+ SUCCESS 3.1400000000000001
+
+pack("s", "test")
+ SUCCESS "test"
+
+pack("s?", "test")
+ SUCCESS "test"
+
+pack("s?", NULL)
+ SUCCESS null
+
+pack("s#", "test asdf", 4)
+ SUCCESS "test"
+
+pack("s%", "test asdf", (size_t)4)
+ SUCCESS "test"
+
+pack("s#", buffer, 4)
+ SUCCESS "test"
+
+pack("s%", buffer, (size_t)4)
+ SUCCESS "test"
+
+pack("s++", "te", "st", "ing")
+ SUCCESS "testing"
+
+pack("s#+#+", "test", 1, "test", 2, "test")
+ SUCCESS "ttetest"
+
+pack("s%+%+", "test", (size_t)1, "test", (size_t)2, "test")
+ SUCCESS "ttetest"
+
+pack("{}", 1.0)
+ SUCCESS { }
+
+pack("[]", 1.0)
+ SUCCESS [ ]
+
+pack("o", json_object_new_int(1))
+ SUCCESS 1
+
+pack("o?", json_object_new_int(1))
+ SUCCESS 1
+
+pack("o?", NULL)
+ SUCCESS null
+
+pack("O", json_object_new_int(1))
+ SUCCESS 1
+
+pack("O?", json_object_new_int(1))
+ SUCCESS 1
+
+pack("O?", NULL)
+ SUCCESS null
+
+pack("{s:[]}", "foo")
+ SUCCESS { "foo": [ ] }
+
+pack("{s+#+: []}", "foo", "barbar", 3, "baz")
+ SUCCESS { "foobarbaz": [ ] }
+
+pack("{s:s,s:o,s:O}", "a", NULL, "b", NULL, "c", NULL)
+ ERROR[char 6 err 10] string is NULL
+
+pack("{s:**}", "a", NULL)
+ ERROR[char 4 err 5] invalid character
+
+pack("{s:s*,s:o*,s:O*}", "a", NULL, "b", NULL, "c", NULL)
+ SUCCESS { }
+
+pack("[i,i,i]", 0, 1, 2)
+ SUCCESS [ 0, 1, 2 ]
+
+pack("[s,o,O]", NULL, NULL, NULL)
+ ERROR[char 4 err 10] string is NULL
+
+pack("[**]", NULL)
+ ERROR[char 2 err 5] invalid character
+
+pack("[s*,o*,O*]", NULL, NULL, NULL)
+ SUCCESS [ ]
+
+pack(" s ", "test")
+ SUCCESS "test"
+
+pack("[ ]")
+ SUCCESS [ ]
+
+pack("[ i , i, i ] ", 1, 2, 3)
+ SUCCESS [ 1, 2, 3 ]
+
+pack("{\n\n1")
+ ERROR[char 4 err 5] invalid character
+
+pack("[}")
+ ERROR[char 2 err 5] invalid character
+
+pack("{]")
+ ERROR[char 2 err 5] invalid character
+
+pack("[")
+ ERROR[char 2 err 2] truncated
+
+pack("{")
+ ERROR[char 2 err 2] truncated
+
+pack("[i]a", 42)
+ ERROR[char 4 err 5] invalid character
+
+pack("ia", 42)
+ ERROR[char 2 err 5] invalid character
+
+pack("s", NULL)
+ ERROR[char 2 err 10] string is NULL
+
+pack("+", NULL)
+ ERROR[char 1 err 5] invalid character
+
+pack(NULL)
+ ERROR[char 1 err 8] spec is NULL
+
+pack("{s:i}", NULL, 1)
+ ERROR[char 4 err 10] string is NULL
+
+pack("{ {}: s }", "foo")
+ ERROR[char 3 err 5] invalid character
+
+pack("{ s: {}, s:[ii{} }", "foo", "bar", 12, 13)
+ ERROR[char 19 err 5] invalid character
+
+pack("[[[[[ [[[[[ [[[[ }]]]] ]]]] ]]]]]")
+ ERROR[char 21 err 5] invalid character
+
+pack("y", "???????hello>>>>>>>", (size_t)19)
+ SUCCESS "Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg"
+
+pack("Y", "???????hello>>>>>>>", (size_t)19)
+ SUCCESS "Pz8\/Pz8\/P2hlbGxvPj4+Pj4+Pg"
+
+pack("{sy?}", "foo", "hi", (size_t)2)
+ SUCCESS { "foo": "aGk" }
+
+pack("{sy?}", "foo", NULL, 0)
+ SUCCESS { "foo": null }
+
+pack("{sy*}", "foo", "hi", (size_t)2)
+ SUCCESS { "foo": "aGk" }
+
+pack("{sy*}", "foo", NULL, 0)
+ SUCCESS { }
+
+unpack("true", "b", &xi[0])
+ SUCCESS b:1
+
+unpack("false", "b", &xi[0])
+ SUCCESS b:0
+
+unpack("null", "n")
+ SUCCESS n
+
+unpack("42", "i", &xi[0])
+ SUCCESS i:42
+
+unpack("123456789", "I", &xI[0])
+ SUCCESS I:123456789
+
+unpack("3.14", "f", &xf[0])
+ SUCCESS f:3.140000
+
+unpack("12345", "F", &xf[0])
+ SUCCESS F:12345.000000
+
+unpack("3.14", "F", &xf[0])
+ SUCCESS F:3.140000
+
+unpack("\"foo\"", "s", &xs[0])
+ SUCCESS s:foo
+
+unpack("\"foo\"", "s%", &xs[0], &xz[0])
+ SUCCESS s:foo %:3
+
+unpack("{}", "{}")
+ SUCCESS
+
+unpack("[]", "[]")
+ SUCCESS
+
+unpack("{}", "o", &xo[0])
+ SUCCESS o:{ }
+
+unpack("{}", "O", &xo[0])
+ SUCCESS O:{ }
+
+unpack("{\"foo\":42}", "{si}", "foo", &xi[0])
+ SUCCESS s:foo i:42
+
+unpack("[1,2,3]", "[i,i,i]", &xi[0], &xi[1], &xi[2])
+ SUCCESS i:1 i:2 i:3
+
+unpack("{\"a\":1,\"b\":2,\"c\":3}", "{s:i, s:i, s:i}", "a", &xi[0], "b", &xi[1], "c", &xi[2])
+ SUCCESS s:a i:1 s:b i:2 s:c i:3
+
+unpack("42", "z")
+ ERROR[char 1 err 5] invalid character
+
+unpack("null", "[i]")
+ ERROR[char 1 err 13] missfit of type
+
+unpack("[]", "[}")
+ ERROR[char 2 err 5] invalid character
+
+unpack("{}", "{]")
+ ERROR[char 2 err 5] invalid character
+
+unpack("[]", "[")
+ ERROR[char 2 err 11] array too small
+
+unpack("{}", "{")
+ ERROR[char 2 err 2] truncated
+
+unpack("[42]", "[i]a", &xi[0])
+ ERROR[char 4 err 5] invalid character
+
+unpack("42", "ia", &xi[0])
+ ERROR[char 2 err 5] invalid character
+
+unpack("[]", NULL)
+ ERROR[char 1 err 8] spec is NULL
+
+unpack("\"foo\"", "s", NULL)
+ SUCCESS s:(null)
+
+unpack("42", "s", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("42", "n")
+ ERROR[char 1 err 13] missfit of type
+
+unpack("42", "b", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("42", "f", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("42", "[i]", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("42", "{si}", "foo", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "n")
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "b", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "i", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "I", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "f", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("\"foo\"", "F", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "s", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "n")
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "i", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "I", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "f", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("true", "F", NULL)
+ ERROR[char 1 err 13] missfit of type
+
+unpack("[42]", "[ii]", &xi[0], &xi[1])
+ ERROR[char 3 err 11] array too small
+
+unpack("{\"foo\":42}", "{si}", NULL, &xi[0])
+ ERROR[char 3 err 9] key is NULL
+
+unpack("{\"foo\":42}", "{si}", "baz", &xi[0])
+ ERROR[char 3 err 14] key not found
+
+unpack("[1,2,3]", "[iii!]", &xi[0], &xi[1], &xi[2])
+ SUCCESS i:1 i:2 i:3
+
+unpack("[1,2,3]", "[ii!]", &xi[0], &xi[1])
+ ERROR[char 5 err 12] incomplete container
+
+unpack("[1,2,3]", "[ii]", &xi[0], &xi[1])
+ SUCCESS i:1 i:2
+
+unpack("[1,2,3]", "[ii*]", &xi[0], &xi[1])
+ SUCCESS i:1 i:2
+
+unpack("{\"foo\":42,\"baz\":45}", "{sisi}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45 s:foo i:42
+
+unpack("{\"foo\":42,\"baz\":45}", "{sisi*}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45 s:foo i:42
+
+unpack("{\"foo\":42,\"baz\":45}", "{sisi!}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45 s:foo i:42
+
+unpack("{\"foo\":42,\"baz\":45}", "{si}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45
+
+unpack("{\"foo\":42,\"baz\":45}", "{si*}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45
+
+unpack("{\"foo\":42,\"baz\":45}", "{si!}", "baz", &xi[0], "foo", &xi[1])
+ ERROR[char 5 err 12] incomplete container
+
+unpack("[1,{\"foo\":2,\"bar\":null},[3,4]]", "[i{sisn}[ii]]", &xi[0], "foo", &xi[1], "bar", &xi[2], &xi[3])
+ SUCCESS i:1 s:foo i:2 s:bar n i:3 i:4
+
+unpack("[1,2,3]", "[ii!i]", &xi[0], &xi[1], &xi[2])
+ ERROR[char 5 err 5] invalid character
+
+unpack("[1,2,3]", "[ii*i]", &xi[0], &xi[1], &xi[2])
+ ERROR[char 5 err 5] invalid character
+
+unpack("{\"foo\":1,\"bar\":2}", "{si!si}", "foo", &xi[1], "bar", &xi[2])
+ ERROR[char 5 err 5] invalid character
+
+unpack("{\"foo\":1,\"bar\":2}", "{si*si}", "foo", &xi[1], "bar", &xi[2])
+ ERROR[char 5 err 5] invalid character
+
+unpack("{\"foo\":{\"baz\":null,\"bar\":null}}", "{s{sn!}}", "foo", "bar")
+ ERROR[char 7 err 12] incomplete container
+
+unpack("[[1,2,3]]", "[[ii!]]", &xi[0], &xi[1])
+ ERROR[char 6 err 12] incomplete container
+
+unpack("{}", "{s?i}", "foo", &xi[0])
+ SUCCESS s:foo i:0
+
+unpack("{\"foo\":1}", "{s?i}", "foo", &xi[0])
+ SUCCESS s:foo i:1
+
+unpack("{}", "{s?[ii]s?{s{si!}}}", "foo", &xi[0], &xi[1], "bar", "baz", "quux", &xi[2])
+ SUCCESS s:foo i:0 i:0 s:bar s:baz s:quux i:0
+
+unpack("{\"foo\":[1,2]}", "{s?[ii]s?{s{si!}}}", "foo", &xi[0], &xi[1], "bar", "baz", "quux", &xi[2])
+ SUCCESS s:foo i:1 i:2 s:bar s:baz s:quux i:0
+
+unpack("{\"bar\":{\"baz\":{\"quux\":15}}}", "{s?[ii]s?{s{si!}}}", "foo", &xi[0], &xi[1], "bar", "baz", "quux", &xi[2])
+ SUCCESS s:foo i:0 i:0 s:bar s:baz s:quux i:15
+
+unpack("{\"foo\":{\"bar\":4}}", "{s?{s?i}}", "foo", "bar", &xi[0])
+ SUCCESS s:foo s:bar i:4
+
+unpack("{\"foo\":{}}", "{s?{s?i}}", "foo", "bar", &xi[0])
+ SUCCESS s:foo s:bar i:0
+
+unpack("{}", "{s?{s?i}}", "foo", "bar", &xi[0])
+ SUCCESS s:foo s:bar i:0
+
+unpack("{\"foo\":42,\"baz\":45}", "{s?isi!}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:45 s:foo i:42
+
+unpack("{\"foo\":42}", "{s?isi!}", "baz", &xi[0], "foo", &xi[1])
+ SUCCESS s:baz i:0 s:foo i:42
+
+unpack("\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"", "y", &xy[0], &xz[0])
+ SUCCESS y/19:???????hello>>>>>>>
+
+unpack("{\"foo\":\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"}", "{s?y}", "foo", &xy[0], &xz[0])
+ SUCCESS s:foo y/19:???????hello>>>>>>>
+
+unpack("{\"foo\":\"\"}", "{s?y}", "foo", &xy[0], &xz[0])
+ SUCCESS s:foo y/0:
+
+unpack("{}", "{s?y}", "foo", &xy[0], &xz[0])
+ SUCCESS s:foo y/0:
+
an>index = 0; return ctx; } /* ------ PUBLIC PLUGIN FUNCTIONS --------- */ static void init (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* create a private client context */ if (!ctx) { ctx = initMediaCtx(); afb_req_context_set (request, ctx, free); } /* initialize server connection */ if (!ctx->media_server) _rygel_init (ctx); jresp = json_object_new_object (); json_object_object_add (jresp, "init", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Initialized"); } static void list (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } jresp = _rygel_list (ctx); if (!jresp) { afb_req_fail (request, "failed", "no content found in media server"); return; } afb_req_success (request, jresp, "Media - Listed"); } static void selecting (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); const char *value = afb_req_value (request, "value"); json_object *jresp; unsigned int index; char index_str[5]; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } /* no "?value=" parameter : return current index */ if (!value) { snprintf (index_str, sizeof(index_str), "%d", ctx->index); jresp = json_object_new_object(); json_object_object_add (jresp, "index", json_object_new_string (index_str)); } /* "?value=" parameter is negative */ else if (atoi(value) < 0) { afb_req_fail (request, "failed", "chosen index cannot be negative"); return; } /* "?value=" parameter is positive */ else if (atoi(value) >= 0) { index = (unsigned int) atoi(value); if (!_rygel_select (ctx, index)) { afb_req_fail (request, "failed", "chosen index superior to current media count"); return; } ctx->index = index; jresp = json_object_new_object(); json_object_object_add (jresp, "index", json_object_new_string (value)); } else jresp = NULL; afb_req_success (request, jresp, "Media - Listed"); } static void play (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } if (!_rygel_do (ctx, PLAY, NULL)) { afb_req_fail (request, "failed", "could not play chosen media"); return; } jresp = json_object_new_object (); json_object_object_add (jresp, "play", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Listed"); } static void stop (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } if (!_rygel_do (ctx, STOP, NULL)) { afb_req_fail (request, "failed", "could not stop chosen media"); return; } jresp = json_object_new_object (); json_object_object_add (jresp, "stop", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Stopped"); } static void pausing (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } if (!_rygel_do (ctx, PAUSE, NULL)) { afb_req_fail (request, "failed", "could not pause chosen media"); return; } jresp = json_object_new_object(); json_object_object_add (jresp, "pause", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Paused"); } static void seek (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); const char *value = afb_req_value (request, "value"); json_object *jresp; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } /* no "?value=" parameter : return error */ if (!value) { afb_req_fail (request, "failed", "you must provide a time"); return; } if (!_rygel_do (ctx, SEEK, (char *)value)) { afb_req_fail (request, "failed", "could not seek chosen media"); return; } jresp = json_object_new_object(); json_object_object_add (jresp, "seek", json_object_new_string ("success")); afb_req_success (request, jresp, "Media - Sought"); } static char *renamed_filename(struct afb_arg argfile) { char *result; const char *e = strrchr(argfile.path, '/'); if (e == NULL) result = strdup(argfile.value); else { result = malloc((++e - argfile.path) + strlen(argfile.value) + 1); if (result != NULL) strcpy(stpncpy(result, argfile.path, e - argfile.path), argfile.value); } return result; } static void on_uploaded(struct afb_req *prequest, int status) { struct afb_req request = afb_req_unstore(prequest); struct afb_arg argfile = afb_req_get(request, "file-upload"); char *file = renamed_filename(argfile); if (file != NULL) unlink(file); free(file); if (status) afb_req_fail (request, "failed", "expected file not received"); else afb_req_success_f (request, NULL, "uploaded file %s", argfile.value); } static void upload (struct afb_req request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = afb_req_context_get(request); struct afb_req *prequest; struct afb_arg argfile; char *path; /* check that context is initialized */ if (ctx == NULL) { afb_req_fail (request, "failed", "uninitialized"); return; } /* get the file */ argfile = afb_req_get(request, "file-upload"); if (!argfile.value || !argfile.path) { afb_req_fail (request, "failed", "expected file not received"); return; } /* rename the file */ path = renamed_filename(argfile); if (path == NULL) { afb_req_fail (request, "failed", "out of memory"); return; } if (rename(argfile.path, path) != 0) { free(path); afb_req_fail (request, "failed", "system error"); return; } /* for asynchronous processing */ prequest = afb_req_store(request); if (path == NULL) { unlink(path); afb_req_fail (request, "failed", "out of memory"); } else if (!_rygel_upload (ctx, path, (void*)on_uploaded, prequest)) { unlink(path); afb_req_fail (afb_req_unstore(prequest), "failed", "Error when uploading file to media server... could not complete"); } free(path); } static void ping (struct afb_req request) { /* AFB_SESSION_NONE */ afb_req_success (request, NULL, "Media - Ping succeeded"); } static const struct AFB_restapi pluginApis[]= { {"init" , AFB_SESSION_CHECK, init , "Media API - init" }, {"list" , AFB_SESSION_CHECK, list , "Media API - list" }, {"select" , AFB_SESSION_CHECK, selecting , "Media API - select" }, {"play" , AFB_SESSION_CHECK, play , "Media API - play" }, {"stop" , AFB_SESSION_CHECK, stop , "Media API - stop" }, {"pause" , AFB_SESSION_CHECK, pausing , "Media API - pause" }, {"seek" , AFB_SESSION_CHECK, seek , "Media API - seek" }, // {"upload" , AFB_SESSION_CHECK, upload , "Media API - upload" }, {"ping" , AFB_SESSION_NONE, ping , "Media API - ping" }, {NULL} }; static const struct AFB_plugin pluginDesc = { .type = AFB_PLUGIN_JSON, .info = "Application Framework Binder - Media plugin", .prefix = "media", .apis = pluginApis }; const struct AFB_plugin *pluginRegister (const struct AFB_interface *itf) { return &pluginDesc; }