Merge lp:~mandel/ubuntu-download-manager/update-go-bindings into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 295
Proposed branch: lp:~mandel/ubuntu-download-manager/update-go-bindings
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/filter-all-per-app
Diff against target: 875 lines (+583/-67)
4 files modified
bindings/golang/common.go (+78/-0)
bindings/golang/common_test.go (+83/-0)
bindings/golang/downloader.go (+116/-67)
bindings/golang/downloader_test.go (+306/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/update-go-bindings
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Sergio Schvezov Needs Fixing
Ubuntu One hackers Pending
Review via email: mp+217255@code.launchpad.net

Commit message

Add the SetLocationDir method that was missing from the golang API. Add missing tests to ensure the correct use of dbus.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

433 + . "gopkg.in/check.v1"

just use the real name, it's packaged as such in the archives.

review: Needs Fixing
259. By Manuel de la Peña

Merged filter-all-per-app into update-go-bindings.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
260. By Manuel de la Peña

Merged filter-all-per-app into update-go-bindings.

261. By Manuel de la Peña

Merged filter-all-per-app into update-go-bindings.

262. By Manuel de la Peña

Reduce the diff in the following branches by making the generalized moves in this branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
263. By Manuel de la Peña

Merged filter-all-per-app into update-go-bindings.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
264. By Manuel de la Peña

Fix criss-cross issues.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bindings/golang/common.go'
2--- bindings/golang/common.go 1970-01-01 00:00:00 +0000
3+++ bindings/golang/common.go 2014-05-09 08:51:26 +0000
4@@ -0,0 +1,78 @@
5+/*
6+ * Copyright 2014 Canonical Ltd.
7+ *
8+ * Authors:
9+ * Manuel de la Pena: manuel.delapena@canonical.com
10+ *
11+ * This file is part of ubuntu-download-manager.
12+ *
13+ * ubuntu-download-manager is free software; you can redistribute it and/or modify
14+ * it under the terms of the GNU General Public License as published by
15+ * the Free Software Foundation; version 3.
16+ *
17+ * ubuntu-download-manager is distributed in the hope that it will be useful,
18+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+ * GNU General Public License for more details.
21+ *
22+ * You should have received a copy of the GNU General Public License
23+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
24+ */
25+
26+// Package udm provides a go interface to work with the ubuntu download manager
27+package udm
28+
29+import (
30+ "launchpad.net/go-dbus/v1"
31+)
32+
33+// Progress provides how much progress has been performed in a download that was
34+// already started.
35+type Progress struct {
36+ Received uint64
37+ Total uint64
38+}
39+
40+// internal interface used to simplify testing
41+type watch interface {
42+ Cancel() error
43+ Chanel() chan *dbus.Message
44+}
45+
46+// small wrapper used to simplify testing by using the watch interface
47+type watchWrapper struct {
48+ watch *dbus.SignalWatch
49+}
50+
51+func newWatchWrapper(sw *dbus.SignalWatch) *watchWrapper {
52+ w := watchWrapper{}
53+ return &w
54+}
55+
56+func (w *watchWrapper) Cancel() error {
57+ return w.watch.Cancel()
58+}
59+
60+func (w *watchWrapper) Chanel() chan *dbus.Message {
61+ return w.watch.C
62+}
63+
64+// interface added to simplify testing
65+type proxy interface {
66+ Call(iface, method string, args ...interface{}) (*dbus.Message, error)
67+}
68+
69+var readArgs = func(msg *dbus.Message, args ...interface{}) error {
70+ return msg.Args(args)
71+}
72+
73+func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (watch, error) {
74+ sw, err := conn.WatchSignal(&dbus.MatchRule{
75+ Type: dbus.TypeSignal,
76+ Sender: DOWNLOAD_SERVICE,
77+ Interface: DOWNLOAD_INTERFACE,
78+ Member: signal,
79+ Path: path})
80+ w := newWatchWrapper(sw)
81+ return w, err
82+}
83
84=== added file 'bindings/golang/common_test.go'
85--- bindings/golang/common_test.go 1970-01-01 00:00:00 +0000
86+++ bindings/golang/common_test.go 2014-05-09 08:51:26 +0000
87@@ -0,0 +1,83 @@
88+/*
89+ * Copyright 2014 Canonical Ltd.
90+ *
91+ * Authors:
92+ * Manuel de la Pena: manuel.delapena@canonical.com
93+ *
94+ * This file is part of ubuntu-download-manager.
95+ *
96+ * ubuntu-download-manager is free software; you can redistribute it and/or modify
97+ * it under the terms of the GNU General Public License as published by
98+ * the Free Software Foundation; version 3.
99+ *
100+ * ubuntu-download-manager is distributed in the hope that it will be useful,
101+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
102+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103+ * GNU General Public License for more details.
104+ *
105+ * You should have received a copy of the GNU General Public License
106+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
107+ */
108+
109+package udm
110+
111+import (
112+ . "gopkg.in/check.v1"
113+ "launchpad.net/go-dbus/v1"
114+ "testing"
115+)
116+
117+func Test(t *testing.T) { TestingT(t) }
118+
119+type fakeProxy struct {
120+ Interface string
121+ MethodName string
122+ Args []interface{}
123+ Err error
124+ Result *dbus.Message
125+}
126+
127+func (f *fakeProxy) Call(iface, method string, args ...interface{}) (*dbus.Message, error) {
128+ // store the called method and return Result
129+ f.Interface = iface
130+ f.MethodName = method
131+ f.Args = args
132+ if f.Err == nil {
133+ return f.Result, nil
134+ }
135+ return nil, f.Err
136+}
137+
138+type FakeWatch struct {
139+ Canceled bool
140+ Ch chan *dbus.Message
141+}
142+
143+func newFakeWatch() *FakeWatch {
144+ ch := make(chan *dbus.Message)
145+ fw := FakeWatch{false, ch}
146+ return &fw
147+}
148+
149+func (w *FakeWatch) Cancel() error {
150+ w.Canceled = true
151+ return nil
152+}
153+
154+func (w *FakeWatch) Chanel() chan *dbus.Message {
155+ return w.Ch
156+}
157+
158+// returns a new error that can be used in the tests
159+func newDBusError() *dbus.Message {
160+ msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method")
161+ msg.Type = dbus.TypeError
162+ msg.ErrorName = "com.testing.udm"
163+ return msg
164+}
165+
166+func newDBusReturn() *dbus.Message {
167+ msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method")
168+ msg.Type = dbus.TypeMethodReturn
169+ return msg
170+}
171
172=== renamed file 'bindings/golang/udm.go' => 'bindings/golang/downloader.go'
173--- bindings/golang/udm.go 2014-03-19 11:57:35 +0000
174+++ bindings/golang/downloader.go 2014-05-09 08:51:26 +0000
175@@ -24,6 +24,7 @@
176
177 import (
178 "errors"
179+ "fmt"
180 "launchpad.net/go-dbus/v1"
181 "runtime"
182 )
183@@ -51,13 +52,6 @@
184 POST_DOWNLOAD_COMMAND = "post-download-command"
185 )
186
187-// Progress provides how much progress has been performed in a download that was
188-// already started.
189-type Progress struct {
190- Received uint64
191- Total uint64
192-}
193-
194 // Download is the common interface of a download. It provides all the required
195 // methods to interact with a download created by udm.
196 type Download interface {
197@@ -67,6 +61,7 @@
198 SetThrottle(uint64) error
199 Throttle() (uint64, error)
200 AllowMobileDownload(bool) error
201+ SetDestinationDir(string) error
202 IsMobileDownload() (bool, error)
203 Start() error
204 Pause() error
205@@ -81,42 +76,25 @@
206 Error() chan error
207 }
208
209-// Manager is the single point of entry of the API. Allows to interact with the
210-// general setting of udm as well as to create downloads at will.
211-type Manager interface {
212- CreateDownload(string, string, string, map[string]interface{}, map[string]string) (Download, error)
213- CreateMmsDownload(string, string, int, string, string) (Download, error)
214-}
215-
216 // FileDownload represents a single file being downloaded by udm.
217 type FileDownload struct {
218 conn *dbus.Connection
219- proxy *dbus.ObjectProxy
220+ proxy proxy
221 path dbus.ObjectPath
222 started chan bool
223- started_w *dbus.SignalWatch
224+ started_w watch
225 paused chan bool
226- paused_w *dbus.SignalWatch
227+ paused_w watch
228 resumed chan bool
229- resumed_w *dbus.SignalWatch
230+ resumed_w watch
231 canceled chan bool
232- canceled_w *dbus.SignalWatch
233+ canceled_w watch
234 finished chan string
235- finished_w *dbus.SignalWatch
236+ finished_w watch
237 errors chan error
238- error_w *dbus.SignalWatch
239+ error_w watch
240 progress chan Progress
241- progress_w *dbus.SignalWatch
242-}
243-
244-func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (*dbus.SignalWatch, error) {
245- w, err := conn.WatchSignal(&dbus.MatchRule{
246- Type: dbus.TypeSignal,
247- Sender: DOWNLOAD_SERVICE,
248- Interface: DOWNLOAD_INTERFACE,
249- Member: signal,
250- Path: path})
251- return w, err
252+ progress_w watch
253 }
254
255 func (down *FileDownload) free() {
256@@ -197,10 +175,15 @@
257 // TotalSize returns the total size of the file being downloaded.
258 func (down *FileDownload) TotalSize() (size uint64, err error) {
259 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "totalSize")
260- if err != nil || reply.Type == dbus.TypeError {
261+ if err != nil {
262 return 0, err
263 }
264- if err = reply.Args(&size); err != nil {
265+
266+ if reply.Type == dbus.TypeError {
267+ return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
268+ }
269+
270+ if err = readArgs(reply, &size); err != nil {
271 return 0, err
272 }
273 return size, nil
274@@ -209,10 +192,15 @@
275 // Process returns the process so far in downloading the file.
276 func (down *FileDownload) Progress() (progress uint64, err error) {
277 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "progress")
278- if err != nil || reply.Type == dbus.TypeError {
279+ if err != nil {
280 return 0, err
281 }
282- if err = reply.Args(&progress); err != nil {
283+
284+ if reply.Type == dbus.TypeError {
285+ return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
286+ }
287+
288+ if err = readArgs(reply, &progress); err != nil {
289 return 0, err
290 }
291 return progress, nil
292@@ -221,10 +209,15 @@
293 // Metadata returns the metadata that was provided at creating time to the download.
294 func (down *FileDownload) Metadata() (metadata map[string]string, err error) {
295 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "metadata")
296- if err != nil || reply.Type == dbus.TypeError {
297+ if err != nil {
298 return nil, err
299 }
300- if err = reply.Args(&metadata); err != nil {
301+
302+ if reply.Type == dbus.TypeError {
303+ return nil, fmt.Errorf("DBus Error: %", reply.ErrorName)
304+ }
305+
306+ if err = readArgs(reply, &metadata); err != nil {
307 return nil, err
308 }
309 return metadata, nil
310@@ -233,19 +226,29 @@
311 // SetThrottle sets the network throttle to be used in the download.
312 func (down *FileDownload) SetThrottle(throttle uint64) (err error) {
313 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setThrottle", throttle)
314- if err != nil || reply.Type == dbus.TypeError {
315+ if err != nil {
316 return err
317 }
318+
319+ if reply.Type == dbus.TypeError {
320+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
321+ }
322+
323 return nil
324 }
325
326 // Throttle returns the network throttle that is currently used in the download.
327 func (down *FileDownload) Throttle() (throttle uint64, err error) {
328 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "throttle")
329- if err != nil || reply.Type == dbus.TypeError {
330+ if err != nil {
331 return 0, err
332 }
333- if err = reply.Args(&throttle); err != nil {
334+
335+ if reply.Type == dbus.TypeError {
336+ return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
337+ }
338+
339+ if err = readArgs(reply, &throttle); err != nil {
340 return 0, err
341 }
342 return throttle, nil
343@@ -255,26 +258,52 @@
344 // connection.
345 func (down *FileDownload) AllowMobileDownload(allowed bool) (err error) {
346 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "allowGSMDownload", allowed)
347- if err != nil || reply.Type == dbus.TypeError {
348- return err
349- }
350+ if err != nil {
351+ return err
352+ }
353+
354+ if reply.Type == dbus.TypeError {
355+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
356+ }
357+
358+ return nil
359+}
360+
361+// SetDestinationDir permits unconfined applications to set the destination
362+// directory of the download. This method must be called BEFORE the download
363+// is started else an error will be returned.
364+func (down *FileDownload) SetDestinationDir(path string) (err error) {
365+ reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setDestinationDir", path)
366+ if err != nil {
367+ return err
368+ }
369+
370+ if reply.Type == dbus.TypeError {
371+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
372+ }
373+
374 return nil
375 }
376
377 // IsMobileDownload returns if the download will be performed over the mobile data.
378 func (down *FileDownload) IsMobileDownload() (allowed bool, err error) {
379 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "isGSMDownloadAllowed", allowed)
380- if err != nil || reply.Type == dbus.TypeError {
381+ if err != nil {
382 return false, err
383 }
384- if err = reply.Args(&allowed); err != nil {
385+
386+ if reply.Type == dbus.TypeError {
387+ return false, fmt.Errorf("DBus Error: %", reply.ErrorName)
388+ }
389+
390+ if err = readArgs(reply, &allowed); err != nil {
391 return false, err
392 }
393 return allowed, nil
394 }
395
396 // Start tells udm that the download is ready to be peformed and that the client is
397-// ready to recieve signals. The following is a commong pattern to be used when
398+// ready to recieve signals. The following is a common pattern to be used when
399 // creating downloads in udm.
400 //
401 // man, err := udm.NewDownloadManager()
402@@ -317,27 +346,42 @@
403 // <- finished_signal
404 func (down *FileDownload) Start() (err error) {
405 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "start")
406- if err != nil || reply.Type == dbus.TypeError {
407+ if err != nil {
408 return err
409 }
410+
411+ if reply.Type == dbus.TypeError {
412+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
413+ }
414+
415 return nil
416 }
417
418 // Pause pauses a download that was started and if not nothing is done.
419 func (down *FileDownload) Pause() (err error) {
420 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "pause")
421- if err != nil || reply.Type == dbus.TypeError {
422+ if err != nil {
423 return err
424 }
425+
426+ if reply.Type == dbus.TypeError {
427+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
428+ }
429+
430 return nil
431 }
432
433 // Resumes a download that was paused or does nothing otherwise.
434 func (down *FileDownload) Resume() (err error) {
435 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "resume")
436- if err != nil || reply.Type == dbus.TypeError {
437+ if err != nil {
438 return err
439 }
440+
441+ if reply.Type == dbus.TypeError {
442+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
443+ }
444+
445 return nil
446 }
447
448@@ -345,17 +389,22 @@
449 // that were created.
450 func (down *FileDownload) Cancel() (err error) {
451 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "cancel")
452- if err != nil || reply.Type == dbus.TypeError {
453+ if err != nil {
454 return err
455 }
456+
457+ if reply.Type == dbus.TypeError {
458+ return fmt.Errorf("DBus Error: %", reply.ErrorName)
459+ }
460+
461 return nil
462 }
463
464 func (down *FileDownload) connectToStarted() {
465 go func() {
466- for msg := range down.started_w.C {
467+ for msg := range down.started_w.Chanel() {
468 var started bool
469- msg.Args(&started)
470+ readArgs(msg, &started)
471 down.started <- started
472 }
473 close(down.started)
474@@ -369,9 +418,9 @@
475
476 func (down *FileDownload) connectToPaused() {
477 go func() {
478- for msg := range down.paused_w.C {
479+ for msg := range down.paused_w.Chanel() {
480 var paused bool
481- msg.Args(&paused)
482+ readArgs(msg, &paused)
483 down.paused <- paused
484 }
485 close(down.paused)
486@@ -385,10 +434,10 @@
487
488 func (down *FileDownload) connectToProgress() {
489 go func() {
490- for msg := range down.progress_w.C {
491+ for msg := range down.progress_w.Chanel() {
492 var received uint64
493 var total uint64
494- msg.Args(&received, &total)
495+ readArgs(msg, &received, &total)
496 down.progress <- Progress{received, total}
497 }
498 close(down.progress)
499@@ -403,9 +452,9 @@
500
501 func (down *FileDownload) connectToResumed() {
502 go func() {
503- for msg := range down.resumed_w.C {
504+ for msg := range down.resumed_w.Chanel() {
505 var resumed bool
506- msg.Args(&resumed)
507+ readArgs(msg, &resumed)
508 down.resumed <- resumed
509 }
510 close(down.resumed)
511@@ -419,9 +468,9 @@
512
513 func (down *FileDownload) connectToCanceled() {
514 go func() {
515- for msg := range down.canceled_w.C {
516+ for msg := range down.canceled_w.Chanel() {
517 var canceled bool
518- msg.Args(&canceled)
519+ readArgs(msg, &canceled)
520 down.canceled <- canceled
521 }
522 close(down.canceled)
523@@ -435,9 +484,9 @@
524
525 func (down *FileDownload) connectToFinished() {
526 go func() {
527- for msg := range down.finished_w.C {
528+ for msg := range down.finished_w.Chanel() {
529 var path string
530- msg.Args(&path)
531+ readArgs(msg, &path)
532 down.finished <- path
533 }
534 close(down.finished)
535@@ -451,9 +500,9 @@
536
537 func (down *FileDownload) connectToError() {
538 go func() {
539- for msg := range down.error_w.C {
540+ for msg := range down.error_w.Chanel() {
541 var reason string
542- msg.Args(&reason)
543+ readArgs(msg, &reason)
544 down.errors <- errors.New(reason)
545 }
546 close(down.errors)
547@@ -527,7 +576,7 @@
548 if err != nil || reply.Type == dbus.TypeError {
549 return nil, err
550 }
551- if err = reply.Args(&path); err != nil {
552+ if err = readArgs(reply, &path); err != nil {
553 return nil, err
554 }
555 down, err = newFileDownload(man.conn, path)
556@@ -543,7 +592,7 @@
557 if err != nil || reply.Type == dbus.TypeError {
558 return nil, err
559 }
560- if err = reply.Args(&path); err != nil {
561+ if err = readArgs(reply, &path); err != nil {
562 return nil, err
563 }
564 down, err = newFileDownload(man.conn, path)
565
566=== added file 'bindings/golang/downloader_test.go'
567--- bindings/golang/downloader_test.go 1970-01-01 00:00:00 +0000
568+++ bindings/golang/downloader_test.go 2014-05-09 08:51:26 +0000
569@@ -0,0 +1,306 @@
570+/*
571+ * Copyright 2014 Canonical Ltd.
572+ *
573+ * Authors:
574+ * Manuel de la Pena: manuel.delapena@canonical.com
575+ *
576+ * This file is part of ubuntu-download-manager.
577+ *
578+ * ubuntu-download-manager is free software; you can redistribute it and/or modify
579+ * it under the terms of the GNU General Public License as published by
580+ * the Free Software Foundation; version 3.
581+ *
582+ * ubuntu-download-manager is distributed in the hope that it will be useful,
583+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
584+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
585+ * GNU General Public License for more details.
586+ *
587+ * You should have received a copy of the GNU General Public License
588+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
589+ */
590+
591+package udm
592+
593+import (
594+ "errors"
595+ . "gopkg.in/check.v1"
596+ "launchpad.net/go-dbus/v1"
597+ "reflect"
598+)
599+
600+type DownloadSuite struct {
601+ proxy *fakeProxy
602+ download *FileDownload
603+ msg_args []interface{}
604+ msg_args_err error
605+ started_ch chan bool
606+ started_w watch
607+ paused_ch chan bool
608+ paused_w watch
609+ resumed_ch chan bool
610+ resumed_w watch
611+ canceled_ch chan bool
612+ canceled_w watch
613+ finished_ch chan string
614+ finished_w watch
615+ errors_ch chan error
616+ errors_w watch
617+ progress_ch chan Progress
618+ progress_w watch
619+}
620+
621+var _ = Suite(&DownloadSuite{})
622+
623+func (s *DownloadSuite) SetUpTest(c *C) {
624+ s.proxy = &fakeProxy{}
625+ s.started_ch = make(chan bool)
626+ s.started_w = newFakeWatch()
627+ s.paused_ch = make(chan bool)
628+ s.paused_w = newFakeWatch()
629+ s.resumed_ch = make(chan bool)
630+ s.resumed_w = newFakeWatch()
631+ s.canceled_ch = make(chan bool)
632+ s.canceled_w = newFakeWatch()
633+ s.finished_ch = make(chan string)
634+ s.finished_w = newFakeWatch()
635+ s.errors_ch = make(chan error)
636+ s.errors_w = newFakeWatch()
637+ s.progress_ch = make(chan Progress)
638+ s.progress_w = newFakeWatch()
639+ s.download = &FileDownload{nil, s.proxy, "", s.started_ch, s.started_w, s.paused_ch, s.paused_w, s.resumed_ch, s.resumed_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w}
640+
641+ readArgs = func(msg *dbus.Message, args ...interface{}) error {
642+ for i, arg := range args {
643+ v := reflect.ValueOf(arg)
644+ e := v.Elem()
645+ switch s.msg_args[i].(type) {
646+ default:
647+ return errors.New("unexpected type")
648+ case bool:
649+ e.SetBool(s.msg_args[i].(bool))
650+ case uint64:
651+ e.SetUint(s.msg_args[i].(uint64))
652+ }
653+ }
654+ return s.msg_args_err
655+ }
656+}
657+
658+func (s *DownloadSuite) TestTotalSizeError(c *C) {
659+ s.proxy.Result = newDBusError()
660+ size, err := s.download.TotalSize()
661+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
662+ c.Assert(s.proxy.MethodName, Equals, "totalSize")
663+ c.Assert(size, Equals, uint64(0))
664+ c.Assert(err, NotNil)
665+}
666+
667+func (s *DownloadSuite) TestTotalSize(c *C) {
668+ expected_size := uint64(98)
669+ s.proxy.Result = newDBusReturn()
670+ s.msg_args = make([]interface{}, 1)
671+ s.msg_args[0] = expected_size
672+ s.msg_args_err = nil
673+ size, err := s.download.TotalSize()
674+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
675+ c.Assert(s.proxy.MethodName, Equals, "totalSize")
676+ c.Assert(err, IsNil)
677+ c.Assert(size, Equals, expected_size)
678+}
679+
680+func (s *DownloadSuite) TestProgressError(c *C) {
681+ s.proxy.Result = newDBusError()
682+ progress, err := s.download.Progress()
683+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
684+ c.Assert(s.proxy.MethodName, Equals, "progress")
685+ c.Assert(progress, Equals, uint64(0))
686+ c.Assert(err, NotNil)
687+}
688+
689+func (s *DownloadSuite) TestProgress(c *C) {
690+ expected_progress := uint64(98)
691+ s.proxy.Result = newDBusReturn()
692+ s.msg_args = make([]interface{}, 1)
693+ s.msg_args[0] = expected_progress
694+ s.msg_args_err = nil
695+ progress, err := s.download.Progress()
696+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
697+ c.Assert(s.proxy.MethodName, Equals, "progress")
698+ c.Assert(err, IsNil)
699+ c.Assert(progress, Equals, expected_progress)
700+}
701+
702+func (s *DownloadSuite) TestMetadataError(c *C) {
703+ s.proxy.Result = newDBusError()
704+ metadata, err := s.download.Metadata()
705+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
706+ c.Assert(s.proxy.MethodName, Equals, "metadata")
707+ c.Assert(metadata, IsNil)
708+ c.Assert(err, NotNil)
709+}
710+
711+func (s *DownloadSuite) TestSetThrotthleError(c *C) {
712+ throttle := uint64(9)
713+ s.proxy.Result = newDBusError()
714+ err := s.download.SetThrottle(throttle)
715+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
716+ c.Assert(s.proxy.MethodName, Equals, "setThrottle")
717+ c.Assert(err, NotNil)
718+ c.Assert(s.proxy.Args[0], Equals, throttle)
719+}
720+
721+func (s *DownloadSuite) TestSetThrottle(c *C) {
722+ s.proxy.Result = newDBusReturn()
723+ err := s.download.SetThrottle(uint64(9))
724+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
725+ c.Assert(s.proxy.MethodName, Equals, "setThrottle")
726+ c.Assert(err, IsNil)
727+}
728+
729+func (s *DownloadSuite) TestThrottleError(c *C) {
730+ s.proxy.Result = newDBusError()
731+ size, err := s.download.Throttle()
732+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
733+ c.Assert(s.proxy.MethodName, Equals, "throttle")
734+ c.Assert(size, Equals, uint64(0))
735+ c.Assert(err, NotNil)
736+}
737+
738+func (s *DownloadSuite) TestThrottle(c *C) {
739+ expected_throttle := uint64(98)
740+ s.proxy.Result = newDBusReturn()
741+ s.msg_args = make([]interface{}, 1)
742+ s.msg_args[0] = expected_throttle
743+ s.msg_args_err = nil
744+ throttle, err := s.download.Throttle()
745+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
746+ c.Assert(s.proxy.MethodName, Equals, "throttle")
747+ c.Assert(err, IsNil)
748+ c.Assert(throttle, Equals, expected_throttle)
749+}
750+
751+func (s *DownloadSuite) TestAllowMobileDownloadError(c *C) {
752+ s.proxy.Result = newDBusError()
753+ err := s.download.AllowMobileDownload(true)
754+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
755+ c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload")
756+ c.Assert(err, NotNil)
757+}
758+
759+func (s *DownloadSuite) TestAllowMobileDownload(c *C) {
760+ expected_allowed := true
761+ s.proxy.Result = newDBusReturn()
762+ err := s.download.AllowMobileDownload(expected_allowed)
763+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
764+ c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload")
765+ c.Assert(err, IsNil)
766+ c.Assert(s.proxy.Args[0], Equals, expected_allowed)
767+}
768+
769+func (s *DownloadSuite) TestSetDestinationDirError(c *C) {
770+ s.proxy.Result = newDBusError()
771+ err := s.download.SetDestinationDir("/new/path")
772+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
773+ c.Assert(s.proxy.MethodName, Equals, "setDestinationDir")
774+ c.Assert(err, NotNil)
775+}
776+
777+func (s *DownloadSuite) TestSetDestinationDir(c *C) {
778+ expected_dir := "/path/to/use"
779+ s.proxy.Result = newDBusReturn()
780+ err := s.download.SetDestinationDir(expected_dir)
781+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
782+ c.Assert(s.proxy.MethodName, Equals, "setDestinationDir")
783+ c.Assert(err, IsNil)
784+ c.Assert(s.proxy.Args[0], Equals, expected_dir)
785+}
786+
787+func (s *DownloadSuite) TestIsMobileDownloadError(c *C) {
788+ s.proxy.Result = newDBusError()
789+ allowed, err := s.download.IsMobileDownload()
790+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
791+ c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed")
792+ c.Assert(allowed, Equals, false)
793+ c.Assert(err, NotNil)
794+}
795+
796+func (s *DownloadSuite) TestIsMobileDownload(c *C) {
797+ expected_allowed := true
798+ s.proxy.Result = newDBusReturn()
799+ s.msg_args = make([]interface{}, 1)
800+ s.msg_args[0] = expected_allowed
801+ s.msg_args_err = nil
802+ allowed, err := s.download.IsMobileDownload()
803+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
804+ c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed")
805+ c.Assert(err, IsNil)
806+ c.Assert(allowed, Equals, expected_allowed)
807+}
808+
809+func (s *DownloadSuite) TestStartDBusError(c *C) {
810+ s.proxy.Result = newDBusError()
811+ err := s.download.Start()
812+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
813+ c.Assert(s.proxy.MethodName, Equals, "start")
814+ c.Assert(err, NotNil)
815+}
816+
817+func (s *DownloadSuite) TestStartError(c *C) {
818+ s.proxy.Result = newDBusReturn()
819+ s.proxy.Err = errors.New("Fake error")
820+ err := s.download.Start()
821+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
822+ c.Assert(s.proxy.MethodName, Equals, "start")
823+ c.Assert(err, NotNil)
824+}
825+
826+func (s *DownloadSuite) TestPauseDBusError(c *C) {
827+ s.proxy.Result = newDBusError()
828+ err := s.download.Pause()
829+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
830+ c.Assert(s.proxy.MethodName, Equals, "pause")
831+ c.Assert(err, NotNil)
832+}
833+
834+func (s *DownloadSuite) TestPauseError(c *C) {
835+ s.proxy.Result = newDBusReturn()
836+ s.proxy.Err = errors.New("Fake error")
837+ err := s.download.Pause()
838+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
839+ c.Assert(s.proxy.MethodName, Equals, "pause")
840+ c.Assert(err, NotNil)
841+}
842+
843+func (s *DownloadSuite) TestResumeDBusError(c *C) {
844+ s.proxy.Result = newDBusError()
845+ err := s.download.Resume()
846+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
847+ c.Assert(s.proxy.MethodName, Equals, "resume")
848+ c.Assert(err, NotNil)
849+}
850+
851+func (s *DownloadSuite) TestResumeError(c *C) {
852+ s.proxy.Result = newDBusReturn()
853+ s.proxy.Err = errors.New("Fake error")
854+ err := s.download.Resume()
855+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
856+ c.Assert(s.proxy.MethodName, Equals, "resume")
857+ c.Assert(err, NotNil)
858+}
859+
860+func (s *DownloadSuite) TestCancelDBusError(c *C) {
861+ s.proxy.Result = newDBusError()
862+ err := s.download.Cancel()
863+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
864+ c.Assert(s.proxy.MethodName, Equals, "cancel")
865+ c.Assert(err, NotNil)
866+}
867+
868+func (s *DownloadSuite) TestCancelError(c *C) {
869+ s.proxy.Result = newDBusReturn()
870+ s.proxy.Err = errors.New("Fake error")
871+ err := s.download.Cancel()
872+ c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
873+ c.Assert(s.proxy.MethodName, Equals, "cancel")
874+ c.Assert(err, NotNil)
875+}

Subscribers

People subscribed via source and target branches