Unit test a bunch of scripted effects
ClosedPublic

Authored by davidedmundson on Jul 30 2018, 11:58 AM.

Details

Summary

Ready for QJSEngine port and upcoming other fixes.
Split as it makes it easier to do any before/after testing.

Test Plan

All tests pass with the current QScriptEngine
Verified expected API against a wiki page and current code.

Diff Detail

Repository
R108 KWin
Branch
scripting_unit_tests
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 1367
Build 1385: arc lint + arc unit
Restricted Application added a project: KWin. · View Herald TranscriptJul 30 2018, 11:58 AM
Restricted Application added a subscriber: kwin. · View Herald Transcript
davidedmundson requested review of this revision.Jul 30 2018, 11:58 AM
broulik added inline comments.
autotests/integration/effects/scripted_effects_test.cpp
302

This is flaky, fails every second time getting 201 instead of 200. (Javascript…)

zzag added a subscriber: zzag.Jul 30 2018, 12:56 PM
zzag added inline comments.
autotests/integration/effects/scripted_effects_test.cpp
25–35

Please sort includes.

56

Indent it?

Also, a question: why some people don't indent Q_OBJECT, Q_PROPERTY, etc? Is there some reason?

73

Please put '{' on a new line.

85

auto *script

113

That's not really obvious way to load effects so please add a comment what's going on here. :-)

166

auto *e

177

Please keep '*'. In some cases, '*' matters.

184

Please use QStringLiteral.

298

const auto state or even better const AniMap state.

302

You don't take into account that compositeTimer can be triggered during testing. Probably, you should subtract time, e.g.

QCOMPARE(animationsForWindow[0].duration - animationsForWindow[0].time, 200);
zzag added inline comments.Jul 30 2018, 1:04 PM
autotests/integration/effects/scripted_effects_test.cpp
302

Still, not sure if it's right (to subtract time). retarget is a little bit interesting...

davidedmundson marked 7 inline comments as done.Jul 30 2018, 1:32 PM
davidedmundson added inline comments.
autotests/integration/effects/scripted_effects_test.cpp
56

Also, a question: why some people don't indent Q_OBJECT, Q_PROPERTY, etc? Is there some reason?

No reason.

184

It's not going to do speed optimisations in unit tests

302

Whilst storing ints in doubles (which JS will do) can lead to loss, the first 2^53 values will always be correct. 200 shouldn't get corrupted anywhere.

Timer being the cause makes more sense, I'm running the event loop during renderAndWaitForShown and showing will be after the window is added.

In retarget: anim->duration = anim->time + newRemainingTime;

There's no event loop after we read the first values, so offsetting should be easy.

davidedmundson marked 2 inline comments as done.

ZZag comments

zzag added a comment.EditedJul 30 2018, 2:24 PM

Some small nitpicks... Other than that, I think this change is pretty good.

Also, some reasons for keeping * and & when using auto:
(a) it improves readability
(b) as I said previously, in some cases, * matters, e.g.

int x = 42;

const auto foo = &x;
*foo = 43; // totally fine, foo of type int* const

const auto *bar = &x;
*bar = 43; // compilation error, bar is of type const int*

In most cases, we want to have the latter, not the former. If one wants to have a const pointer to something, then he/she needs to say it explicitly, e.g.

auto *const foo = &x;
autotests/integration/effects/scripted_effects_test.cpp
39–41

Sort them too.

47–48

Dup.

197

auto *

200

auto *

240

auto *. (It's QAction*, right? I use vim, so it's a little bit problematic to deduce type of action)

287

Please use concrete type here too.

davidedmundson marked 7 inline comments as done.

Auto changes

We need to start a thread on frameworks-devel defining KDE's coding standard use of auto. I've made the changes for now but it's rather frustrating to try and follow non-defined policies.

Personally, I fully support being explicit with type hints when there's overloads or when you want const references, but being explicit for the common T* case doesn't help anything.
Also I don't really buy that being explicit is needed for readability given we allow foo()->bar() without interim variables.

but I'm happy to follow whatever

We need to start a thread on frameworks-devel defining KDE's coding standard use of auto. I've made the changes for now but it's rather frustrating to try and follow non-defined policies.

Personally, I fully support being explicit with type hints when there's overloads or when you want const references, but being explicit for the common T* case doesn't help anything.
Also I don't really buy that being explicit is needed for readability given we allow foo()->bar() without interim variables.

but I'm happy to follow whatever

I agree with David. I'm only explicit with const, * or & if it is needed. So in most cases it is just auto.

zzag added a comment.Jul 31 2018, 8:11 AM

We need to start a thread on frameworks-devel defining KDE's coding standard use of auto. I've made the changes for now but it's rather frustrating to try and follow non-defined policies.

+1. Also, maybe, there should be some rules for using auto, because currently it's overused.

Personally, I fully support being explicit with type hints when there's overloads or when you want const references, but being explicit for the common T* case doesn't help anything.
Also I don't really buy that being explicit is needed for readability given we allow foo()->bar() without interim variables.

I think that would be the case only for types that are used very often. E.g. if we're inside of QWidget, I think that's fine to have the following piece of code

void Widget::painEvent(QPaintEvent *e)
{
    ...
    const QPoint center = rect().center();
    ...
}

If auto wasn't overused, I would agree with you too (about readability), because in most cases it would be overkill:

auto *bar = static_cast<int *>(foo.data());

But even if it wasn't overused, I still would prefer to keep * because of consistency:

int x = 42;

const auto *foo = &x;

auto bar = &x; // ???

and because it constrains variables to raw pointers.

Anyway, we got our discussion a little bit off-topic.

but I'm happy to follow whatever

Also, if you feel that omitting * would be better, omit them. As you said, we don't have any policies on auto. Should we use it with new? Should we use it with reinterpret_cast? Should we use it with static_cast? Should we use auto in the following scenario auto foo = bar();?

Using auto with static_cast and new is very common so I think it should go.

zzag accepted this revision.EditedJul 31 2018, 8:32 AM

I hope that I have enough rights to accept this patch after doing some work on effects.

Some comments:

  • please add a new line between static const QString s_socketName = QStringLiteral("wayland_test_effects_scripts-0"); and class ScriptedEffectsTest : public QObject
  • tests have test prefix
  • please put a whitespace between // and proceeding comment
  • tests usually start with // this test verifies ...
  • if you think it would be better to omit *, omit them
  • also, it would be great to prepend "[autotests]" to the title

... and upcoming other fixes.

So, with the "new" API, scripted effects will be able to do full screen effects, right?

This revision is now accepted and ready to land.Jul 31 2018, 8:32 AM

I hope that I have enough rights to accept this patch after doing some work on effects.

Sure

So, with the "new" API, scripted effects will be able to do full screen effects, right?

Not as a direct result of the QJSEngine port, but we should have something for 5.14 to handle that.

This revision was automatically updated to reflect the committed changes.