From patchwork Thu Feb 8 16:28:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 85470 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9000238582A9 for ; Thu, 8 Feb 2024 16:30:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 894843858C60 for ; Thu, 8 Feb 2024 16:28:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 894843858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 894843858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707409732; cv=none; b=mvvKW7mIJP88rysWUFsOJBnIL4iEyC3dmu4TpGftflVm4MuDAXQeGQ8r9ybJqTZR9AmgPZ4lwf7iPH/+lLMapCUDIbOv0rjvKrb+HwSEFvdOkXy4AzEDKt5AIEJpqdtloENIZ4C2TV1P+Gg6CQ6IbgDFN7+0CrUHge7f0BtXY60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707409732; c=relaxed/simple; bh=JSLBee/snA3v35gjrzIvcnGI8uhmPFprUPKp4HD0MYY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=oon1YVIjUaSYWrysdLSSsyY1wCWfb/gmymadsaHtHmtXURT3c5GUtSCx7wlwHrAX0eNGDR2aypLd8aeYtLOtQPO4xhuuBJOTBLQRvWba3TtaW4XTSZP9+OHcqrStCqOMQeFT3s4yBjQMqiMFD6Tb+3gGxibwxSIzH/X3153n63s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707409730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3mL+uqY7WrHvOwRvYyrUJRuxpuuXctCjM04uEnfdgqg=; b=UKJBeMqritTCKIixcO0Mbpwbve88JdAkmhX52jNhMJg6DQnU6ijUv3PJHW7p41HLDn5XCX xFJjhEoqcIEnsa9ZeFUfPOuitIXw99UhdaAHhUylOuMM/xiUAlG/xIBv3NBYf9xh/OBUBN v/6VrZaIxYy3ECjsm6pykRrdZHtoaF8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-A__XPAzGMzCsWQq0-oD9hg-1; Thu, 08 Feb 2024 11:28:49 -0500 X-MC-Unique: A__XPAzGMzCsWQq0-oD9hg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40e435a606aso115175e9.3 for ; Thu, 08 Feb 2024 08:28:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707409727; x=1708014527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3mL+uqY7WrHvOwRvYyrUJRuxpuuXctCjM04uEnfdgqg=; b=mkogjpP3gdxM1+JDj1oycdhF5NEy8YAZdj9ye96FeczgkiZEL7TSht0nVOFsq8mxub 9ECG2E2x2ZQhBRgk7opqi7V16PqulsIlXHCTz6ticY6piPxD4SLE37kS6XiT/Uply6Rq yT7bvfPPQWzV3NcNmxDXHFA7oBMbD8nolSLsOYoPsc1f0pHIl9MHtQx3bIAae4G/ah/4 s44+1IzN2ZQzB+9ATiZg9SpuxgKt7+rlpri10R+TyMtNmns6J408sG30MNuSAslnMPoF RewJUOHJKAdT+U1itsU+VS8e8ZQlFZCfZ56kE6mpacQ12vBX8FMvu+//ApBgc/JIpz/Y DwEA== X-Gm-Message-State: AOJu0Yz9DG1iiTIipdjR6G8GlKIbos8Sg0Lu5nQ6zkoszqHkzwRlYz9Z +CZEI9KdkqTCBeip7SWr+RnPvNTz2J64+3F4IdybRBB+zK8QRO3WEz3tM2Ak+xEjTXB/jI4VhOC +gKZYUx8vrqM70M8Y6vRUX/bejRuuyyBflRvIlmPNvK14CBOOmECY98+gvXmEPzSFw6SE1nzjV6 YwJNZXBcoQ/L0kPwFgBbrKKGDPYMu6lI+lLhSWjfncE7U= X-Received: by 2002:a05:600c:4750:b0:410:2793:4e91 with SMTP id w16-20020a05600c475000b0041027934e91mr2450433wmo.34.1707409727020; Thu, 08 Feb 2024 08:28:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0HGjg6KDrtu6UudpQdJgQV1hVtYTMzqSHjI7eRjV1BBEK7Nlh8TSInj9AwxzDf/cPul+5sg== X-Received: by 2002:a05:600c:4750:b0:410:2793:4e91 with SMTP id w16-20020a05600c475000b0041027934e91mr2450413wmo.34.1707409726239; Thu, 08 Feb 2024 08:28:46 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id jr1-20020a05600c560100b0040ef718cf81sm2051007wmb.28.2024.02.08.08.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 08:28:46 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/4] gdb/unittests: add extract_string_maybe_quoted self tests Date: Thu, 8 Feb 2024 16:28:40 +0000 Message-Id: <694821ad9a09cabbc3fa3eccda73836fea550773.1707409662.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit adds some self tests for the extract_string_maybe_quoted function. No functionality is changed in this commit. --- gdb/Makefile.in | 1 + gdb/unittests/extract-string-selftests.c | 85 ++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 gdb/unittests/extract-string-selftests.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 0e0f19c40c9..92fe06de489 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -457,6 +457,7 @@ SELFTESTS_SRCS = \ unittests/copy_bitwise-selftests.c \ unittests/enum-flags-selftests.c \ unittests/environ-selftests.c \ + unittests/extract-string-selftests.c \ unittests/filtered_iterator-selftests.c \ unittests/format_pieces-selftests.c \ unittests/frame_info_ptr-selftests.c \ diff --git a/gdb/unittests/extract-string-selftests.c b/gdb/unittests/extract-string-selftests.c new file mode 100644 index 00000000000..c2eedd75342 --- /dev/null +++ b/gdb/unittests/extract-string-selftests.c @@ -0,0 +1,85 @@ +/* Self tests for the function extract_string_maybe_quoted. + + Copyright (C) 2024 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#include "defs.h" +#include "gdbsupport/selftest.h" + +namespace selftests { +namespace extract_string { + +struct test_def +{ + test_def (const char *input, + const char *output, + size_t offset) + : m_input (input), + m_output (output), + m_offset (offset) + { /* Nothing. */ } + + void run () const + { + const char *tmp = m_input; + std::string test_out = extract_string_maybe_quoted (&tmp); + + if (run_verbose ()) + { + debug_printf ("Input: %s\n", m_input); + debug_printf ("Output [Got]: %s\n", test_out.c_str ()); + debug_printf ("Output [Exp]: %s\n", m_output); + debug_printf ("Rest [Got]: %s\n", tmp); + debug_printf ("Rest [Exp]: %s\n", (m_input + m_offset)); + } + + SELF_CHECK (test_out == m_output); + SELF_CHECK (tmp == m_input + m_offset); + } + +private: + const char *m_input; + const char *m_output; + size_t m_offset; +}; + +test_def tests[] = { + { "abc def", "abc", 3 }, + { "'abc' def", "abc", 5 }, + { "\"abc\" def", "abc", 5 }, + { "ab\\ cd ef", "ab cd", 6 }, + { "\"abc\\\"def\" ghi", "abc\"def", 10 }, + { "\"'abc' 'def'\" ghi", "'abc' 'def'", 13 }, +}; + +static void +run_tests () +{ + for (const auto &test : tests) + test.run (); +} + +} /* namespace extract_string */ +} /* namespace selftests */ + +void _initialize_extract_string_selftest (); +void +_initialize_extract_string_selftest () +{ + selftests::register_test ("extract-string", + selftests::extract_string::run_tests); +}