~khurshid-alam/libunity/glib-2.59.3

113.2.1 by Michal Hruby
Added unity-lens-test-tool
1
/*
2
 * Copyright (C) 2012 Canonical Ltd
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License version 3 as
6
 * published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 * Authored by Michal Hruby <michal.hruby@canonical.com>
17
 *
18
 */
138.1.1 by Pawel Stolowski
Initial UI implementation.
19
using Gtk;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
20
using Unity.Protocol;
138.1.1 by Pawel Stolowski
Initial UI implementation.
21
113.2.1 by Michal Hruby
Added unity-lens-test-tool
22
namespace Unity.Tester
23
{
24
  namespace Options
25
  {
138.1.1 by Pawel Stolowski
Initial UI implementation.
26
    public static bool gui;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
27
    public static bool benchmark;
199.2.2 by Michal Hruby
Omg it compiles
28
    public static string scope_dbus_name;
29
    public static string scope_dbus_path;
30
    public static string scope_file;
113.2.1 by Michal Hruby
Added unity-lens-test-tool
31
    public static string search_string;
32
    public static int search_type;
199.53.1 by Michal Hruby
Add ability to use private channels
33
    public static bool private_channel;
113.2.1 by Michal Hruby
Added unity-lens-test-tool
34
    public static bool common_tests;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
35
    public static bool print_search_reply;
113.2.1 by Michal Hruby
Added unity-lens-test-tool
36
    public static bool dump_results;
37
    public static bool dump_filters;
301.2.1 by Michal Hruby
Make tracing easy
38
    public static bool diff_changes;
113.2.1 by Michal Hruby
Added unity-lens-test-tool
39
40
    public static bool test_server_mode;
41
    public static string[] test_cases;
42
  }
43
44
  namespace TestRunner
45
  {
46
    public static string[] test_cases;
47
    public static int test_index;
48
  }
49
50
  public errordomain TesterError
51
  {
52
    INVALID_ARGS
53
  }
54
138.2.2 by Didier Roche
just rename the binary, not the files themselves (mhr3 asked for it)
55
  private UnityToolUi ui;
138.1.1 by Pawel Stolowski
Initial UI implementation.
56
113.2.1 by Michal Hruby
Added unity-lens-test-tool
57
  const OptionEntry[] options =
58
  {
59
    {
138.1.1 by Pawel Stolowski
Initial UI implementation.
60
      "gui", 'g', 0, OptionArg.NONE, out Options.gui,
61
      "Run GUI", null
62
    },
63
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
64
      "benchmark", 'b', 0, OptionArg.NONE, out Options.benchmark,
65
      "Benchmark searches", null
66
    },
67
    {
199.2.2 by Michal Hruby
Omg it compiles
68
      "dbus-name", 'n', 0, OptionArg.STRING, out Options.scope_dbus_name,
69
      "Unique dbus name of the tested scope", null
70
    },
71
    {
72
      "dbus-path", 'p', 0, OptionArg.STRING, out Options.scope_dbus_path,
73
      "Object path of the scope", null
74
    },
75
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
76
      "scope-file", 's', 0, OptionArg.STRING, out Options.scope_file,
199.2.2 by Michal Hruby
Omg it compiles
77
      "Path to the scope file (to read out dbus name and path)", null
113.2.1 by Michal Hruby
Added unity-lens-test-tool
78
    },
79
    {
80
      "common-tests", 'c', 0, OptionArg.NONE, out Options.common_tests,
199.2.2 by Michal Hruby
Omg it compiles
81
      "Perform common tests each scope should conform to", null
113.2.1 by Michal Hruby
Added unity-lens-test-tool
82
    },
83
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
84
      "search", 'q', 0, OptionArg.STRING, out Options.search_string,
199.2.2 by Michal Hruby
Omg it compiles
85
      "Search string to send to the scope", null
113.2.1 by Michal Hruby
Added unity-lens-test-tool
86
    },
87
    {
88
      "search-type", 't', 0, OptionArg.INT, out Options.search_type,
89
      "Type of the search (value from Unity.SearchType enum)", null
90
    },
91
    {
92
      "dump-results", 'r', 0, OptionArg.NONE, out Options.dump_results,
93
      "Output the results model on stdout", null
94
    },
95
    {
96
      "dump-filters", 'f', 0, OptionArg.NONE, out Options.dump_filters,
97
      "Output the filter model on stdout", null
98
    },
99
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
100
      "print-search-reply", 0, 0, OptionArg.NONE, out Options.print_search_reply,
