From patchwork Mon Jan 14 09:54:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 222 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E32DD60C6A for ; Mon, 14 Jan 2019 10:54:21 +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 69ABB530; Mon, 14 Jan 2019 10:54:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547459661; bh=/fE6aOUSI0e6XdN7rveyCnhQUi+6lY5g4WPeeWxslfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=krLlo4N828lspLQajS+crGUA/17rsqzX+7AKuzkfngKAgvIXO+uc1Nbbe0vPWRB7w 4+fahGuKSZy42DpV+E+LCIn1liZ4wdKNJATWgxKA0bI3g7u1GoZmYgb+nfuUOoGaco sSKwXHr/BAhKtBCblEV7JoI88rwNzWMKsfPCfhIk= From: Kieran Bingham To: LibCamera Devel Date: Mon, 14 Jan 2019 09:54:16 +0000 Message-Id: <20190114095417.16473-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190114095417.16473-1-kieran.bingham@ideasonboard.com> References: <20190114095417.16473-1-kieran.bingham@ideasonboard.com> Subject: [libcamera-devel] [PATCH RFC 1/2] test: Add TestStatus classes X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jan 2019 09:54:22 -0000 Provide Class object to return the test status, and perform any result reporting. Signed-off-by: Kieran Bingham --- test/libtest/meson.build | 1 + test/libtest/test.h | 2 ++ test/libtest/test_status.cpp | 42 +++++++++++++++++++++++++++ test/libtest/test_status.h | 55 ++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 test/libtest/test_status.cpp create mode 100644 test/libtest/test_status.h diff --git a/test/libtest/meson.build b/test/libtest/meson.build index e0893b70c3d4..a9e67d8d7e6c 100644 --- a/test/libtest/meson.build +++ b/test/libtest/meson.build @@ -1,5 +1,6 @@ libtest_sources = files([ 'test.cpp', + 'test_status.cpp', ]) libtest = static_library('libtest', libtest_sources) diff --git a/test/libtest/test.h b/test/libtest/test.h index ec08bf97c03d..d816cf15aaf0 100644 --- a/test/libtest/test.h +++ b/test/libtest/test.h @@ -9,6 +9,8 @@ #include +#include "test_status.h" + enum TestStatus { TestPass = 0, TestFail = -1, diff --git a/test/libtest/test_status.cpp b/test/libtest/test_status.cpp new file mode 100644 index 000000000000..c0daef866740 --- /dev/null +++ b/test/libtest/test_status.cpp @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * test_status.cpp - libcamera test result management + */ + +#include "test.h" + +static unsigned int test_number = 0; + +TestStatusBase::TestStatusBase() + : value(-99) +{ + test_number++; +}; + +TestStatusBase::~TestStatusBase() +{ + std::cout << prefix << test_number << " " << message << std::endl; +}; + +TestStatusPass::TestStatusPass(const std::string &m) +{ + value = ValuePass; + prefix = "ok "; + message = m; +}; + +TestStatusFail::TestStatusFail(const std::string &m) +{ + value = ValueFail; + prefix = "not ok "; + message = m; +}; + +TestStatusSkip::TestStatusSkip(const std::string &m) +{ + value = ValueSkip; + prefix = "skip "; + message = m; +}; diff --git a/test/libtest/test_status.h b/test/libtest/test_status.h new file mode 100644 index 000000000000..2e4713ad3f6d --- /dev/null +++ b/test/libtest/test_status.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * test_status.h - libcamera test status class + */ +#ifndef __TEST_TEST_STATUS_H__ +#define __TEST_TEST_STATUS_H__ + +#include +#include + +class TestStatusBase +{ +public: + TestStatusBase(); + TestStatusBase(const std::string &m); + ~TestStatusBase(); + + operator int() { return value; }; + + enum ReturnValues { + ValuePass = 0, + ValueFail = -1, + ValueSkip = 77, + }; + +protected: + int value; + std::string prefix; + std::string message; +}; + +class TestStatusPass : public TestStatusBase +{ +public: + TestStatusPass(const std::string &m); +}; + +class TestStatusFail : public TestStatusBase +{ +public: + TestStatusFail(const std::string &m); +}; + +class TestStatusSkip : public TestStatusBase +{ +public: + TestStatusSkip(const std::string &m); +}; + +#define is(a, b, m) ({((a) == (b)) ? TestStatusPass((m)) : TestStatusFail((m));}) +#define isnt(a, b, m) ({((a) != (b)) ? TestStatusPass((m)) : TestStatusFail((m));}) + +#endif /* __TEST_TEST_STATUS_H__ */ From patchwork Mon Jan 14 09:54:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 223 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21D3E60C76 for ; Mon, 14 Jan 2019 10:54:22 +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 B04FD573; Mon, 14 Jan 2019 10:54:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547459661; bh=9fT3IChQjj2P7BbXLBZfOh6Tmd8voRWI2qNFdfoB2p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMMUh8osGdSo9x942b3ovM0qg9O0OTL36py09aR0Qh4nBlpFyc6qGMpMyk1uAA3tb 0wUlN8+gdA9h1Xkj4Dqw2u305/jEHhpr1brTk4yPyk+OcsLSw8Fbmr3oHtE7j9PhBP 8/LXDDWyHQjNde3WjkSdHe+DvXr62w47jwM3+pyQ= From: Kieran Bingham To: LibCamera Devel Date: Mon, 14 Jan 2019 09:54:17 +0000 Message-Id: <20190114095417.16473-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190114095417.16473-1-kieran.bingham@ideasonboard.com> References: <20190114095417.16473-1-kieran.bingham@ideasonboard.com> Subject: [libcamera-devel] [PATCH RFC 2/2] test: Provide TestStatus validation tests X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jan 2019 09:54:22 -0000 Validate the return values of the objects, and the ability to use "is" and "isnt()" correctly. Signed-off-by: Kieran Bingham --- test/meson.build | 1 + test/test_status.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/test_status.cpp diff --git a/test/meson.build b/test/meson.build index 32152888a55e..ae5bd7b47b3b 100644 --- a/test/meson.build +++ b/test/meson.build @@ -6,6 +6,7 @@ public_tests = [ ['event', 'event.cpp'], ['list-cameras', 'list-cameras.cpp'], ['signal', 'signal.cpp'], + ['test_status', 'test_status.cpp'], ['timer', 'timer.cpp'], ] diff --git a/test/test_status.cpp b/test/test_status.cpp new file mode 100644 index 000000000000..297cc5189f49 --- /dev/null +++ b/test/test_status.cpp @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * list.cpp - camera list tests + */ + +#include +#include + +#include "test.h" + +class TestStatusTest : public Test +{ +protected: + int run() + { + // plan(8); + // note("Correct output here is 1 skip, and three failures"); + + /* + * TestStatusPass should return 0. + * Test without operator= + */ + if (TestStatusPass("[Verify TestStatusPass]")) + return TestStatusFail("TestStatusPass test"); + + /* Test an integer on the rhs. */ + if (TestStatusFail("[Verify TestStatusFail]") != -1) + return TestStatusFail("TestStatusFail test"); + + /* Test an integer on the lhs. */ + if (77 != TestStatusSkip("[Verify TestStatusSkip]")) + return TestStatusFail("TestStatusSkip test"); + + if (is(1, 1, "[Good is return check]") != TestStatusBase::ValuePass) + return TestStatusFail("Good is check failed"); + + if (isnt(1, 0, "[Good isn't return check]") != TestStatusBase::ValuePass) + return TestStatusFail("Good isn't check failed"); + + if (is(1, 0, "[Bad Is Check]") == TestStatusBase::ValuePass) + return TestStatusFail("Bad is check failed"); + + if (isnt(1, 1, "[Bad Isn't check]") == TestStatusBase::ValuePass) + return TestStatusFail("Bad isn't check failed"); + + return TestStatusPass("TestStatus validations"); + } +}; + +TEST_REGISTER(TestStatusTest)