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 75699A00C4; Mon, 25 Jul 2022 18:36:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C75A04282D; Mon, 25 Jul 2022 18:36:10 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 4768A4282D for ; Mon, 25 Jul 2022 18:36:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658766968; x=1690302968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3R7YDQkLSJb0lMuB2SKKfDQinNEFHdqXX2l2iCPysLk=; b=YX8AWQQw5VRfytWxVh6YyDZ21kJ8d71ukxZ9wM/rOoBBLhG0P+l4SEEx cnb47e45p7MotASdmb7c9+EPfSMEBnP+MVUbzypeliAIF8CB7xM6P1Efp Kz9HbLMZ74sukHmNvbXycQ5JS/rotPUdOq793JqBHDacgAlHnBjT+1Apx URxjNYSgTtQUhVI6tJB9nPTd9YlCmm1LacDJcjLSoaxOjUKQDp6vu+odN t1Ev5LBfu5uRNeokeS/zPB45RjYV1HXoPVdONCrWpRkuuTdllRQb3BmA6 YXBKz04lS66+euuBP7HGggzc6VURuVLe2G6DXIW4I+J8lgdqE5/bunhJi Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="288499057" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="288499057" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 09:36:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="575121874" Received: from silpixa00401385.ir.intel.com (HELO silpixa00401385.ger.corp.intel.com.) ([10.237.223.47]) by orsmga006.jf.intel.com with ESMTP; 25 Jul 2022 09:36:06 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power Subject: [PATCH v2 03/13] test/telemetry_json: add test for string character escaping Date: Mon, 25 Jul 2022 17:35:32 +0100 Message-Id: <20220725163543.875775-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220725163543.875775-1-bruce.richardson@intel.com> References: <20220623164245.561371-1-bruce.richardson@intel.com> <20220725163543.875775-1-bruce.richardson@intel.com> MIME-Version: 1.0 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 unit test to validate that when creating a string response in json, that characters such as \n or quotes are properly escaped. Signed-off-by: Bruce Richardson --- app/test/test_telemetry_json.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 748b7cfe5a..955c2e5b1b 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -125,6 +125,22 @@ test_large_obj_element(void) return strncmp(expected, buf, sizeof(buf)); } +static int +test_string_char_escaping(void) +{ + static const char str[] = "A string across\ntwo lines and \"with quotes\"!"; + const char *expected = "\"A string across\\ntwo lines and \\\"with quotes\\\"!\""; + char buf[sizeof(str) + 10]; + int used = 0; + + used = rte_tel_json_str(buf, sizeof(buf), used, str); + printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); + if (used != (int)strlen(expected)) + return -1; + + return strncmp(expected, buf, sizeof(buf)); +} + typedef int (*test_fn)(void); static int @@ -138,6 +154,7 @@ test_telemetry_json(void) test_overflow_obj, test_large_array_element, test_large_obj_element, + test_string_char_escaping, }; for (i = 0; i < RTE_DIM(fns); i++) if (fns[i]() == 0) -- 2.34.1