101
      "Output reply of the search call in its raw form", null
113.2.1 by Michal Hruby
Added unity-lens-test-tool
102
    },
103
    {
199.53.1 by Michal Hruby
Add ability to use private channels
104
      "private-channel", 0, 0, OptionArg.NONE, out Options.private_channel,
105
      "Use private channel for results transfer", null
106
    },
107
    {
301.2.1 by Michal Hruby
Make tracing easy
108
      "diff-changes", 'd', 0, OptionArg.NONE, out Options.diff_changes,
109
      "Use diff channel", null
110
    },
111
    {
113.2.1 by Michal Hruby
Added unity-lens-test-tool
112
      "test-server-mode", 0, 0, OptionArg.NONE, out Options.test_server_mode,
113.2.5 by Michal Hruby
Fix typo
113
      "Run a collection of test scripts", null
113.2.1 by Michal Hruby
Added unity-lens-test-tool
114
    },
115
    {
116
      "", 0, 0, OptionArg.FILENAME_ARRAY, out Options.test_cases,
117
      "Invididual test cases", "<test-scripts>"
118
    },
119
    {
120
      null
121
    }
122
  };
123
300.1.1 by Michal Hruby
Use protocol library to get scope properties
124
  public static void get_scope_params_from_file(string filename) throws Error
138.1.6 by Pawel Stolowski
UI code cleanup. Reuse call_lens_search and get_lens_info from unity-tool console code, removing
125
  {
300.1.1 by Michal Hruby
Use protocol library to get scope properties
126
    Unity.Protocol.ScopeRegistry.ScopeMetadata metadata;
127
    if (Path.is_absolute (filename))
128
    {
129
      metadata = Unity.Protocol.ScopeRegistry.ScopeMetadata.for_path (filename);
130
    }
131
    else
132
    {
133
      metadata = Unity.Protocol.ScopeRegistry.ScopeMetadata.for_id (filename);
134
    }
138.1.6 by Pawel Stolowski
UI code cleanup. Reuse call_lens_search and get_lens_info from unity-tool console code, removing
135
300.1.1 by Michal Hruby
Use protocol library to get scope properties
136
    Options.scope_dbus_name = metadata.dbus_name;
137
    Options.scope_dbus_path = metadata.dbus_path;
138.1.6 by Pawel Stolowski
UI code cleanup. Reuse call_lens_search and get_lens_info from unity-tool console code, removing
138
  }
139
113.2.4 by Michal Hruby
Address issues brought up during review
140
  public static void warn (string format, ...)
141
  {
142
    var args = va_list ();
138.2.1 by Didier Roche
rename unity-tool to libunity-tool
143
    logv ("libunity-tool", LogLevelFlags.LEVEL_WARNING, format, args);
113.2.4 by Michal Hruby
Address issues brought up during review
144
  }
145
113.2.1 by Michal Hruby
Added unity-lens-test-tool
146
  public static int main (string[] args)
