From 03d92f51588c1cd45178321a86cb3aacb80a0f33 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 19 Apr 2007 23:12:35 +0000 Subject: [PATCH] improve mupa comment character parsing ticket:261 It also makes sure that load_mupa throws an exception when it loads a file it doesn't understand. I wonder if the GUI knows to catch this? --- alg/mussa.cpp | 8 +++++++- alg/test/test_mussa.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 9a5935e..2fb639b 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -381,6 +381,7 @@ Mussa::load_mupa_file(fs::path para_file_path) void Mussa::load_mupa_stream(std::istream& para_file, fs::path& file_path_base) { + bool error_occured = false; string file_data_line; string param, value; fs::path annot_file; @@ -454,11 +455,13 @@ Mussa::load_mupa_stream(std::istream& para_file, fs::path& file_path_base) did_seq = true; } //ignore empty lines or that start with '#' - else if ((param == "") || (param == "#")) {} + else if ( (param.size() == 0) || (param[0] == '#')) + {} // pass else { clog << "Illegal/misplaced mussa parameter in file\n"; clog << param << "\n"; + error_occured = true; } if (!did_seq) @@ -471,6 +474,9 @@ Mussa::load_mupa_stream(std::istream& para_file, fs::path& file_path_base) } } + if (error_occured) { + throw mussa_load_error("Error parsing MUPA file"); + } soft_thres = threshold; // no file was loaded, signal error set_dirty(true); diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index e1cef22..9f11a5e 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -129,6 +129,39 @@ BOOST_AUTO_TEST_CASE( mussa_load_mupa_crlf ) // Should run with no exceptions } +BOOST_AUTO_TEST_CASE( mussa_load_mupa_comment_character ) +{ + fs::path mupa_path(EXAMPLE_DIR, fs::native); + fs::path seq_path = fs::initial_path() / "seq" / "mouse_mck_pro.fa"; + fs::path annot_path = fs::initial_path() / "mm_mck3test.annot"; + + std::string mupa( + "# hello\015\012" + "ANA_NAME load_mupa_crlf\015\012"); + mupa += "#SEQUENCE " + seq_path.native_file_string() + "\015\012"; + mupa += "#ANNOTATION " + annot_path.native_file_string() + "\015\012"; + + istringstream mupa_stream(mupa); + Mussa m; + fs::path base; + m.load_mupa_stream( mupa_stream, base ); + // Should run with no exceptions +} + +BOOST_AUTO_TEST_CASE( mussa_load_mupa_exception ) +{ + std::string mupa( + "# hello\015\012" + "ANA_NAME load_mupa_crlf\015\012" + "mwahhaha I broke you!\n" + ); + + istringstream mupa_stream(mupa); + Mussa m; + fs::path base; + BOOST_CHECK_THROW(m.load_mupa_stream( mupa_stream, base ), mussa_load_error); +} + BOOST_AUTO_TEST_CASE( mussa_load_mupa ) { fs::path mupa_path(EXAMPLE_DIR, fs::native); -- 2.30.2