updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 7 Nov 2006 16:45:37 +0000 (16:45 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 7 Nov 2006 16:45:37 +0000 (16:45 +0000)
CHANGES
lib/silcutil/tests/test_silcfsm.c
lib/silcutil/tests/test_silcstrutil.c

diff --git a/CHANGES b/CHANGES
index aef4df9013f5c62df86a27d692e09e4bcf015aef..0b08f2a5e39219fb26757a095d5b26636fbc1c3e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Tue Nov  7 18:04:36 EET 2006  Pekka Riikonen <priikone@silcnet.org
+
+       * Added silc_string_split to lib/silcutil/silcstrutil.[ch].
+
+       * Added silc_mutex_assert_locked to lib/silcutil/silcmutex.h.
+
+       * silc_fsm_continue[_sync] now cancels erlier timeout set with
+         silc_fsm_next_later.  Affected file lib/silcutil/silcfsm.c.
+
 Sat Nov  4 21:50:37 EET 2006  Pekka Riikonen <priikone@silcnet.org
 
        * Added SILC_STR_FUNC to buffer format API.  Affected files
index 1a48aed15c021a57484bc4894441d6b7df0ab075..df11891ba2bb90c1b817355a51340a9c8fc96dcf 100644 (file)
@@ -28,10 +28,12 @@ struct FooStruct {
   void *cb_context;
   T threads[NUM_THREADS];
   T threads2[NUM_THREADS];
+  int c;
 };
 
 SILC_FSM_STATE(test_st_start);
 SILC_FSM_STATE(test_st_second);
+SILC_FSM_STATE(test_st_second_timeout);
 SILC_FSM_STATE(test_st_third);
 SILC_FSM_STATE(test_st_fourth);
 SILC_FSM_STATE(test_st_fifth);
@@ -80,9 +82,35 @@ SILC_FSM_STATE(test_st_second)
 {
   SILC_LOG_DEBUG(("test_st_second"));
 
-  /** Move to third state, timeout */
+  /** Move to second timeout state, timeout */
   SILC_LOG_DEBUG(("Move to next state with 2 second timeout"));
-  silc_fsm_next_later(fsm, test_st_third, 2, 0);
+  silc_fsm_next_later(fsm, test_st_second_timeout, 2, 0);
+  return SILC_FSM_WAIT;
+}
+
+SILC_TASK_CALLBACK(test_second_timeout)
+{
+  Foo f = context;
+  SILC_LOG_DEBUG(("test_second_timeout"));
+
+  SILC_LOG_DEBUG(("Interrupt 3 second wait and continue immediately"));
+  f->c++;
+  silc_fsm_next(f->fsm, test_st_third);
+  silc_fsm_continue(f->fsm);
+}
+
+SILC_FSM_STATE(test_st_second_timeout)
+{
+  Foo f = fsm_context;
+
+  SILC_LOG_DEBUG(("test_st_second_timeout"));
+
+  /** Move to third state, timeout */
+  SILC_LOG_DEBUG(("Move to next state with 3 second timeout"));
+  SILC_LOG_DEBUG(("The timeout will be interrupted with silc_fsm_continue"));
+  silc_fsm_next_later(fsm, test_st_third, 3, 0);
+  silc_schedule_task_add_timeout(silc_fsm_get_schedule(fsm),
+                                test_second_timeout, f, 2, 500000);
   return SILC_FSM_WAIT;
 }
 
@@ -99,6 +127,9 @@ SILC_FSM_STATE(test_st_third)
 
   SILC_LOG_DEBUG(("test_st_third"));
 
+  f->c++;
+  assert(f->c == 2);
+
   f->fsm = fsm;
 
   /** Wait async callback*/
@@ -364,7 +395,7 @@ int main(int argc, char **argv)
   f->schedule = schedule;
 
   SILC_LOG_DEBUG(("Allocating FSM context"));
-  fsm = silc_fsm_alloc(f, destructor, f, schedule);
+  f->fsm = fsm = silc_fsm_alloc(f, destructor, f, schedule);
   if (!fsm)
     goto err;
   silc_fsm_start(fsm, test_st_start);
index 343ab714fc9e93048561f2134c59ae8f55385ff3..0673199e3d328ae73af37d86f4c9325976872176 100644 (file)
@@ -1,4 +1,5 @@
 /* UTF-8 decoding tests */
+/* Other string util tests too */
 
 #include "silc.h"
 
@@ -149,6 +150,18 @@ int main(int argc, char **argv)
   silc_free(s3);
   silc_free(s4);
 
+  /* Regex test */
+  SILC_LOG_DEBUG(("Simple regex test"));
+  s1 = "foo,bar,silc,com";
+  SILC_LOG_DEBUG(("Find 'silc' from %s", s1));
+  if (!silc_string_match(s1, "silc"))
+    goto err;
+  SILC_LOG_DEBUG(("Regex match"));
+  SILC_LOG_DEBUG(("Find 'foobar' from %s", s1));
+  if (silc_string_match(s1, "foobar"))
+    goto err;
+  SILC_LOG_DEBUG(("Regex not found (Ok)"));
+
   success = TRUE;
 
  err: