[nemiver/varobjs-support] Add regression test for watchpoints



commit 1b3936390c53f6cf11fee12bf092ba7d789b5ce1
Author: Dodji Seketeli <dodji redhat com>
Date:   Thu May 21 18:31:07 2009 +0200

    Add regression test for watchpoints
    
    	* tests/test-watchpoint.cc: New test.
    	* tests/Makefile.am: Integrate the new test to the build system.
---
 tests/Makefile.am        |    6 ++-
 tests/test-watchpoint.cc |  124 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 363e795..faa6766 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,7 @@ TESTS=\
 runtestgdbmi runtestunicode \
 runtestvars runtestcpptrait runtestvarlist \
 runtestvarwalker runtestbreakpoint \
-runtestderef \
+runtestwatchpoint runtestderef \
 runtestlocalvarslist runtestcpplexer \
 runtestcppparser  \
 runtestlibtoolwrapperdetection \
@@ -48,6 +48,10 @@ runtestbreakpoint_SOURCES=test-breakpoint.cc
 runtestbreakpoint_LDADD= NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la
 
+runtestwatchpoint_SOURCES=test-watchpoint.cc
+runtestwatchpoint_LDADD= NEMIVERCOMMON_LIBS@ \
+$(top_builddir)/src/common/libnemivercommon.la
+
 #runtestoverloads_SOURCES=test-overloads.cc
 #runtestoverloads_LDADD= NEMIVERCOMMON_LIBS@ @BOOST_TEST_EXEC_MONITOR_LIB@ \
 #$(top_builddir)/src/common/libnemivercommon.la
diff --git a/tests/test-watchpoint.cc b/tests/test-watchpoint.cc
new file mode 100644
index 0000000..3b46859
--- /dev/null
+++ b/tests/test-watchpoint.cc
@@ -0,0 +1,124 @@
+#include <iostream>
+#include <boost/test/minimal.hpp>
+#include <glibmm.h>
+#include "common/nmv-initializer.h"
+#include "common/nmv-safe-ptr-utils.h"
+#include "nmv-i-debugger.h"
+
+#ifdef WITH_VAROBJS
+
+using namespace nemiver;
+using namespace nemiver::common ;
+
+Glib::RefPtr<Glib::MainLoop> loop =
+    Glib::MainLoop::create (Glib::MainContext::get_default ());
+
+static int nb_watchpoint_trigger;
+static int nb_watchpoint_out_of_scope;
+
+void
+on_engine_died_signal ()
+{
+    MESSAGE ("engine died");
+    loop->quit () ;
+}
+
+void
+on_program_finished_signal ()
+{
+    MESSAGE ("program finished");
+    loop->quit ();
+}
+
+void
+on_breakpoints_set_signal (const std::map<int, IDebugger::BreakPoint> &a_breaks,
+                           const UString &a_cookie)
+{
+    if (a_cookie.empty ()) {}
+
+    MESSAGE ("breakpoints set:");
+    std::map<int, IDebugger::BreakPoint>::const_iterator it;
+    for (it = a_breaks.begin () ; it != a_breaks.end () ; ++it) {
+        MESSAGE ("<break><num>" << it->first <<"</num><line>"
+                 << it->second.file_name () << ":" << it->second.line ()
+                 << "</line></break>");
+    }
+}
+
+void
+on_stopped_signal (IDebugger::StopReason a_reason,
+                   bool a_has_frame,
+                   const IDebugger::Frame &a_frame,
+                   int /*a_thread_id*/,
+                   int /*a_bp_num*/,
+                   const UString &/*a_cookie*/,
+                   IDebuggerSafePtr &a_debugger)
+{
+    MESSAGE ("stopped in: "
+             << a_frame.function_name ());
+
+    if (a_reason == IDebugger::BREAKPOINT_HIT
+        && a_has_frame
+        && a_frame.function_name () == "func1") {
+        a_debugger->set_watchpoint ("i");
+    }
+    if (a_reason == IDebugger::WATCHPOINT_TRIGGER) {
+        MESSAGE ("watchpoint triggered");
+        ++nb_watchpoint_trigger;
+    }
+    if (a_reason == IDebugger::WATCHPOINT_SCOPE) {
+        MESSAGE ("watchpoint gone out of scope");
+        ++nb_watchpoint_out_of_scope;
+    }
+    a_debugger->do_continue ();
+}
+
+NEMIVER_API int
+test_main (int, char **)
+{
+    NEMIVER_TRY
+
+    Initializer::do_init ();
+
+    THROW_IF_FAIL (loop);
+
+    DynamicModuleManager module_manager;
+    IDebuggerSafePtr debugger =
+        module_manager.load_iface<IDebugger> ("gdbengine", "IDebugger");
+
+    debugger->set_event_loop_context (loop->get_context ());
+
+    //*****************************
+    //<connect to IDebugger events>
+    //*****************************
+    debugger->engine_died_signal ().connect (&on_engine_died_signal);
+
+    debugger->program_finished_signal ().connect
+                                            (&on_program_finished_signal);
+
+    debugger->breakpoints_set_signal ().connect
+                                            (&on_breakpoints_set_signal);
+
+    debugger->stopped_signal ().connect
+                            (sigc::bind (&on_stopped_signal, debugger));
+
+    std::vector<UString> args, source_search_dir;
+    args.push_back ("fooprog") ;
+    source_search_dir.push_back (".");
+
+    debugger->load_program (args, "", source_search_dir);
+    debugger->set_breakpoint ("main");
+    debugger->set_breakpoint ("func1");
+    debugger->run ();
+
+    loop->run () ;
+
+    NEMIVER_CATCH_NOX
+
+    BOOST_REQUIRE (nb_watchpoint_trigger == 1);
+    BOOST_REQUIRE (nb_watchpoint_out_of_scope == 1);
+    return 0;
+}
+
+#endif //WITH_VAROBJS
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]