Merge lp://staging/~charlesk/indicator-power/coverage into lp://staging/indicator-power/12.10

Proposed by Charles Kerr
Status: Superseded
Proposed branch: lp://staging/~charlesk/indicator-power/coverage
Merge into: lp://staging/indicator-power/12.10
Diff against target: 3844 lines (+2748/-695)
16 files modified
Makefile.am (+8/-27)
configure.ac (+26/-1)
m4/gtest.m4 (+63/-0)
po/POTFILES.in (+2/-0)
src/Makefile.am (+36/-0)
src/dbus-listener.c (+247/-0)
src/dbus-listener.h (+82/-0)
src/device.c (+667/-0)
src/device.h (+107/-0)
src/indicator-power.c (+200/-667)
src/indicator-power.h (+58/-0)
tests/Makefile.am (+62/-0)
tests/Makefile.am.strings (+38/-0)
tests/test-dbus-listener.cc (+370/-0)
tests/test-device.cc (+470/-0)
tests/test-indicator.cc (+312/-0)
To merge this branch: bzr merge lp://staging/~charlesk/indicator-power/coverage
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Needs Fixing
Review via email: mp+108599@code.staging.launchpad.net

This proposal has been superseded by a proposal from 2012-06-06.

Description of the change

Refactoring of indicator-power to facilitate automated testing.

1. The devices are no longer stored internally in indicator-power as GVariants. Instead there is a new IndicatorPowerDevice object which contains the fields returned from Gnome Settings Daemon, and also adds public methods to get icons and user-readable strings describing the device. These icons and strings all have full coverage in the new unit tests.

2. Extract the DBus-specific code into a new object, IndicatorPowerDbusListener. This allows the indicator's DBus interaction to be tested at a low level via this object's API.

3. Fixes a handful of edge case bugs discovered while adding unit tests.

This patch increases indicator-power's branch coverage from 0% to 84% and its line coverage from 0% to 96%

To post a comment you must log in.
Revision history for this message
Lars Karlitski (larsu) wrote :

Very nice work! And impressive test coverage.

Note: I couldn't test it yet, as I'm still on precise. /me ducks.

src/Makefile.am:207:
  * any reason you're using noinst_HEADERS instead of listing the headers
    in the libraries sources? (the latter is recommended for programs and
    convenience libs in the automake docs)

dbus-listener.c
  * afaict, it could have been written by gdbus-codegen
  * 305: g_signal_new is passed one too many arguments. Please add the
    docstring with the number and names of parameters to it [1]
  * dispose() is missing g_bus_unwatch_name (priv->watcher_id)
  * get_devices_cb:144: trailing whitespace ;)
  * the cancellable is passed into all functions and unreffed in dispose()
    is the cancellable cancelled on unref or do we need to do that explicitely?
    (I can't find anything in the docs)

dbus-listener.h:
  * 50: the signal name is overly complicated (it doesn't need to be namespaced
    to the class)
  * indicator_power_dbus_listener_new is declared but not defined in the .c

device.c:
  * class_init: I prefer saving all pspecs in a static array and installing
    them all at once with g_object_class_install_properties. This also allows
    using g_object_notify_by_pspec
  * finalize doesn't chain up to the parent class
  * get/set_property:
     - use G_OBJECT_WARN_INVALID_PROPERTY_ID in the 'default' switch case
     - PROP_ICON is not handled
     - kind and state should check for sane input values
  * 260 ff: I don't think we can use Richard's code (indicators are CA, right?)
  * indicator_power_device_new_from_variant: check whether the input variant
    has the correct type before calling g_variant_get
  * 298: reference functions with 'function_name()' instead of #function_name
    in doc strings

device.h:
  * 43 ff: no need to namespace gobject properties (tbh, I wouldn't even
    #define them, but simply use the strings)

indicator-power.c:
  * 119: ah, that's why you didn't notice the implementation of
    indicator_power_dbus_listener_new was missing :)
  * ref the floating widgets in the private struct
    (just something I noticed, it has nothing to do with this work)

indicator-power.h:
  * device.h include is superfluous

test/test-dbus-{listener,device}.cc:
  * ensure_glib_initalized: g_type_init can be called multiple times

[1] http://developer.gnome.org/gtk-doc-manual/stable/documenting_symbols.html.en
    Section 3.3.4

review: Needs Fixing
Revision history for this message
Charles Kerr (charlesk) wrote :

Lars, thanks for the great review!

> any reason you're using noinst_HEADERS instead of listing the headers
> in the libraries sources? (the latter is recommended for programs and
> convenience libs in the automake docs)

Fixed r204

> dbus-listener.c
>
> 305: g_signal_new is passed one too many arguments. Please add the
> docstring with the number and names of parameters to it [1]

Fixed r205

> dispose() is missing g_bus_unwatch_name (priv->watcher_id)

Fixed r206

> get_devices_cb:144: trailing whitespace ;)

Fixed r207

