~mhr3/libunity/remote-scope-sources

« back to all changes in this revision

Viewing changes to test/vala/test-lens.vala

  • Committer: Tarmac
  • Author(s): Michal Hruby
  • Date: 2012-01-06 13:53:21 UTC
  • mfrom: (100.2.10 libunity)
  • Revision ID: tarmac-20120106135321-sxkgofuygntazlhe
Changes the API for setting sources on the scope side. (and makes it actually work). Fixes: https://bugs.launchpad.net/bugs/879484. Appoved by Mikkel Kamstrup Erlandsen.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    Test.add_data_func ("/Unit/Lens/TwoSearches", test_lens_two_searches);
50
50
    Test.add_data_func ("/Unit/Lens/ModelSync", test_lens_model_sync);
51
51
    Test.add_data_func ("/Unit/Lens/ReplyHint", test_lens_reply_hint);
 
52
    Test.add_data_func ("/Unit/Lens/Sources", test_lens_sources);
52
53
 
53
54
    Test.run ();
54
55
 
55
56
    return 0;
56
57
  }
57
58
 
 
59
  public static bool run_with_timeout (MainLoop ml, uint timeout_ms)
 
60
  {
 
61
    bool timeout_reached = false;
 
62
    var t_id = Timeout.add (timeout_ms, () => 
 
63
    {
 
64
      timeout_reached = true;
 
65
      debug ("Timeout reached");
 
66
      ml.quit ();
 
67
      return false;
 
68
    });
 
69
 
 
70
    ml.run ();
 
71
 
 
72
    if (!timeout_reached) Source.remove (t_id);
 
73
 
 
74
    return !timeout_reached;
 
75
  }
 
76
 
58
77
  static Unity.Lens exported_lens;
59
78
  static bool name_owned = false;
60
79
 
100
119
                                    () => { scope_up = true; ml.quit (); },
101
120
                                    () => { scope_up = false; });
102
121
 
103
 
    Timeout.add (2000, () => { ml.quit (); return false; });
104
 
    ml.run ();
 
122
    run_with_timeout (ml, 2000);
105
123
 
106
124
    assert (scope_up == true);
107
125
 
180
198
    });
181
199
 
182
200
    // wait for the signal or timeout
183
 
    Timeout.add (1000, () => { ml.quit (); return false; });
184
 
    ml.run ();
 
201
    run_with_timeout (ml, 1000);
185
202
 
186
203
    assert (got_search_changed == true);
187
204
    SignalHandler.disconnect (local_scope, sig_id);
224
241
    // we want to make sure the Search DBus call doesn't return before we
225
242
    // call finished on the LensSearch instance
226
243
    call_lens_search ("qoo", cb);
227
 
    Timeout.add (5000, () => { ml.quit (); return false; });
228
 
    ml.run ();
 
244
    run_with_timeout (ml, 5000);
229
245
 
230
246
    assert (got_search_changed == true);
231
247
    assert (finish_called == true);
338
354
      seqnum = seqnum_v.get_uint64 ();
339
355
      ml.quit ();
340
356
    });
341
 
    Timeout.add (3000, () => { assert_not_reached (); });
342
 
    ml.run ();
 
357
 
 
358
    run_with_timeout (ml, 3000);
343
359
    // libunity will emit warnings if the models are out-of-sync, those would
344
360
    // fail this test
345
361
 
383
399
      hint_reply = hint_v.get_string ();
384
400
      ml.quit ();
385
401
    });
386
 
    Timeout.add (3000, () => { assert_not_reached (); });
387
 
    ml.run ();
 
402
 
 
403
    run_with_timeout (ml, 3000);
388
404
 
389
405
    assert (got_search_changed == true);
390
406
    // FIXME: not too great test if previous tests did something with the model
392
408
 
393
409
    SignalHandler.disconnect (local_scope, sig_id);
394
410
  }
 
411
 
 
412
  public static void test_lens_sources ()
 
413
  {
 
414
    assert (local_scope != null);
 
415
 
 
416
    bool got_search_changed = false;
 
417
    local_scope.sources.add_option ("id1", "Source1", null);
 
418
    local_scope.sources.add_option ("id2", "Source2", null);
 
419
    var ml = new MainLoop ();
 
420
 
 
421
    // wait a bit for the model to update
 
422
    Timeout.add (500, () => { ml.quit (); return false; });
 
423
    ml.run ();
 
424
 
 
425
    bool found1 = false;
 
426
    bool found2 = false;
 
427
    foreach (var filter_option in exported_lens.get_sources_internal ().options)
 
428
    {
 
429
      if (filter_option.id.has_suffix ("id1") && filter_option.id != "id1")
 
430
        found1 = true;
 
431
      else if (filter_option.id.has_suffix ("id2") && filter_option.id != "id2")
 
432
        found2 = true;
 
433
    }
 
434
 
 
435
    assert (found1);
 
436
    assert (found2);
 
437
  }
395
438
}