[PATCH] lib/util: Add tests for strv
Bryan Burgin
bburgin at microsoft.com
Fri Feb 26 18:31:25 UTC 2016
Ignore this -- replied to wrong thread!
Sorry all!.
B.
-----Original Message-----
From: samba-technical [mailto:samba-technical-bounces at lists.samba.org] On Behalf Of Bryan Burgin
Sent: Friday, February 26, 2016 10:27 AM
To: Jeremy Allison <jra at samba.org>; Martin Schwenke <martin at meltin.net>
Cc: Samba Technical <samba-technical at lists.samba.org>
Subject: RE: [PATCH] lib/util: Add tests for strv
I set up two Windows 10 (10586) machines and did Windows backup:
wbadmin start backup -allCritical -backupTarget:\\10.0.0.103\share -user:workgroup\bburgin -password:P at ssw0rd
I note the Create has a VHDX V2 Open Context: [MS-RSVD] 2.2.4.32 "SVHDX_OPEN_DEVICE_CONTEXT_V2 Structure"
The response does NOT include [MS-RSVD] 2.2.4.33 "SVHDX_OPEN_DEVICE_CONTEXT_V2_RESPONSE Structure"
I'm looking into why that is.
Let's hold off acting on anything until the investigation is complete.
B.
-----Original Message-----
From: samba-technical [mailto:samba-technical-bounces at lists.samba.org] On Behalf Of Jeremy Allison
Sent: Friday, February 26, 2016 10:16 AM
To: Martin Schwenke <martin at meltin.net>
Cc: Samba Technical <samba-technical at lists.samba.org>
Subject: Re: [PATCH] lib/util: Add tests for strv
On Fri, Feb 26, 2016 at 04:05:32PM +1100, Martin Schwenke wrote:
> I thought I would learn how to write tests for something in lib/util.
> :-)
>
> Please review and perhaps push...
>
> peace & happiness,
> martin
Really nice job Martin - thanks ! More tests are always good :-).
Pushed.
> From f606ad87f3adc5e60102b51ba43bb1611f5ec204 Mon Sep 17 00:00:00 2001
> From: Martin Schwenke <martin at meltin.net>
> Date: Fri, 26 Feb 2016 15:23:31 +1100
> Subject: [PATCH] lib/util: Add tests for strv
>
> These are blackbox tests against most of the API.
>
> It would be possible to write tests that check the internals of the
> strv are as expected but that probably doesn't add much value.
>
> Signed-off-by: Martin Schwenke <martin at meltin.net>
> ---
> lib/util/tests/strv.c | 169 ++++++++++++++++++++++++++++++++++++
> source4/torture/local/local.c | 1 +
> source4/torture/local/wscript_build | 1 +
> 3 files changed, 171 insertions(+)
> create mode 100644 lib/util/tests/strv.c
>
> diff --git a/lib/util/tests/strv.c b/lib/util/tests/strv.c new file
> mode 100644 index 0000000..4030c44
> --- /dev/null
> +++ b/lib/util/tests/strv.c
> @@ -0,0 +1,169 @@
> +/*
> + * Tests for strv
> + *
> + * Copyright Martin Schwenke <martin at meltin.net> 2016
> + *
> + * 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 3 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, see <https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fwww.gnu.org%2flicenses%2f&data=01%7c01%7cbburgin%40microsoft.com%7c7c76430826bf40c0790c08d33ed97384%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=GcaQyVcMirpQqN1t9XHAfxrpPd56Dpl5wO6fH0RxJU8%3d>.
> + */
> +
> +
> +#include <talloc.h>
> +
> +#include "replace.h"
> +
> +#include "libcli/util/ntstatus.h"
> +#include "torture/torture.h"
> +#include "lib/util/data_blob.h"
> +#include "torture/local/proto.h"
> +
> +#include "lib/util/strv.h"
> +
> +static bool test_strv_empty(struct torture_context *tctx) {
> + /* NULL strv contains 0 entries */
> + torture_assert_int_equal(tctx,
> + strv_count(NULL),
> + 0,
> + "strv_count() on NULL failed");
> +
> + /* NULL strv has no next entry */
> + torture_assert(tctx,
> + strv_next(NULL, NULL) == NULL,
> + "strv_next() on NULL failed");
> +
> + return true;
> +}
> +
> +static bool test_strv_single(struct torture_context *tctx) {
> + const char *data = "foo";
> + char *strv = NULL;
> + char *t;
> + int ret;
> +
> + /* Add an item */
> + ret = strv_add(tctx, &strv, data);
> + torture_assert(tctx, ret == 0, "strv_add() failed");
> +
> + /* Is there 1 item? */
> + torture_assert_int_equal(tctx,
> + strv_count(strv), 1,
> + "strv_count() failed");
> +
> + /* Is the expected item the first one? */
> + t = strv_next(strv, NULL);
> + torture_assert(tctx,
> + strcmp(t, data) == 0,
> + "strv_next() failed");
> +
> + /* Can the expected item be found? */
> + t = strv_find(strv, data);
> + torture_assert(tctx,
> + strcmp(t, data) == 0,
> + "strv_next() failed");
> +
> + /* Delete it */
> + strv_delete(&strv, t);
> +
> + /* Should have no items */
> + torture_assert_int_equal(tctx,
> + strv_count(strv), 0,
> + "strv_count() failed");
> + return true;
> +}
> +
> +static bool test_strv_multi(struct torture_context *tctx) {
> + const char *data[5] = { "foo", "bar", "", "samba", "x"};
> + char *strv = NULL;
> + char *t;
> + int i, ret;
> + const int num = sizeof(data) / sizeof(data[0]);
> +
> + /* Add items */
> + for (i = 0; i < num; i++) {
> + ret = strv_add(tctx, &strv, data[i]);
> + torture_assert(tctx, ret == 0, "strv_add() failed");
> + }
> +
> + torture_assert_int_equal(tctx,
> + strv_count(strv), num,
> + "strv_count() failed");
> +
> + /* Check that strv_next() finds the expected values */
> + t = NULL;
> + for (i = 0; i < num; i++) {
> + t = strv_next(strv, t);
> + torture_assert(tctx,
> + strcmp(t, data[i]) == 0,
> + "strv_next() failed");
> + }
> +
> +
> + /* Check that strv_next() finds the expected values */
> + t = NULL;
> + for (i = 0; i < num; i++) {
> + t = strv_next(strv, t);
> + torture_assert(tctx,
> + strcmp(t, data[i]) == 0,
> + "strv_next() failed");
> + }
> +
> + /* Find each item, delete it, check count */
> + for (i = 0; i < num; i++) {
> + t = strv_find(strv, data[i]);
> + torture_assert(tctx,
> + strcmp(t, data[i]) == 0,
> + "strv_next() failed");
> + strv_delete(&strv, t);
> + torture_assert_int_equal(tctx,
> + strv_count(strv), num - i - 1,
> + "strv_delete() failed");
> + }
> +
> + /* Add items */
> + for (i = 0; i < num; i++) {
> + ret = strv_add(tctx, &strv, data[i]);
> + torture_assert(tctx, ret == 0, "strv_add() failed");
> + }
> +
> + torture_assert_int_equal(tctx,
> + strv_count(strv), num,
> + "strv_count() failed");
> +
> + /* Find items in reverse, delete, check count */
> + for (i = num - 1; i >= 0; i--) {
> + t = strv_find(strv, data[i]);
> + torture_assert(tctx,
> + strcmp(t, data[i]) == 0,
> + "strv_next() failed");
> + strv_delete(&strv, t);
> + torture_assert_int_equal(tctx,
> + strv_count(strv), i,
> + "strv_delete() failed");
> + }
> +
> + return true;
> +}
> +
> +struct torture_suite *torture_local_util_strv(TALLOC_CTX *mem_ctx) {
> + struct torture_suite *suite = torture_suite_create(mem_ctx, "strv");
> +
> + torture_suite_add_simple_test(suite, "strv_empty", test_strv_empty);
> + torture_suite_add_simple_test(suite, "strv_single", test_strv_single);
> + torture_suite_add_simple_test(suite, "strv_multi", test_strv_multi);
> +
> + return suite;
> +}
> diff --git a/source4/torture/local/local.c
> b/source4/torture/local/local.c index 3988988..1f68aac 100644
> --- a/source4/torture/local/local.c
> +++ b/source4/torture/local/local.c
> @@ -41,6 +41,7 @@
> torture_local_util_data_blob,
> torture_local_util_asn1,
> torture_local_util_anonymous_shared,
> + torture_local_util_strv,
> torture_local_idtree,
> torture_local_dlinklist,
> torture_local_genrand,
> diff --git a/source4/torture/local/wscript_build
> b/source4/torture/local/wscript_build
> index eb45df8..ef1fb30 100644
> --- a/source4/torture/local/wscript_build
> +++ b/source4/torture/local/wscript_build
> @@ -17,6 +17,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c
> dbspeed.c torture.c ../ldb/ldb.c ../../dsdb/common/tests/dsdb_dn.c
> ../../dsdb/schema/tests/schema_syntax.c
> ../../../lib/util/tests/anonymous_shared.c
> + ../../../lib/util/tests/strv.c
> verif_trailer.c
> nss_tests.c
> fsrvp_state.c'''
> --
> 2.7.0
>
More information about the samba-technical
mailing list