> the cancellable is passed into all functions and unreffed in dispose()
> is the cancellable cancelled on unref or do we need to do that explicitely?
> (I can't find anything in the docs)

This is a great catch. Looking at the gio code, my assumption was wrong,
it needs to be done explicitly.

Fixed r208

> dbus-listener.h:
> * 50: the signal name is overly complicated (it doesn't need to be namespaced
> to the class)

Fixed r209

> * indicator_power_dbus_listener_new is declared but not defined in the .c

Fixed r210

> device.c:
> class_init: I prefer saving all pspecs in a static array and installing
> them all at once with g_object_class_install_properties. This also allows
> using g_object_notify_by_pspec

Interesting, I don't see that in any of the other indicator code. TIL.

Changed r211

> * finalize doesn't chain up to the parent class

Fixed r212

> * get/set_property:
> - use G_OBJECT_WARN_INVALID_PROPERTY_ID in the 'default' switch case

Fixed r213

> PROP_ICON is not handled

PROP_ICON was cruft, removed r211

> kind and state should check for sane input values

This is already done by glib's plumbing because the pspec defined the sane range. (No change)

> 260 ff: I don't think we can use Richard's code (indicators are CA, right?)

Before my refactoring, i-power was already doing this. One difference is now I'm giving proper attribution. (No change, but maybe a ted question?)

> indicator_power_device_new_from_variant: check whether the input variant has the correct type before calling g_variant_get

Fixed r214.

> 298: reference functions with 'function_name()' instead of #function_name in doc strings

Fixed r215.

> device.h: 43 ff: no need to namespace gobject properties (tbh, I wouldn't even #define them, but simply use the strings)

Fixed r216.

However I've kept the #defines since that idiom catches misspelled keys at compile time...

> indicator-power.c:
> * ref the floating widgets in the private struct
> (just something I noticed, it has nothing to do with this work)

Agreed, but unchanged for this pass...

> indicator-power.h:
> * device.h include is superfluous

Fixed r217

> test/test-dbus-{listener,device}.cc:
> * ensure_glib_initalized: g_type_init can be called multiple times

I don't think this is correct. Are you sure?

204. By Charles Kerr

move the header files from noinst_HEADERS to libpower_la_SOURCES

205. By Charles Kerr

add a GTK-Doc signal comment block for indictor-power-dbus-listener's enumerated signal

206. By Charles Kerr

add g_bus_unwatch_name() to watcher's dispose() method

207. By Charles Kerr

remove trailing whitespace

208. By Charles Kerr

if self->cancellable is non-NULL in dispose(), pass it to g_cancellable_cancel() before clearing the listener's reference

209. By Charles Kerr

simplify the devices-enumerated signal's name

210. By Charles Kerr

remove prototype for indicator_power_dbus_listener_new() since it's not needed/used

211. By Charles Kerr

in IndicatorPowerDevice's class init function, use g_object_class_install_properties() instead of installing each property separately.

212. By Charles Kerr

IndicatorObjectDevice's finalize() function needs to chain up to the parent class.

213. By Charles Kerr

add G_OBJECT_WARN_INVALID_PROPERTY_ID for the 'default' switch case in Device's get/set property methods

214. By Charles Kerr

In indicator_power_device_new_from_variant(), check whether the input variant has the correct type before using it.

215. By Charles Kerr

For GTK-Doc, reference functions with function_name() instead of #function_name

216. By Charles Kerr

simplify the Device properties' name strings

217. By Charles Kerr

remove superfluous #include

218. By Charles Kerr

reimplement indicator_power_device_get_icon_names() since our CA is incompatible with reusing code from GSD.

Revision history for this message
Lars Karlitski (larsu) wrote :

Thanks for the quick fixes!

On 06/06/2012 10:28 PM, Charles Kerr wrote:
>> the cancellable is passed into all functions and unreffed in dispose()
>> is the cancellable cancelled on unref or do we need to do that explicitely?
>> (I can't find anything in the docs)
>
> This is a great catch. Looking at the gio code, my assumption was wrong,
> it needs to be done explicitly.
>
> Fixed r208

Thanks for checking.

> [...]
>> kind and state should check for sane input values
>
> This is already done by glib's plumbing because the pspec defined the sane range. (No change)

You're right of course. Sorry.

>> 260 ff: I don't think we can use Richard's code (indicators are CA, right?)
>
> Before my refactoring, i-power was already doing this. One difference is now I'm giving proper attribution. (No change, but maybe a ted question?)

Definitely a Ted question.

>> indicator_power_device_new_from_variant: check whether the input variant has the correct type before calling g_variant_get
>
> Fixed r214.

Hm, I was thinking more along the lines of

  g_variant_is_of_type (v, G_VARIANT_TYPE ("(susdut)"));

The fix in r214 only checks for a tuple with the correct number of elements.

>> test/test-dbus-{listener,device}.cc:
>> * ensure_glib_initalized: g_type_init can be called multiple times
>
> I don't think this is correct. Are you sure?

I'm not sure. Actually, I think you might be right.

219. By Charles Kerr

improve the variant sanity tests in indicator_power_device_new_from_variant()

220. By Charles Kerr

remove some dead code.

221. By Charles Kerr

disable test-dbus-listener for now

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches