libsmbconf: create text config in smbconftort
authorMichael Adam <obnox@samba.org>
Thu, 23 Oct 2008 22:00:20 +0000 (00:00 +0200)
committerMichael Adam <obnox@samba.org>
Thu, 19 Mar 2009 17:03:53 +0000 (18:03 +0100)
Michael

source/lib/smbconf/testsuite.c

index cffd239df6af0fbac17817add9ea0f08dde56427..100fbe8440deb8f030eed4cca8740e8b6fa6b07e 100644 (file)
@@ -173,17 +173,46 @@ done:
        return ret;
 }
 
+static bool create_conf_file(const char *filename)
+{
+       FILE *f;
+
+       printf("creating file\n");
+       f = sys_fopen(filename, "w");
+       if (!f) {
+               printf("failure: failed to open %s for writing: %s\n",
+                      filename, strerror(errno));
+               return false;
+       }
+
+       fprintf(f, "[global]\n");
+       fprintf(f, "\tserver string = smbconf testsuite\n");
+       fprintf(f, "\tworkgroup = SAMBA\n");
+       fprintf(f, "\tsecurity = user\n");
+
+       fclose(f);
+
+       printf("success: create file\n");
+       return true;
+}
+
 static bool torture_smbconf_txt(void)
 {
        WERROR werr;
        bool ret = true;
+       const char *filename = "/tmp/smb.conf.smbconf_testsuite";
        struct smbconf_ctx *conf_ctx = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
 
        printf("test: text backend\n");
 
+       if (!create_conf_file(filename)) {
+               ret = false;
+               goto done;
+       }
+
        printf("test: init\n");
-       werr = smbconf_init_txt(mem_ctx, &conf_ctx, NULL);
+       werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
        if (!W_ERROR_IS_OK(werr)) {
                printf("failure: init failed: %s\n", dos_errstr(werr));
                ret = false;
@@ -195,6 +224,14 @@ static bool torture_smbconf_txt(void)
 
        smbconf_shutdown(conf_ctx);
 
+       printf("unlinking file\n");
+       if (unlink(filename) != 0) {
+               printf("failure: unlink failed: %s\n", strerror(errno));
+               ret = false;
+               goto done;
+       }
+       printf("success: unlink file\n");
+
        printf("%s: text backend\n", ret ? "success" : "failure");
 
 done: