void BindTransmitterTests::testCreateWithNullData() { CPPUNIT_ASSERT_THROW(new SMPP::BindTransmitter(NULL, 1), std::invalid_argument); }
void runToOsmTest() { // Great bit of code taken from TranslatedTagDifferencer.cpp shared_ptr<ScriptTranslator> st(ScriptTranslatorFactory::getInstance().createTranslator( "test-files/io/SampleTranslation.js")); shared_ptr<ScriptToOgrTranslator>uut = dynamic_pointer_cast<ScriptToOgrTranslator>(st); if (!uut) { throw HootException("Error allocating translator. the translation script must support " "converting to OGR."); } shared_ptr<const Schema> schema = uut->getOgrOutputSchema(); // JavaScriptTranslator::TranslatedFeature tf; ScriptToOgrTranslator::TranslatedFeature tf; QString layer; Tags t; t.clear(); t["building"] = "yes"; t["name"] = "foo"; tf = uut->translateToOgr(t, ElementType::Node, GEOS_POINT)[0]; HOOT_STR_EQUALS("PAL015", tf.tableName); HOOT_STR_EQUALS("[2]{(ARA, -999999), (NAM, foo)}", tf.feature->getValues()); t.clear(); t["building"] = "yes"; t["name"] = "foo"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_POLYGON)[0]; HOOT_STR_EQUALS("AAL015", tf.tableName); HOOT_STR_EQUALS("[2]{(ARA, 10), (NAM, foo)}", tf.feature->getValues()); t.clear(); t["highway"] = "track"; t["name"] = "bar"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING)[0]; HOOT_STR_EQUALS("LAP010", tf.tableName); HOOT_STR_EQUALS("[3]{(ARA, -999999), (NAM, bar), (PCF, 1)}", tf.feature->getValues()); t.clear(); t["highway"] = "road"; t["name"] = "bar"; tf = uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING)[0]; HOOT_STR_EQUALS("LAP030", tf.tableName); HOOT_STR_EQUALS("[4]{(ARA, -999999), (LTN, 2), (NAM, bar), (PCF, 2)}", tf.feature->getValues()); // throw an exception because the BAD field shouldn't be there. t.clear(); t["tableName"] = "PAL015"; t["NAM"] = "foo"; t["BAD"] = "tag"; t["ARA"] = "-999999"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because ARA can't be -1. t.clear(); t["tableName"] = "PAL015"; t["NAM"] = "foo"; t["ARA"] = "-1"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because the NAM field is missing. t.clear(); t["tableName"] = "PAL015"; t["ARA"] = "-999999"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Node, GEOS_POINT), FieldDefinition::InvalidValueException); // throw an exception because the PCF field has an invalid value. t.clear(); t["tableName"] = "LAP030"; t["ARA"] = "-999999"; t["NAM"] = "foo"; t["LTN"] = "2"; t["PCF"] = "3"; CPPUNIT_ASSERT_THROW(uut->translateToOgr(t, ElementType::Way, GEOS_LINESTRING), FieldDefinition::InvalidValueException); }
void ComponentTest::getPortForNonExistingThrowsError() { Component *comp = ComponentFactory::produce("", {"in"}, {}); CPPUNIT_ASSERT_THROW(comp->getPort("lala"), std::invalid_argument); ComponentFactory::dispose(comp); }
void SetInput_2DImage_ThrowsException() { CPPUNIT_ASSERT_THROW( m_oclBinaryFilter->SetInput( m_Random2DImage ), mitk::Exception ); }
void TestBishop::testOther() { CPPUNIT_ASSERT_THROW(board->movePiece(board->getSquare(0, 0), board->getSquare(2, 3)), invalid_move_error); }
void WrapperFactoryTest::testUnknown() { struct IntFactory { static int * timesOne(int * factor) { int * result = new int; *result = *factor * 1; return result; } static int * timesTwo(int * factor) { int * result = new int; *result = *factor * 2; return result; } static int * timesThree(int * factor) { int * result = new int; *result = *factor * 3; return result; } }; typedef std::function<int * (int *)> IntCreator; { Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::ExceptionFallback> factory; factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; int * productA = factory.create(3, &one); int * productB = factory.create(2, &two); int * productC = factory.create(1, &three); CPPUNIT_ASSERT(productA != nullptr); CPPUNIT_ASSERT(productB != nullptr); CPPUNIT_ASSERT(productC != nullptr); CPPUNIT_ASSERT_EQUAL(3, *productA); CPPUNIT_ASSERT_EQUAL(4, *productB); CPPUNIT_ASSERT_EQUAL(3, *productC); delete productC; delete productB; delete productA; typedef Util::FallbackPolicies::ExceptionFallback<int *, int>::Exception FactoryException; CPPUNIT_ASSERT_THROW(factory.create(0, &one), FactoryException); CPPUNIT_ASSERT_THROW(factory.create(4, &two), FactoryException); CPPUNIT_ASSERT_THROW(factory.create(17, &three), FactoryException); } { Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::NULLFallback> factory; factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(0, &one)); CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(4, &two)); CPPUNIT_ASSERT_EQUAL(static_cast<int *>(nullptr), factory.create(17, &three)); CPPUNIT_ASSERT_NO_THROW(factory.create(0, &one)); CPPUNIT_ASSERT_NO_THROW(factory.create(4, &two)); CPPUNIT_ASSERT_NO_THROW(factory.create(17, &three)); } { std::ostringstream outputStream; Util::FallbackPolicies::DefaultCreatorFallback<int *, int> fallback(2, outputStream); Util::WrapperFactory<int *, int *, int, IntCreator, Util::FallbackPolicies::DefaultCreatorFallback> factory(fallback); factory.registerType(1, IntFactory::timesOne); factory.registerType(2, IntFactory::timesTwo); factory.registerType(3, IntFactory::timesThree); int one = 1; int two = 2; int three = 3; int * productA = factory.create(0, &one); int * productB = factory.create(4, &two); int * productC = factory.create(17, &three); CPPUNIT_ASSERT(outputStream.good()); CPPUNIT_ASSERT(!outputStream.str().empty()); CPPUNIT_ASSERT(productA != nullptr); CPPUNIT_ASSERT(productB != nullptr); CPPUNIT_ASSERT(productC != nullptr); CPPUNIT_ASSERT_EQUAL(2, *productA); CPPUNIT_ASSERT_EQUAL(4, *productB); CPPUNIT_ASSERT_EQUAL(6, *productC); delete productC; delete productB; delete productA; } }
void TestBishop::testHorizontal() { CPPUNIT_ASSERT_THROW(board->movePiece(board->getSquare(0, 0), board->getSquare(0, 1)), invalid_move_error); }
void TestBishop::testVertical() { CPPUNIT_ASSERT_THROW(board->movePiece(board->getSquare(0, 0), board->getSquare(1, 0)), invalid_move_error); }
// (2)に相当するテスト void FractionTest::invalid_generation(void){ Fraction * fr; CPPUNIT_ASSERT_THROW(fr = new Fraction(6, 0), Fraction::DivisionByZeroException); delete fr; }
// (6)に相当するテスト void FractionTest::divide_fraction_by_0(void){ Fraction fr1(6, 4); Fraction fr5(0, 2); CPPUNIT_ASSERT_THROW(fr1 / fr5, Fraction::DivisionByZeroException); }
void TestH5::testBase() { CPPUNIT_ASSERT(h5group.isValid()); nix::hdf5::Group g_invalid{}; CPPUNIT_ASSERT_EQUAL(false, g_invalid.isValid()); CPPUNIT_ASSERT_THROW(g_invalid.check("Error"), nix::hdf5::H5Exception); // check check, heh CPPUNIT_ASSERT_THROW(check_h5_arg_name("foo/bar"), std::invalid_argument); // check HTri typedef nix::hdf5::HTri::value_type tri_type; nix::hdf5::HTri htri_true(static_cast<tri_type >(1)); nix::hdf5::HTri htri_false(static_cast<tri_type >(0)); nix::hdf5::HTri htri_error(static_cast<tri_type >(-1)); CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(1), htri_true.value); CPPUNIT_ASSERT_EQUAL(true, htri_true.result()); CPPUNIT_ASSERT_EQUAL(false, htri_true.isError()); CPPUNIT_ASSERT_EQUAL(false, !htri_true); CPPUNIT_ASSERT_EQUAL(true, htri_true.check("Error")); CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(0), htri_false.value); CPPUNIT_ASSERT_EQUAL(false, htri_false.result()); CPPUNIT_ASSERT_EQUAL(false, htri_false.isError()); CPPUNIT_ASSERT_EQUAL(true, !htri_false); CPPUNIT_ASSERT_EQUAL(false, htri_false.check("Error")); CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(-1), htri_error.value); CPPUNIT_ASSERT_EQUAL(false, htri_error.result()); CPPUNIT_ASSERT_EQUAL(true, htri_error.isError()); CPPUNIT_ASSERT_EQUAL(true, !htri_error); CPPUNIT_ASSERT_THROW(htri_error.check("Error"), nix::hdf5::H5Exception); // check HErr typedef nix::hdf5::HErr::value_type err_type; nix::hdf5::HErr herr_success(static_cast<err_type>(1)); nix::hdf5::HErr herr_fail(static_cast<err_type>(-1)); CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(1), herr_success.value); CPPUNIT_ASSERT_EQUAL(false, herr_success.isError()); CPPUNIT_ASSERT_EQUAL(false, !herr_success); CPPUNIT_ASSERT_EQUAL(true, herr_success.check("Error")); CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(-1), herr_fail.value); CPPUNIT_ASSERT_EQUAL(true, herr_fail.isError()); CPPUNIT_ASSERT_EQUAL(true, !herr_fail); CPPUNIT_ASSERT_THROW(herr_fail.check("Error"), nix::hdf5::H5Error); nix::hdf5::HErr herr_default; CPPUNIT_ASSERT_EQUAL(true, herr_default.isError()); //check BaseHDF5 hid_t gcpl = H5Pcreate(H5P_GROUP_CREATE); hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE); CPPUNIT_ASSERT(gcpl > 0); CPPUNIT_ASSERT(dcpl > 0); test_refcounting<nix::hdf5::BaseHDF5>(gcpl, dcpl); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gcpl)); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(dcpl)); //ref counting hid_t ga = H5Gopen(h5file, "/", H5P_DEFAULT); hid_t gb = H5Gopen(h5file, "/h5", H5P_DEFAULT); CPPUNIT_ASSERT(ga > 0); CPPUNIT_ASSERT(gb > 0); test_refcounting<nix::hdf5::BaseHDF5>(ga, gb); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(ga)); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gb)); test_refcounting<nix::hdf5::LocID>(ga, gb); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(ga)); CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gb)); H5Gclose(ga); H5Gclose(gb); //name() std::string name = h5group.name(); CPPUNIT_ASSERT_EQUAL(std::string("/h5"), name); CPPUNIT_ASSERT_EQUAL(std::string{}, g_invalid.name()); //FIXME: this should be somewhere lese size_t sz_a = 10; CPPUNIT_ASSERT_EQUAL(sz_a, nix::check::fits_in_size_t(sz_a, "OOB")); //this is a bit of a hack to get a size that will be bigger then //size_t's max value on 64bit systems double sz_b = static_cast<double>(std::numeric_limits<size_t>::max()) * 2.0; CPPUNIT_ASSERT_THROW(nix::check::fits_in_size_t(sz_b, "OOB"), nix::OutOfBounds); }
void COctetStringTests::testCreateWithNullDataBuffer() { const unsigned char* data = NULL; CPPUNIT_ASSERT_THROW(SMPP::CString(data, 1), std::invalid_argument); }
void TestSaveEmptyData() { mitk::Surface::Pointer data = mitk::Surface::New(); CPPUNIT_ASSERT_THROW(mitk::IOUtil::Save(data, "/tmp/dummy"), mitk::Exception); }
void MatrixWrapperTest::testAtWrongType() { MatrixImpl matrix(3, 2, Matrix::INT_32); CPPUNIT_ASSERT_THROW(matrix.at<int8_t>(0, 1) = 42, WrongArgument); }
void UnitTestOutputLog::testUnit() { // Make cout and cerr available as log stream targets. stk::register_log_ostream(std::cout, "cout"); stk::register_log_ostream(std::cerr, "cerr"); // Test registration, binding, rebinding and unregistration { std::ostringstream log1; std::ostringstream log2; std::ostream out(std::cout.rdbuf()); stk::register_ostream(out, "out"); CPPUNIT_ASSERT(stk::is_registered_ostream("out")); stk::register_log_ostream(log1, "log1"); stk::register_log_ostream(log2, "log2"); stk::bind_output_streams("out>log1"); out << "stk::bind_output_streams(\"out>log1\");" << std::endl; stk::bind_output_streams("out>+log2"); out << "stk::bind_output_streams(\"out>+log2\");" << std::endl; stk::bind_output_streams("out>-log1"); out << "stk::bind_output_streams(\"out>-log1\");" << std::endl; stk::bind_output_streams("out>-log2"); out << "stk::bind_output_streams(\"out>-log2\");" << std::endl; std::ostringstream log1_result; log1_result << "stk::bind_output_streams(\"out>log1\");" << std::endl << "stk::bind_output_streams(\"out>+log2\");" << std::endl; std::ostringstream log2_result; log2_result << "stk::bind_output_streams(\"out>+log2\");" << std::endl << "stk::bind_output_streams(\"out>-log1\");" << std::endl; CPPUNIT_ASSERT_EQUAL(log1_result.str(), log1.str()); CPPUNIT_ASSERT_EQUAL(log2_result.str(), log2.str()); stk::unregister_log_ostream(log1); stk::unregister_log_ostream(log2); stk::unregister_ostream(out); CPPUNIT_ASSERT_EQUAL(out.rdbuf(), std::cout.rdbuf()); } // Test logging to a file { std::ostream out(std::cout.rdbuf()); stk::register_ostream(out, "out"); stk::bind_output_streams("log=\"logfile\" out>log"); CPPUNIT_ASSERT_EQUAL(std::string("logfile"), stk::get_log_path("log")); out << "This is a test" << std::endl; stk::bind_output_streams("log=\"\""); stk::unregister_ostream(out); std::ostringstream log_result; log_result << "This is a test"; std::ifstream log_stream("logfile"); std::string log_string; getline(log_stream, log_string); CPPUNIT_ASSERT_EQUAL(log_result.str(), log_string); } // Test results of unregistration of an output stream bound as a log stream { std::ostringstream default_log; std::ostream out(default_log.rdbuf()); std::ostream pout(std::cout.rdbuf()); stk::register_ostream(out, "out"); stk::register_ostream(pout, "pout"); // Constructing the log streams after the registered output stream is not exception safe. std::ostringstream log; stk::register_log_ostream(log, "log"); // As a result, this try catch block must be represent to ensure the that unregistration // happens correctly. try { stk::bind_output_streams("out>pout pout>log"); out << "This is to out" << std::endl; pout << "This is to pout" << std::endl; std::ostringstream log_result; log_result << "This is to out" << std::endl << "This is to pout" << std::endl; CPPUNIT_ASSERT_EQUAL(log_result.str(), log.str()); throw std::exception(); } catch (...) { } stk::unregister_log_ostream(log); stk::unregister_ostream(pout); stk::unregister_ostream(out); out << "This is to out" << std::endl; std::ostringstream log_result; log_result << "This is to out" << std::endl; CPPUNIT_ASSERT_EQUAL(log_result.str(), default_log.str()); } // Test exception of registration with existing name { std::ostringstream log1; std::ostringstream log2; std::ostream out(std::cout.rdbuf()); std::ostream pout(std::cout.rdbuf()); stk::register_ostream(out, "out"); CPPUNIT_ASSERT_THROW(stk::register_ostream(pout, "out"), std::runtime_error); CPPUNIT_ASSERT_EQUAL(&out, stk::get_ostream_ostream("out")); stk::register_log_ostream(log1, "log"); CPPUNIT_ASSERT_THROW(stk::register_log_ostream(log2, "log"), std::runtime_error); CPPUNIT_ASSERT_THROW(stk::bind_output_streams("badout>log"), std::runtime_error); CPPUNIT_ASSERT_THROW(stk::bind_output_streams("out>badlog"), std::runtime_error); stk::unregister_log_ostream(log1); stk::unregister_ostream(out); } }