From patchwork Sun Jul 12 14:44:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8747 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 59602BD792 for ; Sun, 12 Jul 2020 14:44:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 473BB605A7; Sun, 12 Jul 2020 16:44: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="nsovdzhi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2589660553 for ; Sun, 12 Jul 2020 16:44:46 +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 BA357DC4 for ; Sun, 12 Jul 2020 16:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594565085; bh=uxCB+MLhJuSW1VvUkO6kR84shuC0hnMrYGFKLYY23eg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nsovdzhiUtXtx+llrtJZ8zhjBQXSTpAquOFWy6lLgxLNBnAgcNkwDCu2eYZ53Fo4x XNIRCuk8A6CSQMD1nTrSfao3Bc4gamoWbgmULSNrbwDkY6xGssGoMrwMLiK2qRhaBr U4W7OC66p5clkH+9+7pfPPkRXxqEw1ghgj0IdgF8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Jul 2020 17:44:18 +0300 Message-Id: <20200712144419.21457-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> References: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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;