2 Unix SMB/CIFS implementation.
6 Copyright (C) Jelmer Vernooij 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "system/filesys.h"
24 #include "torture/torture.h"
26 #define TEST_FILENAME "utilfile.test"
27 #define TEST_LINE1 "This is list line 1..."
28 #define TEST_LINE2 ".. and this is line 2"
29 #define TEST_LINE3 "and end of the file"
31 #define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3
33 static bool test_file_load_save(struct torture_context *tctx)
37 TALLOC_CTX *mem_ctx = tctx;
39 torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
42 data = file_load(TEST_FILENAME, &len, mem_ctx);
43 torture_assert(tctx, data, "loading file");
45 torture_assert(tctx, len == strlen(TEST_DATA), "Length");
47 torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents");
49 unlink(TEST_FILENAME);
54 static bool test_afdgets(struct torture_context *tctx)
58 TALLOC_CTX *mem_ctx = tctx;
60 torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA,
64 fd = open(TEST_FILENAME, O_RDONLY);
66 torture_assert(tctx, fd != -1, "opening file");
68 line = afdgets(fd, mem_ctx, 8);
69 torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch");
71 line = afdgets(fd, mem_ctx, 8);
72 torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch");
74 line = afdgets(fd, mem_ctx, 8);
75 torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch");
79 unlink(TEST_FILENAME);
83 struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
85 struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE");
87 torture_suite_add_simple_test(suite, "file_load_save",
90 torture_suite_add_simple_test(suite, "afdgets",