]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
autzone query unit test
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 23 May 2017 11:50:06 +0000 (11:50 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 23 May 2017 11:50:06 +0000 (11:50 +0000)
git-svn-id: file:///svn/unbound/trunk@4184 be551aaa-1e26-0410-a405-d3ace91eadb9

testcode/unitauth.c

index 378c98ee70e794471e4374b1c29876f5ec362acd..5d154576daf1352187925d35a5e611694c2f7e30 100644 (file)
@@ -385,6 +385,49 @@ msgtostr(struct dns_msg* msg)
        return str;
 }
 
+/** find line diff between strings */
+static void
+line_diff(const char* p, const char* q, const char* pdesc, const char* qdesc)
+{
+       char* pdup, *qdup, *pl, *ql;
+       int line = 1;
+       pdup = strdup(p);
+       qdup = strdup(q);
+       if(!pdup || !qdup) fatal_exit("out of memory");
+       pl=pdup;
+       ql=qdup;
+       printf("linediff (<%s, >%s)\n", pdesc, qdesc);
+       while(pl && ql && *pl && *ql) {
+               char* ep = strchr(pl, '\n');
+               char* eq = strchr(ql, '\n');
+               /* terminate lines */
+               if(ep) *ep = 0;
+               if(eq) *eq = 0;
+               /* printout */
+               if(strcmp(pl, ql) == 0) {
+                       printf("%3d   %s\n", line, pl);
+               } else {
+                       printf("%3d < %s\n", line, pl);
+                       printf("%3d > %s\n", line, ql);
+               }
+               if(ep) *ep = '\n';
+               if(eq) *eq = '\n';
+               if(ep) pl = ep+1;
+               else pl = NULL;
+               if(eq) ql = eq+1;
+               else ql = NULL;
+               line++;
+       }
+       if(pl && *pl) {
+               printf("%3d < %s\n", line, pl);
+       }
+       if(ql && *ql) {
+               printf("%3d > %s\n", line, ql);
+       }
+       free(pdup);
+       free(qdup);
+}
+
 /** make q_ans query */
 static void
 q_ans_query(struct q_ans* q, struct auth_zones* az, struct query_info* qinfo,
@@ -407,10 +450,29 @@ q_ans_query(struct q_ans* q, struct auth_zones* az, struct query_info* qinfo,
        if(vbmp) printf("got (ret=%s%s):\n%s",
                (ret?"ok":"fail"), (fallback?" fallback":""), ans_str);
        /* check expected value for ret */
+       if(ret == 0) {
+               /* ret is zero on fallback */
+               if(!expected_fallback) {
+                       if(vbmp) printf("fallback expected, but "
+                               "ret is not false\n");
+               }
+               unit_assert(expected_fallback);
+       }
        /* check expected value for fallback */
-       (void)expected_fallback;
+       if(expected_fallback && !fallback) {
+               if(vbmp) printf("expected fallback, but fallback is no\n");
+       } else if(!expected_fallback && fallback) {
+               if(vbmp) printf("expected no fallback, but fallback is yes\n");
+       }
+       unit_assert( (expected_fallback&&fallback) ||
+               (!expected_fallback&&!fallback));
        /* check answer string */
-       (void)q;
+       if(strcmp(q->answer, ans_str) != 0) {
+               if(vbmp) printf("wanted:\n%s", q->answer);
+               line_diff(q->answer, ans_str, "wanted", "got");
+       }
+       unit_assert(strcmp(q->answer, ans_str) == 0);
+       if(vbmp) printf("query ok\n\n");
        free(ans_str);
 }