[augeas-devel] [PATCH 10/10] Tests for aug_text_retrieve

lutter at redhat.com lutter at redhat.com
Tue May 22 00:44:37 UTC 2012


From: David Lutterkort <lutter at redhat.com>

---
 tests/run.tests  |   35 +++++++++++++++++++++++++++++++++++
 tests/test-api.c |   21 +++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/tests/run.tests b/tests/run.tests
index 5e91917..5d68dd9 100644
--- a/tests/run.tests
+++ b/tests/run.tests
@@ -643,3 +643,38 @@ test store_esyntax 2
   match /augeas/text/text/t1/error
 prints
   /augeas/text/text/t1/error = parse_failed
+
+#
+# Tests for aug_text_retrieve
+#
+test retrieve_hosts 3
+ use Hosts
+  store Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+  set /text/t1/1/alias[1] bar
+  retrieve Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+prints
+192.168.0.1 rtr.example.com bar
+  :
+
+test retrieve_nolens -1 ENOLENS
+  store Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+  retrieve Nomodule.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+
+test retrieve_epathx -1 EPATHX
+ use Hosts
+  store Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+  retrieve Hosts.lns [garbage] "192.168.0.1 rtr.example.com foo\n"
+
+test retrieve_nonode 1
+ use Hosts
+  retrieve Hosts.lns /not/there ""
+prints
+  :
+
+test retrieve_esyntax 3
+ use Hosts
+  store Hosts.lns /text/t1 "192.168.0.1 rtr.example.com foo\n"
+  retrieve Hosts.lns /text/t1 "not a hosts file entry"
+  match /augeas/text/text/t1/error
+prints
+  /augeas/text/text/t1/error = parse_skel_failed
diff --git a/tests/test-api.c b/tests/test-api.c
index 7df7f11..8f86a9f 100644
--- a/tests/test-api.c
+++ b/tests/test-api.c
@@ -508,6 +508,26 @@ static void testTextStore(CuTest *tc) {
     CuAssertIntEquals(tc, 0, r);
 }
 
+static void testTextRetrieve(CuTest *tc) {
+    static const char *const hosts = "192.168.0.1 rtr.example.com router\n";
+    char *hosts_out;
+    unsigned int hosts_out_len;
+
+    struct augeas *aug;
+    int r;
+
+    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
+    CuAssertPtrNotNull(tc, aug);
+
+    r = aug_text_store(aug, "Hosts.lns", "/t1", hosts, strlen(hosts));
+    CuAssertRetSuccess(tc, r);
+
+    r = aug_text_retrieve(aug, "Hosts.lns", "/t1", hosts, strlen(hosts),
+                          &hosts_out, &hosts_out_len);
+    CuAssertRetSuccess(tc, r);
+    CuAssertStrEquals(tc, hosts, hosts_out);
+}
+
 int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
@@ -523,6 +543,7 @@ int main(void) {
     SUITE_ADD_TEST(suite, testMv);
     SUITE_ADD_TEST(suite, testToXml);
     SUITE_ADD_TEST(suite, testTextStore);
+    SUITE_ADD_TEST(suite, testTextRetrieve);
 
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (abs_top_srcdir == NULL)
-- 
1.7.7.6




More information about the augeas-devel mailing list