[compute] 36/46: if the ifstream can't be created in program::create_with_source_file then it throws std::ios_base::failure.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Dec 21 18:28:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository compute.
commit 0a2d7fa0e119cf9202d2d666eceef883df39529d
Author: Alex Olivas <olivas at icecube.umd.edu>
Date: Wed Nov 18 16:27:19 2015 -0700
if the ifstream can't be created in program::create_with_source_file then it throws std::ios_base::failure.
---
include/boost/compute/program.hpp | 4 ++++
test/test_program.cpp | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/include/boost/compute/program.hpp b/include/boost/compute/program.hpp
index 526ca2b..218d840 100644
--- a/include/boost/compute/program.hpp
+++ b/include/boost/compute/program.hpp
@@ -394,6 +394,10 @@ public:
// open file stream
std::ifstream stream(file.c_str());
+ if(stream.fail()){
+ BOOST_THROW_EXCEPTION(std::ios_base::failure("failed to create stream."));
+ }
+
// read source
std::string source(
(std::istreambuf_iterator<char>(stream)),
diff --git a/test/test_program.cpp b/test/test_program.cpp
index 2b004ee..9240293 100644
--- a/test/test_program.cpp
+++ b/test/test_program.cpp
@@ -55,6 +55,16 @@ BOOST_AUTO_TEST_CASE(program_source)
BOOST_CHECK_EQUAL(std::string(source), program.source());
}
+BOOST_AUTO_TEST_CASE(program_source_no_file)
+{
+ // create program from a non-existant source file
+ // and verifies it throws.
+ BOOST_CHECK_THROW(boost::compute::program program =
+ boost::compute::program::create_with_source
+ (std::string(), context),
+ std::ios_base::failure);
+}
+
BOOST_AUTO_TEST_CASE(create_kernel)
{
boost::compute::program program =
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git
More information about the debian-science-commits
mailing list