X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftest_sparql.c;h=963667fd89ff27907688d77225a73d599e3093bd;hb=c835a3a7536f6c1b7314272c5cd5293004155ca3;hp=3590f9b8499af528d052e555fef70b18e5c11803;hpb=90d0517a535806d6b076f7c9812f8292a037cd06;p=mp-sparql-moved-to-github.git diff --git a/src/test_sparql.c b/src/test_sparql.c index 3590f9b..963667f 100644 --- a/src/test_sparql.c +++ b/src/test_sparql.c @@ -63,6 +63,51 @@ static int test_query(yaz_sparql_t s, const char *pqf, const char *expect) return ret; } +static int test_uri(yaz_sparql_t s, const char *uri, const char *schema, + const char *expect) +{ + int ret = 0; + WRBUF addinfo = wrbuf_alloc(); + WRBUF w = wrbuf_alloc(); + + int r = yaz_sparql_from_uri_wrbuf(s, addinfo, w, uri, schema); + if (expect) + { + if (!r) + { + if (!strcmp(expect, wrbuf_cstr(w))) + ret = 1; + else + { + yaz_log(YLOG_WARN, "test_sparql: uri=%s", uri); + yaz_log(YLOG_WARN, " expect: %s", expect); + yaz_log(YLOG_WARN, " got: %s", wrbuf_cstr(w)); + } + } + else + { + yaz_log(YLOG_WARN, "test_sparql: uri=%s", uri); + yaz_log(YLOG_WARN, " expect: %s", expect); + yaz_log(YLOG_WARN, " got error: %d:%s", r, wrbuf_cstr(addinfo)); + } + } + else + { + if (r) + ret = 1; + else + { + yaz_log(YLOG_WARN, "test_sparql: uri=%s", uri); + yaz_log(YLOG_WARN, " expect error"); + yaz_log(YLOG_WARN, " got: %s", wrbuf_cstr(w)); + } + } + wrbuf_destroy(w); + wrbuf_destroy(addinfo); + return ret; +} + + static void tst1(void) { yaz_sparql_t s = yaz_sparql_create(); @@ -73,10 +118,7 @@ static void tst1(void) "bf: "); yaz_sparql_add_pattern(s, "prefix", "gs: http://gs.com/panorama/domain-model"); - yaz_sparql_add_pattern(s, "field.title", "?title"); - yaz_sparql_add_pattern(s, "field.author", "?author"); - yaz_sparql_add_pattern(s, "field.description", "?description"); - yaz_sparql_add_pattern(s, "field.instanceTitle", "?ititle"); + yaz_sparql_add_pattern(s, "form", "SELECT ?title ?author ?description ?ititle"); yaz_sparql_add_pattern(s, "criteria", "?work a bf:Work"); yaz_sparql_add_pattern(s, "criteria", "?work bf:workTitle/bf:titleValue ?title"); yaz_sparql_add_pattern(s, "criteria", "?work bf:creator/bf:label ?author"); @@ -107,12 +149,28 @@ static void tst1(void) yaz_sparql_add_pattern(s, "index.bf.targetAudience", "?work bf:targetAudience %s"); yaz_sparql_add_pattern(s, "index.bf.isbn", "?inst bf:ISBN %s"); + + yaz_sparql_add_pattern(s, "uri.full", "SELECT ?sub ?rel WHERE ?work = %u"); + yaz_sparql_add_pattern(s, "present.brief", "SELECT %u"); + + YAZ_CHECK(test_uri(s, "http://x/y", "full", + "PREFIX rdf: \n" + "PREFIX bf: \n" + "PREFIX gs: \n" + "SELECT ?sub ?rel WHERE ?work = \n")); + + + YAZ_CHECK(test_uri(s, "http://x/z", "brief", + "PREFIX rdf: \n" + "PREFIX bf: \n" + "PREFIX gs: \n" + "SELECT \n")); + YAZ_CHECK(test_query( s, "@attr 1=bf.title computer", "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -132,7 +190,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -152,7 +209,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -173,7 +229,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -198,7 +253,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -228,7 +282,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -255,7 +308,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -280,7 +332,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -301,7 +352,6 @@ static void tst1(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -322,6 +372,7 @@ static void tst1(void) static void tst2(void) { yaz_sparql_t s = yaz_sparql_create(); + yaz_sparql_t s2 = yaz_sparql_create(); yaz_sparql_add_pattern(s, "prefix", "rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns"); @@ -329,10 +380,7 @@ static void tst2(void) "bf: "); yaz_sparql_add_pattern(s, "prefix", "gs: http://gs.com/panorama/domain-model"); - yaz_sparql_add_pattern(s, "field.title", "?title"); - yaz_sparql_add_pattern(s, "field.author", "?author"); - yaz_sparql_add_pattern(s, "field.description", "?description"); - yaz_sparql_add_pattern(s, "field.instanceTitle", "?ititle"); + yaz_sparql_add_pattern(s, "form", "SELECT ?title ?author ?description ?ititle"); yaz_sparql_add_pattern(s, "criteria", "?work a bf:Work"); yaz_sparql_add_pattern(s, "criteria", "?work bf:workTitle/bf:titleValue ?title"); yaz_sparql_add_pattern(s, "criteria", "?work bf:creator/bf:label ?author"); @@ -368,7 +416,6 @@ static void tst2(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -388,7 +435,6 @@ static void tst2(void) "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -400,14 +446,17 @@ static void tst2(void) " OPTIONAL { ?inst bf:heldBy ?lib } .\n" " ?work bf:creator/bf:label ?v0 " "FILTER(contains(?v0, \"london\"))\n" + + "}\n")); + yaz_sparql_include(s2, s); + YAZ_CHECK(test_query( - s, "@or @and @attr 1=bf.creator a @attr 1=bf.title b @attr 1=bf.title c", + s2, "@or @and @attr 1=bf.creator a @attr 1=bf.title b @attr 1=bf.title c", "PREFIX rdf: \n" "PREFIX bf: \n" "PREFIX gs: \n" - "\n" "SELECT ?title ?author ?description ?ititle\n" "WHERE {\n" " ?work a bf:Work .\n" @@ -429,6 +478,7 @@ static void tst2(void) "}\n" )); + yaz_sparql_destroy(s2); yaz_sparql_destroy(s); }