~charlesk/indicator-power/lp-1470080-missing-icon-when-apple-devices-connected

« back to all changes in this revision

Viewing changes to tests/test-device.cc

Fix the fallback power icon so the battery icon doesn't show red above 20% even when the Suru icon theme isn't present. Fixes: #1559731
Approved by: PS Jenkins bot, Ted Gould

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
  protected:
63
63
 
64
 
    void check_icon_names (const IndicatorPowerDevice * device, const char * expected)
 
64
    static std::string get_icon_names_from_device(const IndicatorPowerDevice* device)
65
65
    {
 
66
      std::string ret;
66
67
      char ** names = indicator_power_device_get_icon_names (device);
67
68
      char * str = g_strjoinv (";", names);
68
 
      ASSERT_STREQ (expected, str);
 
69
      if (str != nullptr)
 
70
        ret = str;
69
71
      g_free (str);
70
72
      g_strfreev (names);
 
73
      return ret;
71
74
    }
72
75
 
73
76
    void check_label (const IndicatorPowerDevice * device,
121
124
    }
122
125
};
123
126
 
 
127
#define EXPECT_ICON_NAMES_EQ(expected_in,device_in)                          \
 
128
  do {                                                                       \
 
129
    const std::string tmp_expected {expected_in};                            \
 
130
    const std::string tmp_actual {get_icon_names_from_device(device_in)};    \
 
131
    EXPECT_EQ(tmp_expected, tmp_actual);                                     \
 
132
  } while(0)
 
133
 
124
134
/***
125
135
****
126
136
***/
266
276
  // power
267
277
  g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_LINE_POWER,
268
278
                   NULL);
269
 
  check_icon_names (device, "ac-adapter-symbolic;"
270
 
                            "ac-adapter");
 
279
  EXPECT_ICON_NAMES_EQ("ac-adapter-symbolic;"
 
280
                       "ac-adapter",
 
281
                       device);
271
282
 
272
283
  // monitor
273
284
  g_object_set (o, INDICATOR_POWER_DEVICE_KIND, UP_DEVICE_KIND_MONITOR,
274
285
                   NULL);
275
 
  check_icon_names (device, "gpm-monitor-symbolic;"
276
 
                            "gpm-monitor");
 
286
  EXPECT_ICON_NAMES_EQ("gpm-monitor-symbolic;"
 
287
                       "gpm-monitor",
 
288
                       device);
277
289
 
278
290
  // devices that hold a charge
279
291
  struct {
301
313
      g_string_append_printf (expected, "gpm-%s-empty;", kind_str);
302
314
      g_string_append_printf (expected, "gpm-%s-000;", kind_str);
303
315
      g_string_append_printf (expected, "%s-empty", kind_str);
304
 
      check_icon_names (device, expected->str);
 
316
      EXPECT_ICON_NAMES_EQ(expected->str, device);
305
317
      g_string_truncate (expected, 0);
306
318
 
307
319
      // charged
314
326
      g_string_append_printf (expected, "gpm-%s-100;", kind_str);
315
327
      g_string_append_printf (expected, "%s-full-charged;", kind_str);
316
328
      g_string_append_printf (expected, "%s-full-charging", kind_str);
317
 
      check_icon_names (device, expected->str);
 
329
      EXPECT_ICON_NAMES_EQ(expected->str, device);
318
330
      g_string_truncate (expected, 0);
319
331
 
320
332
      // charging, 95%
326
338
      g_string_append_printf (expected, "gpm-%s-100-charging;", kind_str);
327
339
      g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
328
340
      g_string_append_printf (expected, "%s-full-charging", kind_str);
329
 
      check_icon_names (device, expected->str);
 
341
      EXPECT_ICON_NAMES_EQ(expected->str, device);
330
342
      g_string_truncate (expected, 0);
331
343
 
332
344
      // charging, 85%
340
352
      g_string_append_printf (expected, "gpm-%s-080-charging;", kind_str);
341
353
      g_string_append_printf (expected, "%s-full-charging-symbolic;", kind_str);
342
354
      g_string_append_printf (expected, "%s-full-charging", kind_str);
343
 
      check_icon_names (device, expected->str);
 
355
      EXPECT_ICON_NAMES_EQ(expected->str, device);
344
356
      g_string_truncate (expected, 0);
345
357
 
346
358
      // charging, 50%
354
366
      g_string_append_printf (expected, "gpm-%s-060-charging;", kind_str);
355
367
      g_string_append_printf (expected, "%s-good-charging-symbolic;", kind_str);
356
368
      g_string_append_printf (expected, "%s-good-charging", kind_str);
357
 
      check_icon_names (device, expected->str);
 
369
      EXPECT_ICON_NAMES_EQ(expected->str, device);
358
370
      g_string_truncate (expected, 0);
359
371
 
360
372
      // charging, 25%
364
376
                       NULL);
365
377
      g_string_append_printf (expected, "%s-030-charging;", kind_str);
366
378
      g_string_append_printf (expected, "gpm-%s-030-charging;", kind_str);
367
 
      g_string_append_printf (expected, "%s-020-charging;", kind_str);
368
 
      g_string_append_printf (expected, "gpm-%s-020-charging;", kind_str);
 
379
      g_string_append_printf (expected, "%s-040-charging;", kind_str);
 
380
      g_string_append_printf (expected, "gpm-%s-040-charging;", kind_str);
369
381
      g_string_append_printf (expected, "%s-low-charging-symbolic;", kind_str);
