From owner-svn-src-head@FreeBSD.ORG Sun Mar 1 00:21:38 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 423E823C; Sun, 1 Mar 2015 00:21:38 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2565FDF5; Sun, 1 Mar 2015 00:21:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t210LcHH081281; Sun, 1 Mar 2015 00:21:38 GMT (envelope-from rstone@FreeBSD.org) Received: (from rstone@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t210LcDB081280; Sun, 1 Mar 2015 00:21:38 GMT (envelope-from rstone@FreeBSD.org) Message-Id: <201503010021.t210LcDB081280@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: rstone set sender to rstone@FreeBSD.org using -f From: Ryan Stone Date: Sun, 1 Mar 2015 00:21:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279427 - head/lib/libnv/tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Mar 2015 00:21:38 -0000 Author: rstone Date: Sun Mar 1 00:21:37 2015 New Revision: 279427 URL: https://svnweb.freebsd.org/changeset/base/279427 Log: Add test cases for nvlist_move_* Differential Revision: https://reviews.freebsd.org/D1872 Reviewed by: jfv, pjd MFC after: 1 month Sponsored by: Sandvine Inc. Modified: head/lib/libnv/tests/nv_tests.cc Modified: head/lib/libnv/tests/nv_tests.cc ============================================================================== --- head/lib/libnv/tests/nv_tests.cc Sun Mar 1 00:21:30 2015 (r279426) +++ head/lib/libnv/tests/nv_tests.cc Sun Mar 1 00:21:37 2015 (r279427) @@ -585,6 +585,83 @@ ATF_TEST_CASE_BODY(nvlist_unpack__duplic nvlist_destroy(unpacked); } +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert); +ATF_TEST_CASE_BODY(nvlist_move_string__single_insert) +{ + nvlist_t *nvl; + const char *key; + char *value; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + key = "testkey"; + value = strdup("testval"); + ATF_REQUIRE(value != NULL); + + nvlist_move_string(nvl, key, value); + ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child); +ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child) +{ + nvlist_t *parent; + + parent = nvlist_create(0); + + nvlist_move_nvlist(parent, "test", NULL); + + ATF_REQUIRE(nvlist_error(parent) != 0); + + nvlist_destroy(parent); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert); +ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert) +{ + nvlist_t *nvl; + const char *key; + nvlist_t *value; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + key = "testkey"; + value = nvlist_create(0); + ATF_REQUIRE(value != NULL); + + nvlist_move_nvlist(nvl, key, value); + ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value); + + nvlist_destroy(nvl); +} + +ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert); +ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert) +{ + nvlist_t *nvl; + const char *key; + void *value; + size_t size, actual_size; + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + key = "testkey"; + size = 73; + value = malloc(size); + ATF_REQUIRE(value != NULL); + + nvlist_move_binary(nvl, key, value, size); + ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value); + ATF_REQUIRE_EQ(size, actual_size); + + nvlist_destroy(nvl); +} + ATF_INIT_TEST_CASES(tp) { ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty); @@ -602,6 +679,11 @@ ATF_INIT_TEST_CASES(tp) ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist); ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values); ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key); + + ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert); + ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert); + ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child); + ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert); } /*- * Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.