/*
* test-xpath.c: check that XPath expressions yield the expected result
*
- * Copyright (C) 2007-2015 David Lutterkort
+ * Copyright (C) 2007-2016 David Lutterkort
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return s;
}
+static void free_tests(struct test *test) {
+ while (test != NULL) {
+ struct test *del = test;
+ test = test->next;
+ struct entry *entry = del->entries;
+ while (entry != NULL) {
+ struct entry *e = entry;
+ entry = entry->next;
+ free(e->path);
+ free(e->value);
+ free(e);
+ }
+ free(del->name);
+ free(del->match);
+ free(del);
+ }
+}
+
static struct test *read_tests(void) {
char *fname;
FILE *fp;
die("xpath.tests has incorrect format");
}
}
+ fclose(fp);
+ free(fname);
return result;
}
print_pv(matches[i], val);
}
}
+ for (int i=0; i < nact; i++) {
+ free(matches[i]);
+ }
+ free(matches);
return result;
}
return -1;
}
+static int test_trailing_ws_in_name(struct augeas *aug) {
+ int r;
+
+ printf("%-30s ... ", "trailing_ws_in_name");
+
+ /* We used to incorrectly lop escaped whitespace off the end of a
+ * name. Make sure that we really create a tree node with label 'x '
+ * with the below set, and look for it in a number of ways to ensure we
+ * are not lopping off trailing whitespace. */
+ r = aug_set(aug, "/ws\\ ", "1");
+ if (r < 0) {
+ fprintf(stderr, "failed to set '/ws ': %d\n", r);
+ goto fail;
+ }
+ /* We did not create a node with label 'ws' */
+ r = aug_get(aug, "/ws", NULL);
+ if (r != 0) {
+ fprintf(stderr, "created '/ws' instead: %d\n", r);
+ goto fail;
+ }
+
+ /* We did not create a node with label 'ws\t' (this also checks that we
+ * don't create something like 'ws\\' by dropping the last whitespace
+ * character. */
+ r = aug_get(aug, "/ws\\\t", NULL);
+ if (r != 0) {
+ fprintf(stderr, "found '/ws\\t': %d\n", r);
+ goto fail;
+ }
+
+ /* But we did create 'ws ' */
+ r = aug_get(aug, "/ws\\ ", NULL);
+ if (r != 1) {
+ fprintf(stderr, "could not find '/ws ': %d\n", r);
+ goto fail;
+ }
+
+ /* If the whitespace is preceded by an even number of '\\' chars,
+ * whitespace must be stripped */
+ r = aug_set(aug, "/nows\\\\ ", "1");
+ if (r < 0) {
+ fprintf(stderr, "set of '/nows' failed: %d\n", r);
+ goto fail;
+ }
+ r = aug_get(aug, "/nows\\\\", NULL);
+ if (r != 1) {
+ fprintf(stderr, "could not get '/nows\\'\n");
+ goto fail;
+ }
+ printf("PASS\n");
+ return 0;
+ fail:
+ printf("FAIL\n");
+ return -1;
+}
+
static int run_tests(struct test *tests, int argc, char **argv) {
char *lensdir;
struct augeas *aug = NULL;
if (test_wrong_regexp_flag(aug) < 0)
result = EXIT_FAILURE;
+
+ if (test_trailing_ws_in_name(aug) < 0)
+ result = EXIT_FAILURE;
}
aug_close(aug);
+ free(lensdir);
return result;
}
}
tests = read_tests();
- return run_tests(tests, argc - 1, argv + 1);
+ int result = run_tests(tests, argc - 1, argv + 1);
/*
list_for_each(t, tests) {
printf("Test %s\n", t->name);
}
}
*/
+ free_tests(tests);
+ return result;
}
/*