From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D94C5A0540; Fri, 9 Sep 2022 11:36:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E87CB42B7E; Fri, 9 Sep 2022 11:35:53 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 0927F42829 for ; Fri, 9 Sep 2022 11:35:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662716151; x=1694252151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ybuJsbCS+BMl1wZU5d0yuc0/cz5tUQOOhQf4ftnns8M=; b=dS8+ws7k+GntD+tL/RxCYgmJkGD/ZmtYK++/cilUqXKFePjZ8xnRPvEG oyWf5tNOyTa6N2lGclh6gu6xfH33zGcEIeLQf6+dpkdhxdQ98nZydBtad VVet1lr2YHS57FUn+0kPIV9vi96du7KRnopuZKf05JmYQ27vf07zaE8AV PiKksIaAFBk+UENA7noNvF2JvZrKJdiU8MUeqv9a0ZThb2uvUcdpHkSoP AlZIIByr+CfSvQfi1Q+HHrBGygodIUt2ChH/7tRYr7Mq1E6k7RyehEqek tc7AoFxa/NCDF85mo8rR6GlfoTsMYQ0v82eE7EQvIiV1/jJePFW5FlJC7 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="297437135" X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="297437135" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2022 02:35:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="740996409" Received: from silpixa00401385.ir.intel.com ([10.237.214.161]) by orsmga004.jf.intel.com with ESMTP; 09 Sep 2022 02:35:48 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v3 08/13] test/telemetry_json: add test for string escaping in objects Date: Fri, 9 Sep 2022 10:35:18 +0100 Message-Id: <20220909093523.471727-9-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220909093523.471727-1-bruce.richardson@intel.com> References: <20220623164245.561371-1-bruce.richardson@intel.com> <20220909093523.471727-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add a test-case to validate that when adding strings either as the name or the value of an entry in an object, that all values are escaped properly. Signed-off-by: Bruce Richardson Acked-by: Ciara Power Acked-by: Morten Brørup --- app/test/test_telemetry_json.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 31a13ea1d7..184c3ba9f1 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -164,6 +164,29 @@ test_array_char_escaping(void) return strncmp(expected, buf, sizeof(buf)); } +static int +test_obj_char_escaping(void) +{ + const char *expected = "{\"good\":\"Clint Eastwood\\n\"," + "\"bad\":\"Lee\\tVan\\tCleef\"," + "\"ugly\":\"\\rEli Wallach\"}"; + char buf[1024]; + int used = 0; + + used = rte_tel_json_empty_obj(buf, sizeof(buf), used); + if (used != 2 || strcmp(buf, "{}")) + return -1; + + used = rte_tel_json_add_obj_str(buf, sizeof(buf), used, "good", "Clint Eastwood\n"); + used = rte_tel_json_add_obj_str(buf, sizeof(buf), used, "bad", "Lee\tVan\tCleef"); + used = rte_tel_json_add_obj_str(buf, sizeof(buf), used, "ugly", "\rEli Wallach"); + + printf("buf = '%s', expected = '%s'\n", buf, expected); + if (used != (int)strlen(expected)) + return -1; + return strncmp(expected, buf, sizeof(buf)); +} + typedef int (*test_fn)(void); static int @@ -179,6 +202,7 @@ test_telemetry_json(void) test_large_obj_element, test_string_char_escaping, test_array_char_escaping, + test_obj_char_escaping }; for (i = 0; i < RTE_DIM(fns); i++) if (fns[i]() == 0) -- 2.34.1