aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libfsotest/fsotest/assert.vala43
-rw-r--r--libfsotest/fsotest/signalwaiter.vala29
2 files changed, 72 insertions, 0 deletions
diff --git a/libfsotest/fsotest/assert.vala b/libfsotest/fsotest/assert.vala
index 35eaff63..2fcb0bbc 100644
--- a/libfsotest/fsotest/assert.vala
+++ b/libfsotest/fsotest/assert.vala
@@ -59,6 +59,14 @@ namespace FsoFramework.Test
throw new AssertError.UNEXPECTED_VALUE( info + ( message.length > 0 ? @" : $(message)" : "" ) );
}
+ /**
+ * Check wether two values of type T are the same. If both values are different an
+ * exception of type AssertError is thrown.
+ *
+ * @param expected Expected value
+ * @param actual Actual value to compare with the expected one
+ * @param message Extra description message if both values are different
+ **/
public static void are_equal<T>( T expected, T actual, string message = "" ) throws AssertError
{
if ( expected != actual )
@@ -68,6 +76,14 @@ namespace FsoFramework.Test
}
}
+ /**
+ * Check wether two values of type T are not the same. If both values are the same an
+ * exception of type AssertError is thrown.
+ *
+ * @param not_expected Not expected value
+ * @param actual Actual value to compare with the not expected one
+ * @param message Extra description message if both values are not different
+ **/
public static void are_not_equal<T>( T not_expected, T actual, string message = "" ) throws AssertError
{
if ( not_expected == actual )
@@ -77,23 +93,50 @@ namespace FsoFramework.Test
}
}
+ /**
+ * Check wether a boolean value is true and throw an exception otherwise.
+ *
+ * @param actual Value to check if it's true or not
+ * @param message Text message to append to error message when assert failed
+ **/
public static void is_true( bool actual, string message = "" ) throws AssertError
{
if ( !actual )
throw_unexpected_value( "Supplied value is not true", message );
}
+ /**
+ * Check wether a boolean value is false and throw an exception otherwise.
+ *
+ * @param actual Value to check if it's false or not
+ * @param message Text message to append to error message when assert failed
+ **/
public static void is_false( bool actual, string message = "" ) throws AssertError
{
if ( actual )
throw_unexpected_value( "Supplied value is not false", message );
}
+ /**
+ * Let test execution fail regardless any condition.
+ *
+ * @param message Text to append to error message
+ **/
public static void fail( string message ) throws AssertError
{
throw new AssertError.UNEXPECTED_STATE( message );
}
+ /**
+ * Check wether an async operation throws a specific exception.
+ *
+ * @param fbegin Method to start execution of async operation
+ * @param ffinish Method to finish execution of async operation
+ * @param domain Error domain of the exception which should be thrown by the async
+ operation.
+ * @param message Text message to append to error message when specific exception
+ * is not thrown.
+ **/
public static void should_throw_async( AsyncBegin fbegin, AsyncFinish ffinish, string domain, string message = "" ) throws AssertError
{
try
diff --git a/libfsotest/fsotest/signalwaiter.vala b/libfsotest/fsotest/signalwaiter.vala
index d02cadf8..e407ca55 100644
--- a/libfsotest/fsotest/signalwaiter.vala
+++ b/libfsotest/fsotest/signalwaiter.vala
@@ -49,12 +49,31 @@ namespace FsoFramework.Test
public signal void triggered();
}
+ /**
+ * Wait for one or more signals to arrived when executing a operation which causes
+ * this signals to be triggered. The waiter will return a failure when a timeout is
+ * reached and no or not all signals has triggered.
+ *
+ * Example:
+ * var waiter = new MultiSignalWaiter();
+ * waiter.add_signal( emitter, "signal0" );
+ * var result = waiter.run( () => { triggerSignal0(); } );
+ **/
public class MultiSignalWaiter : GLib.Object
{
private GLib.List<SignalWrapper> signals = new GLib.List<SignalWrapper>();
private uint succeeded_count = 0;
private MainLoop mainloop;
+ /**
+ * Add a signal of an object called emitter to listen for until a timeout is
+ * reached.
+ *
+ * @param emitter Object which emits the signal
+ * @param signame Name of the signal
+ * @param timeout Timeout Specifies the maximum amount of time to wait for the
+ * signal to be triggerd.
+ **/
public void add_signal( Object emitter, string signame, int timeout = 200 )
{
var s = new SignalWrapper() { emitter = emitter, signame = signame, timeout = 200 };
@@ -66,6 +85,16 @@ namespace FsoFramework.Test
signals.append( s );
}
+ /**
+ * Run the code block which causes the added signals to be triggered. After block
+ * is executed and timeout is reached or all signals has arrived the result is
+ * returned to the caller.
+ *
+ * @param block Code block to execute
+ * @param timeout Timeout to wait before returning to caller
+ * @return True, if all signals has been triggered. False, if timeout is reached
+ * and not all signals has been triggered.
+ **/
public bool run( Block block, int timeout = 200 )
{
mainloop = new MainLoop(MainContext.default(), true);