[rygel] tests: Catch exceptions



commit a6ca57f46edd3b9ae1045d9cea8392626d56ef51
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Dec 6 14:00:38 2012 +0100

    tests: Catch exceptions

 tests/rygel-http-byte-seek-test.vala       |   11 ++++-
 tests/rygel-http-time-seek-test.vala       |    9 +++-
 tests/rygel-media-engine-test.vala         |   72 ++++++++++++++++++++++++---
 tests/rygel-searchable-container-test.vala |   32 ++++++++----
 tests/rygel-user-config-test.vala          |   48 +++++++++++++++---
 5 files changed, 143 insertions(+), 29 deletions(-)
---
diff --git a/tests/rygel-http-byte-seek-test.vala b/tests/rygel-http-byte-seek-test.vala
index b64e09a..b1e8ec9 100644
--- a/tests/rygel-http-byte-seek-test.vala
+++ b/tests/rygel-http-byte-seek-test.vala
@@ -111,8 +111,10 @@ private class Rygel.HTTPByteSeekTest : GLib.Object {
             var test = new HTTPByteSeekTest ();
 
             test.run ();
+	/* TODO: Nothing throws this exception. Should it?
         } catch (TestError.SKIP error) {
             return 77;
+        */
         } catch (Error error) {
             critical ("%s", error.message);
 
@@ -147,8 +149,13 @@ private class Rygel.HTTPByteSeekTest : GLib.Object {
     }
 
     private HTTPByteSeekTest () {
-        this.range_regex = new Regex ("bytes +[0-9]+-[0-9]+/[0-9]+",
-                                      RegexCompileFlags.CASELESS);
+        try {
+            this.range_regex = new Regex ("bytes +[0-9]+-[0-9]+/[0-9]+",
+                                          RegexCompileFlags.CASELESS);
+        } catch (RegexError error) {
+            // This means that it is not a regular expression
+            assert_not_reached ();
+        }
     }
 
     private void test_no_seek (Thumbnail? thumbnail,
diff --git a/tests/rygel-http-time-seek-test.vala b/tests/rygel-http-time-seek-test.vala
index c24c2ac..4ebaf3d 100644
--- a/tests/rygel-http-time-seek-test.vala
+++ b/tests/rygel-http-time-seek-test.vala
@@ -126,8 +126,10 @@ private class Rygel.HTTPTimeSeekTest : GLib.Object {
             var test = new HTTPTimeSeekTest ();
 
             test.run ();
+        /* TODO: Nothing throws this exception. Should it?
         } catch (TestError.SKIP error) {
             return 77;
+        */
         } catch (Error error) {
             critical ("%s", error.message);
 
@@ -163,7 +165,12 @@ private class Rygel.HTTPTimeSeekTest : GLib.Object {
                          "[0-9]+\\.[0-9][0-9][0-9]/" +
                          "[0-9]+\\.[0-9][0-9][0-9]";
 
-        this.range_regex = new Regex (expression, RegexCompileFlags.CASELESS);
+        try {
+            this.range_regex = new Regex (expression, RegexCompileFlags.CASELESS);
+        } catch (RegexError error) {
+            // This means that it is not a regular expression
+            assert_not_reached ();
+        }
     }
 
     private void test_no_seek (Thumbnail? thumbnail,
diff --git a/tests/rygel-media-engine-test.vala b/tests/rygel-media-engine-test.vala
index 6345a2a..2202f17 100644
--- a/tests/rygel-media-engine-test.vala
+++ b/tests/rygel-media-engine-test.vala
@@ -77,7 +77,13 @@ internal class Rygel.DataSourceTestConfig : Rygel.BaseConfiguration {
 internal class Rygel.ByteSeek : Rygel.HTTPSeek {
     public ByteSeek (int64 first, int64 last, int64 length) {
         var msg = new Soup.Message ("GET", "http://example.com/";);
-        base (msg, first, last, 1, length);
+
+        try {
+            base (msg, first, last, 1, length);
+        } catch (HTTPSeekError error) {
+            assert_not_reached ();
+        }
+
         this.seek_type = HTTPSeekType.BYTE;
     }
 
@@ -166,7 +172,17 @@ public class Rygel.DataSourceTest : Object {
         source.done.connect ( (data) => {
             loop.quit ();
         });
-        Idle.add ( () => { source.start (null); return false; });
+
+        
+        Idle.add ( () => {
+            try {
+                source.start (null);
+                return false;
+            } catch (GLib.Error error) {
+                assert_not_reached ();
+            }
+        });
+
         loop.run ();
         assert (received_bytes == this.test_data_mapped.get_length ());
         source.stop ();
@@ -281,10 +297,29 @@ public class Rygel.DataSourceTest : Object {
         source.done.connect ( (data) => {
             loop.quit ();
         });
-        Idle.add ( () => { source.start (null); return false; });
+
+        Idle.add ( () => {
+            try {
+                source.start (null);
+                return false;
+            } catch (GLib.Error error) {
+                assert_not_reached ();
+            }
+        });
+
+
         loop.run ();
         pool.clear ();
-        Idle.add ( () => { source.start (null); return false; });
+
+        Idle.add ( () => {
+            try {
+                source.start (null);
+                return false;
+            } catch (GLib.Error error) {
+                assert_not_reached ();
+            }
+        });
+
         loop.run ();
         Memory.cmp (this.test_data_mapped.get_contents (),
                     pool.flatten (),
@@ -305,7 +340,13 @@ public class Rygel.DataSourceTest : Object {
         var available_id = source.data_available.connect ( () => {
             assert_not_reached ();
         });
-        source.start (null);
+
+        try {
+            source.start (null);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
+
         source.freeze ();
         source.freeze ();
         var loop = new MainLoop (null, false);
@@ -343,7 +384,12 @@ public class Rygel.DataSourceTest : Object {
         // Sources should support file:// urls
         assert (source != null);
 
-        source.start (null);
+        try {
+            source.start (null);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
+
         source.freeze ();
         var loop = new MainLoop (null, false);
         source.done.connect ( () => {
@@ -370,13 +416,23 @@ public class Rygel.DataSourceTest : Object {
                                         (this.test_data_file.get_uri ());
         assert (source2 != null);
 
-        source1.start (null);
+        try {
+            source1.start (null);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
         var seek = new ByteSeek (0,
                                  (this.test_data_mapped.get_length () / 2),
                                  this.test_data_mapped.get_length ());
+        assert (seek != null);
+
+        try {
+            source2.start (null);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
-        source2.start (seek);
         var loop = new MainLoop (null, false);
         var quit = false;
         source1.done.connect ( () => {
diff --git a/tests/rygel-searchable-container-test.vala b/tests/rygel-searchable-container-test.vala
index f803c4c..767be40 100644
--- a/tests/rygel-searchable-container-test.vala
+++ b/tests/rygel-searchable-container-test.vala
@@ -67,21 +67,33 @@ public class TestContainer : MediaContainer, Rygel.SearchableContainer {
         Gee.ArrayList<string> ();}
 
     public async void test_search_no_limit () {
-        uint total_matches;
+        uint total_matches = 0;
 
         // check corners
-        var result = yield search (null, 0, 0, out total_matches, "", null);
-        assert (total_matches == 10);
-        assert (result.size == 10);
+        try {
+            var result = yield search (null, 0, 0, out total_matches, "", null);
+            assert (total_matches == 10);
+            assert (result.size == 10);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
-        result = yield search (null, 10, 0, out total_matches, "",  null);
-        assert (total_matches == 10);
-        assert (result.size == 0);
+        try {
+            var result = yield search (null, 10, 0, out total_matches, "",  null);
+            assert (total_matches == 10);
+            assert (result.size == 0);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
         for (int i = 1; i < 10; ++i) {
-            result = yield search (null, i, 0, out total_matches, "", null);
-            assert (total_matches == 10);
-            assert (result.size == 10 - i);
+            try {
+                var result = yield search (null, i, 0, out total_matches, "", null);
+                assert (total_matches == 10);
+                assert (result.size == 10 - i);
+            } catch (GLib.Error error) {
+                assert_not_reached ();
+            }
         }
 
         this.loop.quit ();
diff --git a/tests/rygel-user-config-test.vala b/tests/rygel-user-config-test.vala
index 3d84e74..cd84632 100644
--- a/tests/rygel-user-config-test.vala
+++ b/tests/rygel-user-config-test.vala
@@ -150,8 +150,12 @@ public class Rygel.UserConfigTest : GLib.Object {
         }
 
         public override void perform (string config) {
-            this.test.set_config (config,
+            try {
+                this.test.set_config (config,
                                   this.settings);
+            } catch (GLib.Error error) {
+                assert_not_reached ();
+            }
         }
     }
 
@@ -375,9 +379,19 @@ public class Rygel.UserConfigTest : GLib.Object {
 
     private void test_loading () {
         var remover = new ConfigRemover (this);
+        assert (remover != null);
+
+	try {
+            this.set_config (LOCAL_CONFIG);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
-        this.set_config (LOCAL_CONFIG);
-        this.set_config (SYSTEM_CONFIG);
+        try {
+            this.set_config (SYSTEM_CONFIG);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
         this.try_load (false);
         this.remove_config (LOCAL_CONFIG);
         this.try_load (false);
@@ -636,13 +650,31 @@ public class Rygel.UserConfigTest : GLib.Object {
 
     private void test_watching () {
         var remover = new ConfigRemover (this);
+        assert (remover != null);
         var full_settings = new Settings.default ();
+        assert (full_settings != null);
+
+        try {  
+            this.set_config (LOCAL_CONFIG,
+                             full_settings);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
+
+        try {
+            this.set_config (SYSTEM_CONFIG,
+                             full_settings);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
+
+        try {
+            this.config = new UserConfig.with_paths (LOCAL_CONFIG, SYSTEM_CONFIG);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
 
-        this.set_config (LOCAL_CONFIG,
-                         full_settings);
-        this.set_config (SYSTEM_CONFIG,
-                         full_settings);
-        this.config = new UserConfig.with_paths (LOCAL_CONFIG, SYSTEM_CONFIG);
+        assert (this.config != null);
         this.config.configuration_changed.connect
                                         (this.on_configuration_changed);
         this.config.section_changed.connect (this.on_section_changed);



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