Permalink
Browse files

Merge pull request #360 from lgremy/Wcatch-value

Remove Wcatch-value and unify way to check if files are read.
  • Loading branch information...
malb committed Oct 4, 2018
2 parents 2219652 + ccf2f60 commit 5419de48e85b3c9bb429927380f9c90cb11937ea
Showing with 18 additions and 40 deletions.
  1. +1 −1 tests/test_bkz.cpp
  2. +3 −3 tests/test_cvp.cpp
  3. +2 −2 tests/test_gso.cpp
  4. +1 −1 tests/test_lll.cpp
  5. +1 −1 tests/test_lll_gram.cpp
  6. +2 −2 tests/test_sieve.cpp
  7. +2 −2 tests/test_svp.cpp
  8. +6 −28 tests/test_utils.h
View
@@ -274,7 +274,7 @@ int test_filename(const char *input_filename, const int block_size,
{
ZZ_mat<ZT> A, B;
int status = 0;
status |= read_matrix(A, input_filename);
status |= read_file(A, input_filename);
B = A;
status |= test_bkz<ZT>(A, block_size, float_type, flags, prec);
status |= test_bkz_param<ZT>(B, block_size);
View
@@ -89,13 +89,13 @@ int test_filename(const char *input_filename_lattice, const char *input_filename
{
ZZ_mat<ZT> A;
int status = 0;
status |= read_matrix(A, input_filename_lattice);
status |= read_file(A, input_filename_lattice);
vector<Z_NR<mpz_t>> t;
status |= read_vector(t, input_filename_target);
status |= read_file(t, input_filename_target);
vector<Z_NR<mpz_t>> b;
status |= read_vector(b, output_filename);
status |= read_file(b, output_filename);
status |= test_cvp<ZT>(A, t, b, method);
return status;
View
@@ -151,8 +151,8 @@ template <class ZT, class FT> int test_ggso(ZZ_mat<ZT> &A)
template <class ZT, class FT> int test_filename(const char *input_filename)
{
ZZ_mat<ZT> A;
int status = read_matrix(A, input_filename);
// if status == 1, read_matrix fails.
int status = read_file(A, input_filename);
// if status == 1, read_file fails.
if (status == 1)
{
return 1;
View
@@ -119,7 +119,7 @@ int test_filename(const char *input_filename, LLLMethod method, FloatType float_
{
ZZ_mat<ZT> A;
int status = 0;
status |= read_matrix(A, input_filename);
status |= read_file(A, input_filename);
status |= test_lll<ZT>(A, method, float_type, flags, prec);
return status;
}
View
@@ -179,7 +179,7 @@ template <class ZT, class FT> int test_filename(const char *input_filename)
{
ZZ_mat<ZT> A;
int status = 0;
status |= read_matrix(A, input_filename);
status |= read_file(A, input_filename);
status |= test_lll<ZT, FT>(A);
return status;
}
View
@@ -58,9 +58,9 @@ template <class ZT> int test_filename(const char *input_filename, const char *ou
{
ZZ_mat<ZT> A;
int status = 0;
status |= read_matrix(A, input_filename);
status |= read_file(A, input_filename);
vector<Z_NR<mpz_t>> b;
status |= read_vector(b, output_filename);
status |= read_file(b, output_filename);
status |= test_sieve<ZT>(A, b);
return status;
}
View
@@ -266,10 +266,10 @@ int test_filename(const char *input_filename, const char *output_filename,
{
ZZ_mat<ZT> A;
int status = 0;
status |= read_matrix(A, input_filename);
status |= read_file(A, input_filename);
vector<Z_NR<mpz_t>> b;
status |= read_vector(b, output_filename);
status |= read_file(b, output_filename);
switch (test)
{
View
@@ -6,48 +6,26 @@ using namespace std;
using namespace fplll;
/**
@brief Read matrix from `input_filename`.
@brief Read T from `input_filename`.
@param A matrix
@param X T (T is usually a ZZ_mat<ZT> or a vector<Z_NR<ZT>>
@param input_filename
@return zero if the file is correctly read, 1 otherwise.
*/
template <class ZT> int read_matrix(ZZ_mat<ZT> &A, const char *input_filename)
{
int status = 0;
ifstream is(input_filename);
if (!is)
{
status = 1;
cerr << "Could not open file " << input_filename << "." << endl;
} // throw std::runtime_error("could not open input file");
is >> A;
return status;
}
/**
@brief Read vector from `input_filename` into `b`.
@param b vector
@param input_filename filename
@return zero if the file is correctly read, 1 otherwise.
*/
template <class ZT> int read_vector(vector<Z_NR<ZT>> &b, const char *input_filename)
{
template <class T> int read_file(T &X, const char *input_filename) {
int status = 0;
ifstream is;
is.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try {
is.open(input_filename);
is >> b;
is >> X;
is.close();
}
catch (ifstream::failure e) {
catch (const ifstream::failure&) {
status = 1;
cerr << "Error by reading " << input_filename << "." << endl;
}
return status;
}
#endif /* TEST_UTILS_H */

0 comments on commit 5419de4

Please sign in to comment.