~ubuntu-branches/ubuntu/trusty/rygel/trusty

« back to all changes in this revision

Viewing changes to tests/rygel-http-time-seek-test.vala

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2011-12-16 15:21:25 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111216152125-qgn31dkfmhouhrf0
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        this.add_headers (start, stop);
88
88
    }
89
89
 
 
90
    public HTTPGet.seek_strings (string     start,
 
91
                                 string     stop,
 
92
                                 Thumbnail? thumbnail,
 
93
                                 Subtitle?  subtitle) {
 
94
        this (thumbnail, subtitle);
 
95
 
 
96
        this.add_string_headers (start, stop);
 
97
    }
 
98
 
90
99
    private void add_headers (int64 start, int64 stop) requires (start >= 0) {
91
100
        var stop_str = (stop > 0)? stop.to_string (): "";
92
101
        var range = "npt=" + start.to_string () + "-" + stop_str;
93
102
        this.msg.request_headers.append ("TimeSeekRange.dlna.org", range);
94
103
    }
 
104
 
 
105
    private void add_string_headers (string start, string stop) {
 
106
        var range = "npt=" + start + "-" + stop;
 
107
        this.msg.request_headers.append ("TimeSeekRange.dlna.org", range);
 
108
    }
95
109
}
96
110
 
97
111
private class Rygel.HTTPTimeSeekTest : GLib.Object {
98
112
    private Regex range_regex;
99
113
 
 
114
    enum TestType {
 
115
        TEST_SECONDS_PARSING,
 
116
        TEST_HHMMSS_PARSING,
 
117
        TEST_MIXED_PARSING
 
118
    }
 
119
    private TestType test_type;
 
120
 
100
121
    public static int main (string[] args) {
101
122
        try {
102
123
            var test = new HTTPTimeSeekTest ();
119
140
 
120
141
        foreach (var thumbnail in thumbnails) {
121
142
            foreach (var subtitle in subtitles) {
 
143
                this.test_type = TestType.TEST_SECONDS_PARSING;
122
144
                this.test_no_seek (thumbnail, subtitle);
123
145
                this.test_start_only_seek (thumbnail, subtitle);
124
146
                this.test_stop_only_seek (thumbnail, subtitle);
125
147
                this.test_start_stop_seek (thumbnail, subtitle);
 
148
                this.test_type = TestType.TEST_HHMMSS_PARSING;
 
149
                this.test_start_only_seek (thumbnail, subtitle);
 
150
                this.test_stop_only_seek (thumbnail, subtitle);
 
151
                this.test_start_stop_seek (thumbnail, subtitle);
 
152
                this.test_type = TestType.TEST_MIXED_PARSING;
 
153
                this.test_start_stop_seek (thumbnail, subtitle);
126
154
            }
127
155
        }
128
156
    }
131
159
        var expression = "npt=[0-9]+\\.[0-9][0-9][0-9]-" +
132
160
                         "[0-9]+\\.[0-9][0-9][0-9]/" +
133
161
                         "[0-9]+\\.[0-9][0-9][0-9]";
 
162
 
134
163
        this.range_regex = new Regex (expression, RegexCompileFlags.CASELESS);
135
164
    }
136
165
 
138
167
                               Subtitle?  subtitle) throws HTTPSeekError {
139
168
        var request = new HTTPGet (thumbnail, subtitle);
140
169
        var audio_item = request.item as AudioItem;
141
 
 
142
170
        this.test_seek (request, 0, audio_item.duration * SECOND - MSECOND);
143
171
    }
144
172
 
145
173
    private void test_start_only_seek (Thumbnail? thumbnail,
146
174
                                       Subtitle?  subtitle)
147
175
                                       throws HTTPSeekError {
148
 
        var request = new HTTPGet.seek_start (128, thumbnail, subtitle);
 
176
        HTTPGet request = null;
 
177
 
 
178
        switch (this.test_type) {
 
179
        case TestType.TEST_SECONDS_PARSING:
 
180
            request = new HTTPGet.seek_start (128, thumbnail, subtitle);
 
181
 
 
182
            break;
 
183
 
 
184
        case TestType.TEST_HHMMSS_PARSING:
 
185
            request = new HTTPGet.seek_strings ("00:02:08.000", "", thumbnail, subtitle);
 
186
 
 
187
            break;
 
188
        }
 
189
 
149
190
        var audio_item = request.item as AudioItem;
150
 
 
151
191
        this.test_seek (request,
152
192
                        128 * SECOND,
153
193
                        audio_item.duration * SECOND - MSECOND);
156
196
    private void test_stop_only_seek (Thumbnail? thumbnail,
157
197
                                      Subtitle?  subtitle)
158
198
                                      throws HTTPSeekError {
159
 
        var request = new HTTPGet.seek_stop (128, thumbnail, subtitle);
 
199
        HTTPGet request = null;
 
200
 
 
201
        switch (this.test_type) {
 
202
        case TestType.TEST_SECONDS_PARSING:
 
203
            request = new HTTPGet.seek_stop (128, thumbnail, subtitle);
 
204
 
 
205
            break;
 
206
 
 
207
        case TestType.TEST_HHMMSS_PARSING:
 
208
            request = new HTTPGet.seek_strings ("00:00:00.000",
 
209
                                                "00:02:08.000",
 
210
                                                thumbnail,
 
211
                                                subtitle);
 
212
 
 
213
            break;
 
214
        }
160
215
 
161
216
        this.test_seek (request, 0, 128 * SECOND);
162
217
    }
164
219
    private void test_start_stop_seek (Thumbnail? thumbnail,
165
220
                                       Subtitle?  subtitle)
166
221
                                       throws HTTPSeekError {
167
 
        var request = new HTTPGet.seek_start_stop (128,
 
222
        HTTPGet request = null;
 
223
 
 
224
        switch (this.test_type) {
 
225
        case TestType.TEST_SECONDS_PARSING:
 
226
            request = new HTTPGet.seek_start_stop (128,
168
227
                                                   256,
169
228
                                                   thumbnail,
170
229
                                                   subtitle);
171
230
 
 
231
            break;
 
232
 
 
233
        case TestType.TEST_HHMMSS_PARSING:
 
234
            request = new HTTPGet.seek_strings ("00:02:08.000",
 
235
                                                "00:04:16.000",
 
236
                                                thumbnail,
 
237
                                                subtitle);
 
238
 
 
239
            break;
 
240
 
 
241
        case TestType.TEST_MIXED_PARSING:
 
242
            request = new HTTPGet.seek_strings ("00:02:08.000",
 
243
                                                "256.000",
 
244
                                                thumbnail,
 
245
                                                subtitle);
 
246
 
 
247
            break;
 
248
        }
 
249
 
 
250
 
172
251
        this.test_seek (request, 128 * SECOND, 256 * SECOND);
173
252
    }
174
253