Skip to content

Commit

Permalink
Add unit-tests for tuples (too large, too small)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 10, 2015
1 parent 98ac35a commit 6c8b8a7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/test-py2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,26 @@ TEST(CppBuilder_tuple, FromTuple)
EXPECT_FALSE(uncaught_exception());
}

TEST(CppBuilder_tuple, FromTooSmallTuple)
{
std::unique_ptr<PyObject, decref> pyo { PyRun_String("(1,)", Py_eval_input, py_dict, NULL) };
ASSERT_NE(nullptr, pyo.get());

auto Functor = CppBuilder<std::tuple<int, std::string>>();
EXPECT_THROW(Functor(pyo.get()), std::length_error);
EXPECT_FALSE(uncaught_exception());
}

TEST(CppBuilder_tuple, FromTooLargeTuple)
{
std::unique_ptr<PyObject, decref> pyo { PyRun_String("(1, 'toto', 2)", Py_eval_input, py_dict, NULL) };
ASSERT_NE(nullptr, pyo.get());

auto Functor = CppBuilder<std::tuple<int, std::string>>();
EXPECT_THROW(Functor(pyo.get()), std::length_error);
EXPECT_FALSE(uncaught_exception());
}

/** vector **/

TEST(CppBuilder_vector, FromList)
Expand Down Expand Up @@ -605,6 +625,22 @@ TEST(CppBuilder_struct, FromTuple)
EXPECT_FALSE(uncaught_exception());
}

TEST(CppBuilder_struct, FromTooSmallTuple)
{
std::unique_ptr<PyObject, decref> pyo { PyRun_String("(1,)", Py_eval_input, py_dict, NULL) };
ASSERT_NE(nullptr, pyo.get());
EXPECT_THROW(Point::FromPy()(pyo.get()), std::length_error);
EXPECT_FALSE(uncaught_exception());
}

TEST(CppBuilder_struct, FromTooLargeTuple)
{
std::unique_ptr<PyObject, decref> pyo { PyRun_String("(1, 2, 3, 4)", Py_eval_input, py_dict, NULL) };
ASSERT_NE(nullptr, pyo.get());
EXPECT_THROW(Point::FromPy()(pyo.get()), std::length_error);
EXPECT_FALSE(uncaught_exception());
}

TEST(CppBuilder_struct, FromTupleArgs)
{
std::unique_ptr<PyObject, decref> pyo { PyRun_String("(1, 3, 4)", Py_eval_input, py_dict, NULL) };
Expand Down

0 comments on commit 6c8b8a7

Please sign in to comment.