147
  {
138.2.1 by Didier Roche
rename unity-tool to libunity-tool
148
    Environment.set_prgname ("libunity-tool");
149
    var opt_context = new OptionContext (" - libunity tool");
113.2.1 by Michal Hruby
Added unity-lens-test-tool
150
    opt_context.add_main_entries (options, null);
151
152
    try
153
    {
113.2.4 by Michal Hruby
Address issues brought up during review
154
      if (args.length <= 1)
155
      {
156
        print ("%s\n", opt_context.get_help (true, null));
157
        return 0;
158
      }
159
113.2.1 by Michal Hruby
Added unity-lens-test-tool
160
      opt_context.parse (ref args);
161
      if (Options.test_server_mode)
162
      {
163
        if (Options.test_cases == null ||
164
          (Options.test_cases.length=(int)strv_length(Options.test_cases)) == 0)
165
        {
166
          throw new TesterError.INVALID_ARGS ("No test cases specified");
167
        }
168
169
        // special mode where we just run test scripts inside a directory
170
        string[] test_scripts = get_test_cases ();
171
        TestRunner.test_cases = test_scripts;
172
173
        Test.init (ref args);
174
        foreach (unowned string test_case in test_scripts)
175
        {
199.2.2 by Michal Hruby
Omg it compiles
176
          Test.add_data_func ("/Integration/ScopeTest/" + 
113.2.1 by Michal Hruby
Added unity-lens-test-tool
177
                              Path.get_basename (test_case),
178
                              () =>
179
                              {
180
                                string test = TestRunner.test_cases[TestRunner.test_index++];
113.2.3 by Michal Hruby
We don't want no warnings
181
                                int status;
182
                                try
183
                                {
184
                                  Process.spawn_command_line_sync (test,
185
                                                                   null,
186
                                                                   null,
187
                                                                   out status);
188
                                }
189
                                catch (Error e)
190
                                {
113.2.4 by Michal Hruby
Address issues brought up during review
191
                                  warn ("%s", e.message);
113.2.3 by Michal Hruby
We don't want no warnings
192
                                  status = -1;
193
                                }
113.2.1 by Michal Hruby
Added unity-lens-test-tool
194
                                assert (status == 0);
195
                              });
196
        }
197
        return Test.run ();
198
      }
199
      else
200
      {
199.2.2 by Michal Hruby
Omg it compiles
201
        // read dbus name and path from the scope file
202
        if (Options.scope_file != null)
138.1.2 by Pawel Stolowski
Implemented majority of the UI. Moved UI code to separate file.
203
        {
199.2.2 by Michal Hruby
Omg it compiles
204
          get_scope_params_from_file(Options.scope_file);
138.1.2 by Pawel Stolowski
Implemented majority of the UI. Moved UI code to separate file.
205
        }
206
138.1.1 by Pawel Stolowski
Initial UI implementation.
207
        if (Options.gui)
208
        {
209
            Gtk.init(ref args);
138.2.2 by Didier Roche
just rename the binary, not the files themselves (mhr3 asked for it)
210
            ui = new UnityToolUi();
138.1.14 by Pawel Stolowski
Handle error when initializing GUI via *ui file (e.g. missing ui file) by displaying
211
            if (ui.init_gui()) {
212
                Gtk.main();
213
            }
138.1.11 by Pawel Stolowski
Return from main() on gtk loop exit when running gui.
214
            return 0;
138.1.1 by Pawel Stolowski
Initial UI implementation.
215
        }
216
113.2.1 by Michal Hruby
Added unity-lens-test-tool
217
        // check that we have dbus names
199.2.2 by Michal Hruby
Omg it compiles
218
        if (Options.scope_dbus_name == null || Options.scope_dbus_path == null)
113.2.1 by Michal Hruby
Added unity-lens-test-tool
219
        {
199.2.2 by Michal Hruby
Omg it compiles
220
          throw new TesterError.INVALID_ARGS ("Scope DBus name and path not specified!");
113.2.1 by Michal Hruby
Added unity-lens-test-tool
221
        }
222
        if (Options.common_tests)
223
        {
224
          int status = run_common_tests ();
225
          assert (status == 0);
226
        }
227
199.52.3 by Michal Hruby
Add even more information
228
        if (Options.benchmark)
229
        {
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
230
          // libunity uses an envvar to add time information, tell dbus
231
          // to use that envvar for newly spawned services
232
          var conn = Bus.get_sync (BusType.SESSION, null);
233
          var env = new HashTable<string, string> (str_hash, str_equal);
234
          env["LIBUNITY_TIME_SEARCHES"] = "1";
235
          conn.call_sync ("org.freedesktop.DBus",
236
                          "/org/freedesktop/DBus",
237
                          "org.freedesktop.DBus",
238
                          "UpdateActivationEnvironment",
239
                          new Variant.tuple ({env}),
240
                          null, 0, -1, null);
199.52.3 by Michal Hruby
Add even more information
241
        }
242
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
243
        // Get proxy
244
        string channel_id;
245
        Dee.SerializableModel results_model;
246
        var proxy = get_scope_proxy (Options.scope_dbus_name,
247
                                     Options.scope_dbus_path,
248
                                     (ChannelType) Options.search_type,
301.2.1 by Michal Hruby
Make tracing easy
249
                                     get_global_channel_flags (),
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
250
                                     out channel_id, out results_model);
251
113.2.1 by Michal Hruby
Added unity-lens-test-tool
252
        // Performing search
253
        if (Options.search_string != null)
254
        {
255
          var ml = new MainLoop ();
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
256
          int64 start_time = get_monotonic_time ();
257
          int64 first_result = 0;
258
          uint64 model_seqnum = 0;
259
          results_model.row_added.connect (() =>
260
          {
261
            if (first_result == 0) first_result = get_monotonic_time ();
262
          });
263
          proxy.search.begin (channel_id, Options.search_string,
264
                              new HashTable<string, Variant> (null, null),
265
                              null,
266
                              (obj, res) =>
267
          {
268
            try
269
            {
270
              var reply_dict = proxy.search.end (res);
271
              if ("model-seqnum" in reply_dict)
272
                model_seqnum = reply_dict["model-seqnum"].get_uint64 ();
273
              if (Options.print_search_reply)
274
              {
275
                Variant v = reply_dict;
276
                print ("%s\n", v.print (true)); // so much easier
277
              }
278
            }
279
            catch (Error err)
280
            {
281
              warning ("%s", err.message);
282
            }
113.2.1 by Michal Hruby
Added unity-lens-test-tool
283
            ml.quit ();
284
          });
285
286
          assert (run_with_timeout (ml, 15000));
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
287
          wait_for_seqnum (results_model as Dee.SharedModel, model_seqnum);
288
289
          if (Options.benchmark)
290
          {
291
            int64 end_time = get_monotonic_time ();
292
            int64 delta = end_time - start_time;
293
            double elapsed = delta;
294
            print ("Search took: %g seconds\n", elapsed / 1000000.0);
295
            if (first_result > 0)
296
            {
297
              delta = first_result - start_time;
298
              elapsed = delta;
299
              print ("First result after: %g seconds\n", elapsed / 1000000.0);
300
            }
301
          }
113.2.1 by Michal Hruby
Added unity-lens-test-tool
302
        }
303
304
        // Dumping models
305
        if (Options.dump_results || Options.dump_filters)
306
        {
307
          if (Options.dump_results)
308
          {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
309
            dump_results_model (results_model);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
310
          }
311
312
          if (Options.dump_filters)
313
          {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
314
            dump_filters_model (proxy.filters_model);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
315
          }
316
        }
199.53.2 by Michal Hruby
Close channel when done with it
317
318
        close_channel (proxy, channel_id);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
319
      }
320
    }
321
    catch (Error err)
322
    {
113.2.4 by Michal Hruby
Address issues brought up during review
323
      warn ("%s", err.message);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
324
      return 1;
325
    }
326
327
328
    return 0;
329
  }
