From 1afda7bdde90948027e3230c19753280afb16e96 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 2 Mar 2007 14:53:09 +0000 Subject: r21656: Move tests a bit closer to the things they test, should make syncing with samba3 easier. (This used to be commit 4d755fb5d7adedd1dd8bad917b921324411bfd59) --- source4/lib/util/tests/file.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 source4/lib/util/tests/file.c (limited to 'source4/lib/util/tests/file.c') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c new file mode 100644 index 0000000000..87d25b222e --- /dev/null +++ b/source4/lib/util/tests/file.c @@ -0,0 +1,95 @@ +/* + Unix SMB/CIFS implementation. + + util_file testing + + Copyright (C) Jelmer Vernooij 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/filesys.h" +#include "torture/torture.h" + +#define TEST_FILENAME "utilfile.test" +#define TEST_LINE1 "This is list line 1..." +#define TEST_LINE2 ".. and this is line 2" +#define TEST_LINE3 "and end of the file" + +#define TEST_DATA TEST_LINE1 "\n" TEST_LINE2 "\n" TEST_LINE3 + +static bool test_file_load_save(struct torture_context *tctx) +{ + size_t len; + char *data; + TALLOC_CTX *mem_ctx = tctx; + + torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)), + "saving file"); + + data = file_load(TEST_FILENAME, &len, mem_ctx); + torture_assert(tctx, data, "loading file"); + + torture_assert(tctx, len == strlen(TEST_DATA), "Length"); + + torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents"); + + unlink(TEST_FILENAME); + return true; +} + + +static bool test_afdgets(struct torture_context *tctx) +{ + int fd; + char *line; + TALLOC_CTX *mem_ctx = tctx; + + torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA, + strlen(TEST_DATA)), + "saving file"); + + fd = open(TEST_FILENAME, O_RDONLY); + + torture_assert(tctx, fd != -1, "opening file"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch"); + + line = afdgets(fd, mem_ctx, 8); + torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch"); + + close(fd); + + unlink(TEST_FILENAME); + return true; +} + +struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE"); + + torture_suite_add_simple_test(suite, "file_load_save", + test_file_load_save); + + torture_suite_add_simple_test(suite, "afdgets", + test_afdgets); + + return suite; +} -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/tests/file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/tests/file.c') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 87d25b222e..66a3b81dca 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From a43b026ef0e9c1ffd24130c35275f02326bfc9c7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 11 Aug 2007 17:08:22 +0000 Subject: r24333: Add convenience function for checking the contents of a file in tests. (This used to be commit 4e304101241ea7bcb9111b757bb51b16665d492d) --- source4/lib/util/tests/file.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/util/tests/file.c') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 66a3b81dca..0fe117a300 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -39,6 +39,9 @@ static bool test_file_load_save(struct torture_context *tctx) torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)), "saving file"); + torture_assert_file_contains_text(tctx, TEST_FILENAME, TEST_DATA, + "file contents"); + data = file_load(TEST_FILENAME, &len, mem_ctx); torture_assert(tctx, data, "loading file"); -- cgit From f2d64e1c45994e4b519454c071e90e0cd8240c8a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Sep 2007 15:55:26 +0000 Subject: r25306: Add tests for string_sub(). (This used to be commit 2d37ddcbd1243f48d81af17d8ea3cdd6e8e35b8d) --- source4/lib/util/tests/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util/tests/file.c') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index 0fe117a300..fe87293671 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -88,10 +88,10 @@ struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx) struct torture_suite *suite = torture_suite_create(mem_ctx, "FILE"); torture_suite_add_simple_test(suite, "file_load_save", - test_file_load_save); + test_file_load_save); torture_suite_add_simple_test(suite, "afdgets", - test_afdgets); + test_afdgets); return suite; } -- cgit From 148d3b170ae00d4001fa011450c7238052d32ae2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 13 Apr 2008 22:00:36 +0200 Subject: Use torture_assert_mem_equal() in a couple more places. (This used to be commit e2c3fab9d1bf0482c15a115e7d373562ffe50b29) --- source4/lib/util/tests/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/util/tests/file.c') diff --git a/source4/lib/util/tests/file.c b/source4/lib/util/tests/file.c index fe87293671..3377e833dc 100644 --- a/source4/lib/util/tests/file.c +++ b/source4/lib/util/tests/file.c @@ -45,9 +45,9 @@ static bool test_file_load_save(struct torture_context *tctx) data = file_load(TEST_FILENAME, &len, mem_ctx); torture_assert(tctx, data, "loading file"); - torture_assert(tctx, len == strlen(TEST_DATA), "Length"); + torture_assert_int_equal(tctx, len, strlen(TEST_DATA), "Length"); - torture_assert(tctx, memcmp(data, TEST_DATA, len) == 0, "Contents"); + torture_assert_mem_equal(tctx, data, TEST_DATA, len, "Contents"); unlink(TEST_FILENAME); return true; -- cgit