370
382
      g_string_append_printf (expected, "%s-low-charging", kind_str);
371
 
      check_icon_names (device, expected->str);
 
383
      EXPECT_ICON_NAMES_EQ(expected->str, device);
372
384
      g_string_truncate (expected, 0);
373
385
 
374
386
      // charging, 5%
382
394
      g_string_append_printf (expected, "gpm-%s-000-charging;", kind_str);
383
395
      g_string_append_printf (expected, "%s-caution-charging-symbolic;", kind_str);
384
396
      g_string_append_printf (expected, "%s-caution-charging", kind_str);
385
 
      check_icon_names (device, expected->str);
 
397
      EXPECT_ICON_NAMES_EQ(expected->str, device);
386
398
      g_string_truncate (expected, 0);
387
399
 
388
400
      // discharging, 95%
394
406
      g_string_append_printf (expected, "gpm-%s-100;", kind_str);
395
407
      g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
396
408
      g_string_append_printf (expected, "%s-full", kind_str);
397
 
      check_icon_names (device, expected->str);
 
409
      EXPECT_ICON_NAMES_EQ(expected->str, device);
398
410
      g_string_truncate (expected, 0);
399
411
 
400
412
      // discharging, 85%
408
420
      g_string_append_printf (expected, "gpm-%s-080;", kind_str);
409
421
      g_string_append_printf (expected, "%s-full-symbolic;", kind_str);
410
422
      g_string_append_printf (expected, "%s-full", kind_str);
411
 
      check_icon_names (device, expected->str);
 
423
      EXPECT_ICON_NAMES_EQ(expected->str, device);
412
424
      g_string_truncate (expected, 0);
413
425
 
414
426
      // discharging, 50% -- 1 hour left
423
435
      g_string_append_printf (expected, "gpm-%s-060;", kind_str);
424
436
      g_string_append_printf (expected, "%s-good-symbolic;", kind_str);
425
437
      g_string_append_printf (expected, "%s-good", kind_str);
426
 
      check_icon_names (device, expected->str);
 
438
      EXPECT_ICON_NAMES_EQ(expected->str, device);
427
439
      g_string_truncate (expected, 0);
428
440
 
429
441
      // discharging, 25% -- 1 hour left
434
446
                       NULL);
435
447
      g_string_append_printf (expected, "%s-030;", kind_str);
436
448
      g_string_append_printf (expected, "gpm-%s-030;", kind_str);
437
 
      g_string_append_printf (expected, "%s-020;", kind_str);
438
 
      g_string_append_printf (expected, "gpm-%s-020;", kind_str);
 
449
      g_string_append_printf (expected, "%s-040;", kind_str);
 
450
      g_string_append_printf (expected, "gpm-%s-040;", kind_str);
439
451
      g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
440
452
      g_string_append_printf (expected, "%s-low", kind_str);
441
 
      check_icon_names (device, expected->str);
 
453
      EXPECT_ICON_NAMES_EQ(expected->str, device);
442
454
      g_string_truncate (expected, 0);
443
455
 
444
456
      // discharging, 25% -- 15 minutes left
449
461
                       NULL);
450
462
      g_string_append_printf (expected, "%s-030;", kind_str);
451
463
      g_string_append_printf (expected, "gpm-%s-030;", kind_str);
452
 
      g_string_append_printf (expected, "%s-020;", kind_str);
453
 
      g_string_append_printf (expected, "gpm-%s-020;", kind_str);
 
464
      g_string_append_printf (expected, "%s-040;", kind_str);
 
465
      g_string_append_printf (expected, "gpm-%s-040;", kind_str);
454
466
      g_string_append_printf (expected, "%s-low-symbolic;", kind_str);
455
467
      g_string_append_printf (expected, "%s-low", kind_str);
456
 
      check_icon_names (device, expected->str);
 
468
      EXPECT_ICON_NAMES_EQ(expected->str, device);
457
469
      g_string_truncate (expected, 0);
458
470
 
459
471
      // discharging, 5% -- 1 hour left
468
480
      g_string_append_printf (expected, "gpm-%s-000;", kind_str);
469
481
      g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
470
482
      g_string_append_printf (expected, "%s-caution", kind_str);
471
 
      check_icon_names (device, expected->str);
 
483
      EXPECT_ICON_NAMES_EQ(expected->str, device);
472
484
      g_string_truncate (expected, 0);
473
485
 
474
486
      // discharging, 5% -- 15 minutes left
483
495
      g_string_append_printf (expected, "gpm-%s-000;", kind_str);
484
496
      g_string_append_printf (expected, "%s-caution-symbolic;", kind_str);
485
497
      g_string_append_printf (expected, "%s-caution", kind_str);
486
 
      check_icon_names (device, expected->str);
 
498
      EXPECT_ICON_NAMES_EQ(expected->str, device);
487
499
      g_string_truncate (expected, 0);
488
500
 
489
501
      // state unknown
493
505
      g_string_append_printf (expected, "%s-missing-symbolic;", kind_str);
494
506
      g_string_append_printf (expected, "gpm-%s-missing;", kind_str);
495
507
      g_string_append_printf (expected, "%s-missing", kind_str);
496
 
      check_icon_names (device, expected->str);
 
508
      EXPECT_ICON_NAMES_EQ(expected->str, device);
497
509
      g_string_truncate (expected, 0);
498
510
  }
499
511
  g_string_free (expected, TRUE);