330
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
331
  private ScopeProxy get_scope_proxy (string dbus_name, string dbus_path,
332
                                      ChannelType channel_type,
199.53.1 by Michal Hruby
Add ability to use private channels
333
                                      ChannelFlags channel_flags,
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
334
                                      out string channel_id,
335
                                      out Dee.SerializableModel model)
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
336
    throws Error
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
337
  {
338
    ScopeProxy? proxy = null;
339
    var ml = new MainLoop ();
340
    ScopeProxy.new_from_dbus.begin (dbus_name, dbus_path, null, (obj, res) =>
341
    {
342
      try
343
      {
344
        proxy = ScopeProxy.new_from_dbus.end (res);
345
      }
346
      catch (Error err)
347
      {
348
        warning ("%s", err.message);
349
      }
350
      ml.quit ();
351
    });
352
    run_with_timeout (ml, 15000);
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
353
    if (proxy == null)
354
    {
355
      throw new IOError.TIMED_OUT ("Timed out waiting for proxy");
356
    }
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
357
358
    ml = new MainLoop ();
359
    string? chan_id = null;
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
360
    Error? outer_error = null;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
361
    Dee.SerializableModel? results_model = null;
199.53.1 by Michal Hruby
Add ability to use private channels
362
    proxy.open_channel.begin (channel_type, channel_flags, null, (obj, res) =>
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
363
    {
364
      try
365
      {
366
        chan_id = proxy.open_channel.end (res, out results_model);
367
      }
368
      catch (Error err)
369
      {
370
        warning ("%s", err.message);
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
371
        outer_error = err;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
372
      }
373
      ml.quit ();
374
    });
375
    run_with_timeout (ml, 15000);
287.1.1 by Michal Hruby
Make sure libunity-tool doesn't crash when it can't connec to the bus
376
    if (outer_error != null) throw outer_error;
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
377
378
    channel_id = chan_id;
379
    model = results_model;
380
381
    return proxy;
382
  }
383
199.53.2 by Michal Hruby
Close channel when done with it
384
  private void close_channel (ScopeProxy proxy, string channel_id)
385
  {
386
    var ml = new MainLoop ();
387
    proxy.close_channel.begin (channel_id, null, (obj, res) =>
388
    {
389
      try
390
      {
391
        proxy.close_channel.end (res);
392
      }
393
      catch (Error err)
394
      {
395
        warning ("%s", err.message);
396
      }
397
      ml.quit ();
398
    });
399
    run_with_timeout (ml, 15000);
400
  }
