Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-save.c
index faa24e6..ffafa4f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test-save.c: test various aspects of saving
  *
- * Copyright (C) 2009-2015 David Lutterkort
+ * Copyright (C) 2009-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
@@ -61,6 +61,7 @@ static void setup(CuTest *tc) {
     run(tc, "chmod -R u+w %s", root);
 
     aug = aug_init(root, lensdir, AUG_NO_STDINC);
+    free(lensdir);
     CuAssertPtrNotNull(tc, aug);
 }
 
@@ -146,9 +147,21 @@ static void testMultipleXfm(CuTest *tc) {
 
     r = aug_set(aug, "/files/etc/yum.repos.d/fedora.repo/fedora/enabled", "0");
     CuAssertIntEquals(tc, 0, r);
+    /* What we have set up is fine: two ways to save the same file with the
+       same lens */
+    r = aug_save(aug);
+    CuAssertIntEquals(tc, 0, r);
+
+    /* Now we make it bad: a different lens for the same file */
+    r = aug_set(aug, "/augeas/load/Yum2/lens", "@Subversion");
+    CuAssertIntEquals(tc, 0, r);
+
+    r = aug_set(aug, "/files/etc/yum.repos.d/fedora.repo/fedora/enabled", "1");
+    CuAssertIntEquals(tc, 0, r);
 
     r = aug_save(aug);
     CuAssertIntEquals(tc, -1, r);
+
     r = aug_error(aug);
     CuAssertIntEquals(tc, AUG_EMXFM, r);
 }
@@ -175,6 +188,7 @@ static void testMtime(CuTest *tc) {
 
     CuAssertStrNotEqual(tc, mtime1, mtime2);
     CuAssertStrNotEqual(tc, "0", mtime2);
+    free(mtime1);
 }
 
 /* Check that loading and saving a file given with a relative path
@@ -285,6 +299,7 @@ static void testUmask(CuTest *tc, int tumask, mode_t expected_mode) {
 
     CuAssertIntEquals(tc, 0, stat(fpath, &buf));
     CuAssertIntEquals(tc, expected_mode, buf.st_mode & 0777);
+    free(fpath);
 }
 static void testUmask077(CuTest *tc) {
     testUmask(tc, 0077, 0600);
@@ -346,6 +361,9 @@ static void testPathEscaping(CuTest *tc) {
     r = access(fname, R_OK);
     CuAssertIntEquals(tc, -1, r);
     CuAssertIntEquals(tc, ENOENT, errno);
+
+    free(s);
+    free(fname);
 }
 
 /* Test that we handle failure to save a file because we lack permission on
@@ -379,6 +397,7 @@ static void testSaveNoPermission(CuTest *tc) {
     r = aug_get(aug, "/augeas/files/etc/hosts/error", &v);
     CuAssertIntEquals(tc, 1, r);
     CuAssertStrEquals(tc, "replace_from_missing", v);
+    free(path);
 }
 
 int main(void) {
@@ -417,7 +436,9 @@ int main(void) {
     CuSuiteDetails(suite, &output);
     printf("%s\n", output);
     free(output);
-    return suite->failCount;
+    int result = suite->failCount;
+    CuSuiteFree(suite);
+    return result;
 }
 
 /*