Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Linux] add MockSignalHandler for testing GObject signals - #32650

Merged
fluttergithubbot merged 2 commits into
flutter-team-archive:mainfrom
jpnurmi:mock-signal-handler
Apr 14, 2022
Merged

fluttergithubbot merged 2 commits into
flutter-team-archive:mainfrom
jpnurmi:mock-signal-handler

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Apr 13, 2022 •

Copy link
Copy Markdown
Contributor

This is a preparation step split off from #32618 that will eventually fix light
vs. dark theme detection on Linux (flutter/flutter#101438).

MockSignalHandler is a helper class that allows settings GMock expectations
on GObject signals:

GObject* foo_object = ...;

flutter::testing::MockSignalHandler foo_changed(foo_object, "changed");
EXPECT_SIGNAL(foo_changed).Times(1);

foo_set_something(foo_object, ...);

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

This is a simple helper class that allows settings GMock expectations
on GObject signals:

```c
GObject* foo_object = ...;

flutter::testing::MockSignalHandler foo_changed(foo_object, "changed");
EXPECT_SIGNAL(foo_changed).Times(1);

foo_set_something(foo_object, ...);
```
@jpnurmi
jpnurmi force-pushed the mock-signal-handler branch from 8fd30ea to 9cd5982 Compare April 13, 2022 22:01

@robert-ancell robert-ancell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

g_object_add_weak_pointer() does not assign the initial value
jpnurmi added a commit to jpnurmi/engine that referenced this pull request Apr 14, 2022
@jpnurmi

jpnurmi commented Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

Here's an example of matching and capturing signal arguments:

AtkObject* child2_object = nullptr;
flutter::testing::MockSignalHandler2<gint, AtkObject*> child2_added(
    root_object, "children-changed::add");
EXPECT_SIGNAL2(child2_added, ::testing::Eq(1), ::testing::A<AtkObject*>())
    .WillOnce(::testing::SaveArg<1>(&child2_object));

https://github.com/jpnurmi/engine/blob/1e494de6563df865eb16fe3b2515edafdad702b6/shell/platform/linux/fl_view_accessible_test.cc#L52-L157

@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Apr 14, 2022
@fluttergithubbot
fluttergithubbot merged commit 8d1932a into flutter-team-archive:main Apr 14, 2022
@jpnurmi
jpnurmi deleted the mock-signal-handler branch April 14, 2022 20:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs tests platform-linux waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Development

Successfully merging this pull request may close these issues.

4 participants