401
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
402
  private static void wait_for_seqnum (Dee.SharedModel model, uint64 seqnum)
403
  {
404
    if (model.get_seqnum () >= seqnum) return;
405
406
    var ml = new MainLoop ();
407
    var update_sig_id = model.end_transaction.connect ((m, begin_seqnum, end_seqnum) =>
408
    {
409
      if (end_seqnum < seqnum) return;
410
411
      /* disconnect from within the signal handler... awesome, right? */
412
      ml.quit ();
413
    });
414
    run_with_timeout (ml, 15000);
415
    SignalHandler.disconnect (model, update_sig_id);
416
  }
417
113.2.1 by Michal Hruby
Added unity-lens-test-tool
418
  public static string[] get_test_cases ()
419
  {
420
    string[] results = {};
421
    foreach (string path in Options.test_cases)
422
    {
423
      if (FileUtils.test (path, FileTest.IS_REGULAR) &&
424
          FileUtils.test (path, FileTest.IS_EXECUTABLE))
425
      {
426
        results += path;
427
      }
428
      else if (FileUtils.test (path, FileTest.IS_DIR))
429
      {
113.2.3 by Michal Hruby
We don't want no warnings
430
        try
113.2.1 by Michal Hruby
Added unity-lens-test-tool
431
        {
113.2.3 by Michal Hruby
We don't want no warnings
432
          var dir = Dir.open (path);
433
          unowned string name = dir.read_name ();
434
          while (name != null)
113.2.1 by Michal Hruby
Added unity-lens-test-tool
435
          {
113.2.3 by Michal Hruby
We don't want no warnings
436
            var child_path = Path.build_filename (path, name, null);
437
            if (FileUtils.test (child_path, FileTest.IS_REGULAR) &&
438
                FileUtils.test (child_path, FileTest.IS_EXECUTABLE))
439
            {
440
              results += child_path;
441
            }
442
443
            name = dir.read_name ();
113.2.1 by Michal Hruby
Added unity-lens-test-tool
444
          }
113.2.4 by Michal Hruby
Address issues brought up during review
445
        } catch (Error e) { warn ("%s", e.message); }
113.2.1 by Michal Hruby
Added unity-lens-test-tool
446
      }
447
    }
448
449
    return results;
450
  }
451
452
  public static bool run_with_timeout (MainLoop ml, uint timeout_ms)
453
  {
454
    bool timeout_reached = false;
455
    var t_id = Timeout.add (timeout_ms, () => 
456
    {
457
      timeout_reached = true;
458
      debug ("Timeout reached");
459
      ml.quit ();
460
      return false;
461
    });
462
463
    ml.run ();
464
465
    if (!timeout_reached) Source.remove (t_id);
466
467
    return !timeout_reached;
468
  }
469
470
  private static int run_common_tests ()
471
  {
138.2.1 by Didier Roche
rename unity-tool to libunity-tool
472
    string[] args = { "./libunity-tool" };
113.2.1 by Michal Hruby
Added unity-lens-test-tool
473
    unowned string[] dummy = args;
474
475
    Test.init (ref dummy);
476
199.2.2 by Michal Hruby
Omg it compiles
477
    // checks that scope emits finished signal for every search type
113.2.1 by Michal Hruby
Added unity-lens-test-tool
478
    // (and both empty and non-empty searches)
199.2.2 by Michal Hruby
Omg it compiles
479
    Test.add_data_func ("/Integration/ScopeTest/DefaultSearch/Empty", () =>
480
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
481
      call_scope_search ("", ChannelType.DEFAULT);
199.2.2 by Michal Hruby
Omg it compiles
482
    });
483
484
    Test.add_data_func ("/Integration/ScopeTest/DefaultSearch/NonEmpty", () =>
485
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
486
      call_scope_search ("a", ChannelType.DEFAULT);
199.2.2 by Michal Hruby
Omg it compiles
487
    });
488
489
    // check also non-empty -> empty search
490
    Test.add_data_func ("/Integration/ScopeTest/DefaultSearch/Empty2", () =>
491
    {
199.53.2 by Michal Hruby
Close channel when done with it
492
      call_scope_search ("", ChannelType.DEFAULT);
199.2.2 by Michal Hruby
Omg it compiles
493
    });
494
495
    Test.add_data_func ("/Integration/ScopeTest/GlobalSearch/Empty", () =>
496
    {
199.53.2 by Michal Hruby
Close channel when done with it
497
      call_scope_search ("", ChannelType.GLOBAL);
199.2.2 by Michal Hruby
Omg it compiles
498
    });
