From patchwork Thu Feb 13 13:09:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2810 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5578061958 for ; Thu, 13 Feb 2020 14:09:13 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED81C504; Thu, 13 Feb 2020 14:09:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1581599353; bh=xhgeLtquKj+d/2LPChJ3bUCfAhA8plkueBEKBN0yHl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TAK+zfqTBg8IpZiMwivyt1/r6vOzLvebGlkvB+rwiVgP7F16G7t4Y1m6ys3wcF20c ZmBLRHtAlxXeeJFvlO7G344R/YHoK1L1rpXyw+d6TFk45RwjfvEvtwG8YsOGZOnOEI SJzqc8lMvJUFRQoeuFh0D5IBBEauMujSPctchlcQ= From: Kieran Bingham To: libcamera devel Date: Thu, 13 Feb 2020 13:09:07 +0000 Message-Id: <20200213130908.23638-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213130908.23638-1-kieran.bingham@ideasonboard.com> References: <20200213130908.23638-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] test: Add a utils::split() test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Feb 2020 13:09:13 -0000 From: Laurent Pinchart The test constructs a string by joining substrings, splits it, and verifies that the original and resulting substrings match. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/utils.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/utils.cpp b/test/utils.cpp index 9fe0d4775b73..db1fbdde847d 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include #include "test.h" #include "utils.h" @@ -19,6 +21,7 @@ class UtilsTest : public Test protected: int run() { + /* utils::hex() test. */ std::ostringstream os; std::string ref; @@ -46,6 +49,28 @@ protected: return TestFail; } + /* utils::split() test. */ + std::vector elements = { + "/bin", + "/usr/bin", + "", + "", + }; + + std::string path; + for (const auto &element : elements) + path += (path.empty() ? "" : ":") + element; + + std::vector dirs; + + for (const auto &dir : utils::split(path, ":")) + dirs.push_back(dir); + + if (dirs != elements) { + cerr << "utils::split() test failed" << endl; + return TestFail; + } + return TestPass; } };