[augeas-devel] [PATCH 7/7] Tests for aug_text_store and aug_text_retrieve
lutter at redhat.com
lutter at redhat.com
Thu May 24 21:52:17 UTC 2012
From: David Lutterkort <lutter at redhat.com>
---
tests/run.tests | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
tests/test-api.c | 73 +++++++++++++++++++++++++++++++++++------
2 files changed, 156 insertions(+), 12 deletions(-)
diff --git a/tests/run.tests b/tests/run.tests
index bccb802..4bb8682 100644
--- a/tests/run.tests
+++ b/tests/run.tests
@@ -33,7 +33,8 @@
# OUT stream.
#
# The test is run against a tree initialized with AUG_NO_STDINC|AUG_NO_LOAD
-# and file system root /dev/null
+# and file system root /dev/null. The Hosts module is loaded
+
#
# Various corner cases
@@ -614,3 +615,95 @@ test quot_mix_sq -1 ECMDRUN
test quot_mix_dq -1 ECMDRUN
set /test "a"b'c"d'e"
+
+#
+# Tests for aug_text_store
+#
+test store_hosts 3
+ use Hosts
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ store Hosts.lns /text/in/t1 /text/tree/t1
+ print /text/tree/t1
+prints
+ /text/tree/t1
+ /text/tree/t1/1
+ /text/tree/t1/1/ipaddr = "192.168.0.1"
+ /text/tree/t1/1/canonical = "rtr.example.com"
+ /text/tree/t1/1/alias = "foo"
+
+test store_nolens -1 ENOLENS
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ store Nomodule.lns /text/in/t1 /text/tree/t1
+
+test store_epathx_node -1 EPATHX
+ use Hosts
+ store Hosts.lns [garbage] /text/tree/t1
+
+test store_epathx_path -1 EPATHX
+ use Hosts
+ store Hosts.lns /text/in/t1 [garbage]
+
+test store_null_text -1 ENOMATCH
+ use Hosts
+ store Hosts.lns /text/in/t1 /text/tree/t1
+
+test store_esyntax 3
+ use Hosts
+ set /text/in/t1 "not a hosts file entry"
+ store Hosts.lns /text/in/t1 /text/tree/t1
+ match /augeas/text/text/tree/t1/error
+prints
+ /augeas/text/text/tree/t1/error = parse_failed
+
+#
+# Tests for aug_text_retrieve
+#
+test retrieve_hosts 5
+ use Hosts
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ store Hosts.lns /text/in/t1 /text/tree/t1
+ set /text/tree/t1/1/alias[1] bar
+ retrieve Hosts.lns /text/in/t1 /text/tree/t1 /text/out/t1
+ print /text/out/t1
+prints
+ /text/out/t1 = "192.168.0.1 rtr.example.com bar\n"
+
+test retrieve_nolens -1 ENOLENS
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ store Hosts.lns /text/in/t1 /text/tree/t1
+ retrieve Nomodule.lns /text/in/t1 /text/tree/t1 /text/out/t1
+
+test retrieve_epathx_node_in -1 EPATHX
+ use Hosts
+ retrieve Hosts.lns [garbage] /text/tree/t1 /text/out/t1
+
+test retrieve_epathx_path -1 EPATHX
+ use Hosts
+ retrieve Hosts.lns /text/in/t1 [garbage] /text/out/t1
+
+test retrieve_epathx_node_out -1 EPATHX
+ use Hosts
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ retrieve Hosts.lns /text/in/t1 /text/tree/t1 [garbage]
+
+test retrieve_no_node_in -1 ENOMATCH
+ use Hosts
+ retrieve Hosts.lns /text/in/t1 /text/tree/t1 /text/out/t1
+
+test retrieve_no_tree 3
+ use Hosts
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ retrieve Hosts.lns /text/in/t1 /text/tree/t1 /text/out/t1
+ print /text/out/t1
+prints
+ /text/out/t1 = ""
+
+test retrieve_esyntax 5
+ use Hosts
+ set /text/in/t1 "192.168.0.1 rtr.example.com foo\n"
+ store Hosts.lns /text/in/t1 /text/tree/t1
+ set /text/in/t1 "not a hosts file entry"
+ retrieve Hosts.lns /text/in/t1 /text/tree/t1 /text/out/t1
+ match /augeas//error
+prints
+ /augeas/text/text/tree/t1/error = parse_skel_failed
diff --git a/tests/test-api.c b/tests/test-api.c
index a032ac0..5726540 100644
--- a/tests/test-api.c
+++ b/tests/test-api.c
@@ -457,8 +457,9 @@ static void testToXml(CuTest *tc) {
static void testTextStore(CuTest *tc) {
static const char *const hosts = "192.168.0.1 rtr.example.com router\n";
- /* Not acceptable for Hosts.lns - missing \n */
+ /* Not acceptable for Hosts.lns - missing canonical and \n */
static const char *const hosts_bad = "192.168.0.1";
+ const char *v;
struct augeas *aug;
int r;
@@ -466,25 +467,74 @@ static void testTextStore(CuTest *tc) {
aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
CuAssertPtrNotNull(tc, aug);
- r = aug_text_store(aug, "Hosts.lns", "/text/t1", hosts, strlen(hosts));
+ r = aug_set(aug, "/raw/hosts", hosts);
CuAssertRetSuccess(tc, r);
- r = aug_match(aug, "/text/t1/*", NULL);
+ r = aug_text_store(aug, "Hosts.lns", "/raw/hosts", "/t1");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_match(aug, "/t1/*", NULL);
CuAssertIntEquals(tc, 1, r);
- // FIXME: Test bad lens name
- // FIXME: Test parse error
- r = aug_text_store(aug, "Hosts.lns", "text/t3", hosts_bad,
- strlen(hosts_bad));
+ /* Test bad lens name */
+ r = aug_text_store(aug, "Notthere.lns", "/raw/hosts", "/t2");
CuAssertIntEquals(tc, -1, r);
- r = aug_match(aug, "/text/t3", NULL);
+ CuAssertIntEquals(tc, AUG_ENOLENS, aug_error(aug));
+
+ r = aug_match(aug, "/t2", NULL);
+ CuAssertIntEquals(tc, 0, r);
+
+ /* Test parse error */
+ r = aug_set(aug, "/raw/hosts_bad", hosts_bad);
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_text_store(aug, "Hosts.lns", "/raw/hosts_bad", "/t3");
+ CuAssertIntEquals(tc, -1, r);
+
+ r = aug_match(aug, "/t3", NULL);
+ CuAssertIntEquals(tc, 0, r);
+
+ r = aug_get(aug, "/augeas/text/t3/error", &v);
CuAssertIntEquals(tc, 1, r);
+ CuAssertStrEquals(tc, "parse_failed", v);
+
+ r = aug_text_store(aug, "Hosts.lns", "/raw/hosts", "/t3");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_match(aug, "/augeas/text/t3/error", NULL);
+ CuAssertIntEquals(tc, 0, r);
+
+ /* Test invalid PATH */
+ r = aug_text_store(aug, "Hosts.lns", "/raw/hosts", "[garbage]");
+ CuAssertIntEquals(tc, -1, r);
+ CuAssertIntEquals(tc, AUG_EPATHX, aug_error(aug));
+
+ r = aug_match(aug, "/t2", NULL);
+ CuAssertIntEquals(tc, 0, r);
+}
+
+static void testTextRetrieve(CuTest *tc) {
+ static const char *const hosts = "192.168.0.1 rtr.example.com router\n";
+ const char *hosts_out;
+ struct augeas *aug;
+ int r;
+
+ aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
+ CuAssertPtrNotNull(tc, aug);
+
+ r = aug_set(aug, "/raw/hosts", hosts);
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_text_store(aug, "Hosts.lns", "/raw/hosts", "/t1");
+ CuAssertRetSuccess(tc, r);
+
+ r = aug_text_retrieve(aug, "Hosts.lns", "/raw/hosts", "/t1", "/out/hosts");
+ CuAssertRetSuccess(tc, r);
- aug_print(aug, stdout, "/augeas//error");
- r = aug_match(aug, "/augeas/text/text/t3/error", NULL);
+ r = aug_get(aug, "/out/hosts", &hosts_out);
CuAssertIntEquals(tc, 1, r);
- // FIXME: Test invalid PATH
+ CuAssertStrEquals(tc, hosts, hosts_out);
}
int main(void) {
@@ -502,6 +552,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