499
500
    Test.add_data_func ("/Integration/ScopeTest/GlobalSearch/NonEmpty", () =>
501
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
502
      call_scope_search ("a", ChannelType.GLOBAL);
199.2.2 by Michal Hruby
Omg it compiles
503
    });
504
505
    // check also non-empty -> empty search
506
    Test.add_data_func ("/Integration/ScopeTest/GlobalSearch/Empty2", () =>
507
    {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
508
      call_scope_search ("", ChannelType.GLOBAL);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
509
    });
510
511
    return Test.run ();
512
  }
513
301.2.1 by Michal Hruby
Make tracing easy
514
  private static ChannelFlags get_global_channel_flags ()
515
  {
516
    var flags = ChannelFlags.NONE;
517
    if (Options.private_channel) flags |= ChannelFlags.PRIVATE;
518
    if (Options.diff_changes) flags |= ChannelFlags.DIFF_CHANGES;
519
    return flags;
520
  }
521
199.53.2 by Michal Hruby
Close channel when done with it
522
  private static void call_scope_search (string search_string,
523
                                         int search_type)
140.3.30 by Pawel Stolowski
Reverted whitespace/formatting changes in call_lens_search method.
524
  {
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
525
    string channel_id;
526
    Dee.SerializableModel results_model;
527
528
    var proxy = get_scope_proxy (Options.scope_dbus_name,
529
                                 Options.scope_dbus_path,
530
                                 (ChannelType) search_type,
301.2.1 by Michal Hruby
Make tracing easy
531
                                 get_global_channel_flags (),
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
532
                                 out channel_id, out results_model);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
533
534
    var ml = new MainLoop ();
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
535
    uint64 model_seqnum = 0;
536
    HashTable<string, Variant>? reply_dict = null;
537
    proxy.search.begin (channel_id, search_string,
538
                        new HashTable<string, Variant> (null, null),
539
                        null,
540
                        (obj, res) =>
541
    {
542
      try
543
      {
544
        reply_dict = proxy.search.end (res);
545
        if ("model-seqnum" in reply_dict)
546
          model_seqnum = reply_dict["model-seqnum"].get_uint64 ();
547
      }
548
      catch (Error err)
549
      {
550
        warning ("%s", err.message);
551
      }
552
      ml.quit ();
553
    });
554
555
    assert (run_with_timeout (ml, 15000));
556
    wait_for_seqnum (results_model as Dee.SharedModel, model_seqnum);
557
199.53.2 by Michal Hruby
Close channel when done with it
558
    close_channel (proxy, channel_id);
113.2.1 by Michal Hruby
Added unity-lens-test-tool
559
  }
560
561
  private void dump_results_model (Dee.Model model)
562
  {
563
    var iter = model.get_first_iter ();
564
    var last_iter = model.get_last_iter ();
565
566
    while (iter != last_iter)
567
    {
568
      var row = model.get_row (iter);
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
569
      print ("%s\t%s\t%u\t%u\t%s\t%s\t%s\t%s\t%s\n",
113.2.1 by Michal Hruby
Added unity-lens-test-tool
570
             row[0].get_string (),
571
             row[1].get_string (),
572
             row[2].get_uint32 (),
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
573
             row[3].get_uint32 (),
113.2.1 by Michal Hruby
Added unity-lens-test-tool
574
             row[4].get_string (),
575
             row[5].get_string (),
199.52.1 by Michal Hruby
Fix libunity-tool, add benchmark option
576
             row[6].get_string (),
577
             row[7].get_string (),
578
             row[8].print (true)
113.2.1 by Michal Hruby
Added unity-lens-test-tool
579
             );
580
581
      iter = model.next (iter);
582
    }
583
  }
584
585
  private void dump_filters_model (Dee.Model model)
586
  {
587
    var iter = model.get_first_iter ();
588
    var last_iter = model.get_last_iter ();
589
590
    while (iter != last_iter)
591
    {
592
      var row = model.get_row (iter);
593
      print ("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
594
             row[0].get_string (),
595
             row[1].get_string (),
596
             row[2].get_string (),
597
             row[3].get_string (),
598
             row[4].print (true),
599
             row[5].get_boolean ().to_string (),
600
             row[6].get_boolean ().to_string (),
601
             row[7].get_boolean ().to_string ()
602
             );
603
604
      iter = model.next (iter);
605
    }
606
  }
607
}