From patchwork Mon May 18 16:48:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3806 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50F3F603DA for ; Mon, 18 May 2020 18:48:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DKtLNl52"; dkim-atps=neutral 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 89ADBA1D; Mon, 18 May 2020 18:48:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589820498; bh=IlXuCsF606gAAUT1DnoKfLX3xufurPFMCIrVBdSjci4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DKtLNl52mVELCIH1Bep9z28D+ap5Uapj8d2zQ9RlgKtLx62SN2VPekB8vY3Joktoq AJpFwA83485jl04rb5RSOUifQJH/+iKJLozo6iHybwhcFneDzFKwMjrt8YUYld3BJF AuQ6LqzuQVtLAl/tL0a0e7osTv/fIqqJUadXienM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 18 May 2020 19:48:03 +0300 Message-Id: <20200518164804.10088-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518164804.10088-1-laurent.pinchart@ideasonboard.com> References: <20200518164804.10088-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] test: file-descriptor: Add "fd move" constructor 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: Mon, 18 May 2020 16:48:18 -0000 Add a test for the newly added "fd move" constructor. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/file-descriptor.cpp | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/test/file-descriptor.cpp b/test/file-descriptor.cpp index 7477a843531c..aa3c896fb937 100644 --- a/test/file-descriptor.cpp +++ b/test/file-descriptor.cpp @@ -56,16 +56,19 @@ protected: delete desc1_; desc1_ = nullptr; - /* Test creating FileDescriptor from numerical file descriptor. */ + /* + * Test creating FileDescriptor by copying numerical file + * descriptor. + */ desc1_ = new FileDescriptor(fd_); if (desc1_->fd() == fd_) { - std::cout << "Failed fd numerical check (int constructor)" + std::cout << "Failed fd numerical check (lvalue ref constructor)" << std::endl; return TestFail; } if (!isValidFd(fd_) || !isValidFd(desc1_->fd())) { - std::cout << "Failed fd validity after construction (int constructor)" + std::cout << "Failed fd validity after construction (lvalue ref constructor)" << std::endl; return TestFail; } @@ -76,7 +79,38 @@ protected: desc1_ = nullptr; if (!isValidFd(fd_) || isValidFd(fd)) { - std::cout << "Failed fd validity after destruction (int constructor)" + std::cout << "Failed fd validity after destruction (lvalue ref constructor)" + << std::endl; + return TestFail; + } + + /* + * Test creating FileDescriptor by taking ownership of + * numerical file descriptor. + */ + int dupFd = dup(fd_); + int dupFdCopy = dupFd; + + desc1_ = new FileDescriptor(std::move(dupFd)); + if (desc1_->fd() != dupFdCopy) { + std::cout << "Failed fd numerical check (rvalue ref constructor)" + << std::endl; + return TestFail; + } + + if (dupFd != -1 || !isValidFd(fd_) || !isValidFd(desc1_->fd())) { + std::cout << "Failed fd validity after construction (rvalue ref constructor)" + << std::endl; + return TestFail; + } + + fd = desc1_->fd(); + + delete desc1_; + desc1_ = nullptr; + + if (!isValidFd(fd_) || isValidFd(fd)) { + std::cout << "Failed fd validity after destruction (rvalue ref constructor)" << std::endl; return TestFail; }