From patchwork Tue Jul 14 09:09:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8773 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8C6A3BD790 for ; Tue, 14 Jul 2020 09:09:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3C0AC60839; Tue, 14 Jul 2020 11:09:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="v4oUBEeM"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A1B6160486 for ; Tue, 14 Jul 2020 11:09:47 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4B363564 for ; Tue, 14 Jul 2020 11:09:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594717787; bh=4Q6mWaJxSH6gDRcVDdSTfMaXLzYh/nkWlR/I+hAhK6E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=v4oUBEeMhhjBItvYzlCD9T+HzzwdRk88CNXbHsOL+LMNEARLwdco7Jpk27Xw6saVd ABWI8duSDOUmOM1sLOJ82UL/wabMn6c6MbrBIm9F4/qLqyjEvxhc2J3wpsmCtNtF+4 sqO/F1HT1avUZAb+m7qMzq8Ifhi0w+ieHHUvRBOc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Jul 2020 12:09:35 +0300 Message-Id: <20200714090936.9562-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714090936.9562-1-laurent.pinchart@ideasonboard.com> References: <20200714090936.9562-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/4] test: file: Add file creation 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a test to verify file creation with File::open(). The test is expected to fail as the File::open() implementation is not correct. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- test/file.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/file.cpp b/test/file.cpp index 7688a9dc224a..f458f355ccad 100644 --- a/test/file.cpp +++ b/test/file.cpp @@ -31,6 +31,7 @@ protected: return TestFail; close(fd); + unlink(fileName_.c_str()); return TestPass; } @@ -191,14 +192,37 @@ protected: file.close(); + /* Test file creation. */ + file.setFileName(fileName_); + + if (file.exists()) { + cerr << "Temporary file already exists" << endl; + return TestFail; + } + + if (file.open(File::ReadOnly)) { + cerr << "Read-only open succeeded on nonexistent file" << endl; + return TestFail; + } + + if (!file.open(File::WriteOnly)) { + cerr << "Write-only open failed on nonexistent file" << endl; + return TestFail; + } + + if (!file.exists()) { + cerr << "Write-only open failed to create file" << endl; + return TestFail; + } + + file.close(); + /* Test read and write. */ std::array buffer = { 0 }; strncpy(reinterpret_cast(buffer.data()), "libcamera", buffer.size()); - file.setFileName(fileName_); - if (file.read(buffer) >= 0) { cerr << "Read succeeded on closed file" << endl; return TestFail;