Assamese translation updated
[profile/ivi/rygel.git] / tests / rygel-http-response-test.vala
index 64e0bf4..c56230b 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 using Soup;
-using Gst;
 
 public errordomain Rygel.TestError {
     SKIP = 77,
@@ -30,7 +29,7 @@ public errordomain Rygel.TestError {
 }
 
 public errordomain Rygel.HTTPRequestError {
-    NOT_FOUND = Soup.KnownStatusCode.NOT_FOUND
+    NOT_FOUND = Soup.Status.NOT_FOUND
 }
 
 public class Rygel.HTTPResponseTest : GLib.Object {
@@ -50,8 +49,6 @@ public class Rygel.HTTPResponseTest : GLib.Object {
     private Error error;
 
     public static int main (string[] args) {
-        Gst.init (ref args);
-
         try {
             var test = new HTTPResponseTest.complete ();
             test.run ();
@@ -242,7 +239,7 @@ public class Rygel.HTTPClient : GLib.Object, StateMachine {
 
         if (active) {
             this.cancellable = new Cancellable ();
-            this.cancellable.cancelled += this.on_cancelled;
+            this.cancellable.cancelled.connect (this.on_cancelled);
         }
     }
 
@@ -273,7 +270,7 @@ public class Rygel.HTTPClient : GLib.Object, StateMachine {
 
     private void on_cancelled (Cancellable cancellable) {
         this.context.session.cancel_message (this.msg,
-                                             KnownStatusCode.CANCELLED);
+                                             Status.CANCELLED);
         this.completed ();
     }
 }
@@ -326,7 +323,7 @@ public class Rygel.HTTPGet : GLib.Object {
         this.seek = seek;
         this.cancellable = cancellable;
         this.msg.response_headers.set_encoding (Soup.Encoding.EOF);
-        this.msg.set_status (Soup.KnownStatusCode.OK);
+        this.msg.set_status (Soup.Status.OK);
     }
 }
 
@@ -338,8 +335,63 @@ public class Rygel.HTTPGetHandler : GLib.Object {
     }
 }
 
+internal class Rygel.TestDataSource : Rygel.DataSource, Object {
+    private long block_size;
+    private long buffers;
+    private uint64 data_sent;
+    private bool frozen;
+
+    public TestDataSource (long block_size, long buffers) {
+        this.block_size = block_size;
+        this.buffers = buffers;
+        this.data_sent = 0;
+    }
+
+    public void start (HTTPSeek? seek) throws Error {
+        Idle.add ( () => {
+            if (frozen) {
+                return false;
+            }
+
+            var data = new uint8[block_size];
+            this.data_sent += block_size;
+            if (this.data_sent > HTTPResponseTest.MAX_BYTES) {
+                this.done ();
+
+                return false;
+            }
+
+            this.data_available (data);
+
+            return true;
+        });
+    }
+
+    public void freeze () {
+        this.frozen = true;
+    }
+
+    public void thaw () {
+        if (!this.frozen) {
+            return;
+        }
+
+        this.frozen = false;
+
+        try {
+            this.start (null);
+        } catch (GLib.Error error) {
+            assert_not_reached ();
+        }
+    }
+
+    public void stop () {
+        this.freeze ();
+    }
+}
+
 public class Rygel.MediaItem {
-    private static const long BLOCK_SIZE = HTTPResponseTest.MAX_BYTES / 16 + 1;
+    private static const long BLOCK_SIZE = HTTPResponseTest.MAX_BYTES / 16;
     private static const long MAX_BUFFERS = 25;
 
     public int64 size {
@@ -348,26 +400,23 @@ public class Rygel.MediaItem {
         }
     }
 
-    private dynamic Element src;
+    private DataSource src;
+    bool is_live = false;
 
     public MediaItem () {
-        this.src = GstUtils.create_element ("fakesrc", null);
-        this.src.sizetype = 2; // fixed
+        this.src = new TestDataSource (BLOCK_SIZE, MAX_BUFFERS);
+        this.is_live = true;
     }
 
     public MediaItem.fixed_size () {
         this ();
-
-        this.src.blocksize = BLOCK_SIZE;
-        this.src.num_buffers = MAX_BUFFERS;
-        this.src.sizemax = MAX_BUFFERS * BLOCK_SIZE;
     }
 
-    public Element? create_stream_source () {
+    public DataSource? create_stream_source () {
         return this.src;
     }
 
     public bool is_live_stream () {
-        return ((int) this.src.num_buffers) < 0;
+        return this.is_live;
     }
 }