Blob Blame History Raw
From 8686eeeea05de0c5a3aeccfa7560b7668635b99e Mon Sep 17 00:00:00 2001
From: David Lutterkort <lutter@watzmann.net>
Date: Mon, 11 Jun 2018 12:20:31 -0700
Subject: [PATCH] * tests/test-api.c: add a check for aug_source

(cherry picked from commit 74e2f6c74e2e910034339dcda2d46c9aa3f83776)
---
 src/augeas.h     |  2 ++
 tests/test-api.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/src/augeas.h b/src/augeas.h
index d6a1a707..a8770790 100644
--- a/src/augeas.h
+++ b/src/augeas.h
@@ -403,6 +403,8 @@ int aug_print(const augeas *aug, FILE *out, const char *path);
  * contain the path to the toplevel node of that file underneath /files. If
  * it does not, *FILE_PATH will be NULL.
  *
+ * The caller is responsible for freeing *FILE_PATH
+ *
  * Returns:
  * 0 on success, or a negative value on failure. It is an error if PATH
  * matches more than one node.
diff --git a/tests/test-api.c b/tests/test-api.c
index fda8ab6a..6460d7ba 100644
--- a/tests/test-api.c
+++ b/tests/test-api.c
@@ -816,6 +816,41 @@ static void testAugNs(CuTest *tc) {
     aug_close(aug);
 }
 
+/* Test aug_source */
+static void testAugSource(CuTest *tc) {
+    struct augeas *aug;
+    int r;
+    char *s;
+
+    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
+    CuAssertPtrNotNull(tc, aug);
+    CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug));
+
+    r = aug_load_file(aug, "/etc/hosts");
+    CuAssertIntEquals(tc, 0, r);
+
+    r = aug_source(aug, "/files/etc/hosts/1", &s);
+    CuAssertIntEquals(tc, 0, r);
+    CuAssertStrEquals(tc, "/files/etc/hosts", s);
+    free(s);
+
+    r = aug_source(aug, "/files/etc/fstab", &s);
+    CuAssertIntEquals(tc, -1, r);
+    CuAssertIntEquals(tc, AUG_ENOMATCH, aug_error(aug));
+    CuAssertPtrEquals(tc, NULL, s);
+
+    r = aug_source(aug, "/files[", &s);
+    CuAssertIntEquals(tc, -1, r);
+    CuAssertIntEquals(tc, AUG_EPATHX, aug_error(aug));
+    CuAssertPtrEquals(tc, NULL, s);
+
+    r = aug_source(aug, "/files/etc/hosts/*", &s);
+    CuAssertIntEquals(tc, -1, r);
+    CuAssertIntEquals(tc, AUG_EMMATCH, aug_error(aug));
+    CuAssertPtrEquals(tc, NULL, s);
+
+}
+
 int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
@@ -840,6 +875,7 @@ int main(void) {
     SUITE_ADD_TEST(suite, testLoadBadPath);
     SUITE_ADD_TEST(suite, testLoadBadLens);
     SUITE_ADD_TEST(suite, testAugNs);
+    SUITE_ADD_TEST(suite, testAugSource);
 
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (abs_top_srcdir == NULL)
-- 
2.17.2