-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix key event #101
Open
auxxos
wants to merge
13
commits into
faaxm:master
Choose a base branch
from
auxxos:FixKeyEvent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix key event #101
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d190598
add QtTest example
07f456d
send key events on item level
a821c66
send mouse events on item level
3bd7e1f
Added back all examples
c2d6ba9
Merge branch 'AddQtTest' into FixKeyEvent
5fffe29
Cleanup CMakeFile
cb4ed0a
Enhaced QtTest
daeb844
Add switch to show different test results if we tigger mouse events o…
5499d25
merged changes from QtTest
70e0065
include anyrpc
8528f1e
adapted formatting
b15f639
Merge branch 'AddQtTest' into FixKeyEvent
c621f59
remove gitignore entry for editor files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.idea | ||
build | ||
dep-libs | ||
CMakeLists.txt.user | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(QtTestExample VERSION 1.0 LANGUAGES CXX) | ||
|
||
enable_testing() | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(AnyRPC REQUIRED) | ||
find_package(Qt${SPIX_QT_MAJOR} REQUIRED COMPONENTS Test Quick) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include_directories(${AnyRPC_INCLUDE_DIRS}) | ||
|
||
add_executable(QtTestExample tst_test.cpp) | ||
add_test(NAME QtTestExample COMMAND QtTestExample) | ||
|
||
target_link_libraries(QtTestExample PRIVATE | ||
Qt${SPIX_QT_MAJOR}::Test | ||
Spix | ||
|
||
PRIVATE | ||
AnyRPC::anyrpc | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#include <QtTest> | ||
|
||
#include "anyrpc/anyrpc.h" | ||
|
||
#include <memory> | ||
|
||
using namespace anyrpc; | ||
|
||
/** | ||
* @brief Example using QtTest for running test cases against a remote server | ||
* It also contains some handy helper functions to call remote methods. | ||
* | ||
* Run e.g. the RemoteCtrl application as the application under test | ||
*/ | ||
class QtTestExample : public QObject { | ||
Q_OBJECT | ||
|
||
std::shared_ptr<XmlHttpClient> client; | ||
|
||
public: | ||
QtTestExample(); | ||
~QtTestExample(); | ||
|
||
private slots: | ||
void initTestCase(); | ||
void cleanupTestCase(); | ||
void test_case1(); | ||
|
||
void waitFor(int time) | ||
{ | ||
Value paramsWait; | ||
Value resultWait; | ||
paramsWait[0] = time; | ||
client->Call("wait", paramsWait, resultWait); | ||
} | ||
|
||
void mouseClick(std::string path) | ||
{ | ||
Value paramsMouse; | ||
Value resultMouse; | ||
paramsMouse[0] = path; | ||
client->Call("mouseClick", paramsMouse, resultMouse); | ||
waitFor(500); | ||
} | ||
|
||
void screenshot(std::string path, std::string filepath, bool wait = true, bool compare = true) | ||
{ | ||
Value params; | ||
Value result; | ||
params[0] = path; | ||
params[1] = filepath; | ||
client->Call("takeScreenshot", params, result); | ||
} | ||
|
||
void setProperty(std::string path, std::string field, std::string value) | ||
{ | ||
Value params; | ||
Value result; | ||
params[0] = path; | ||
params[1] = field; | ||
params[2] = value; | ||
client->Call("setStringProperty", params, result); | ||
} | ||
|
||
QString getProperty(std::string path, std::string field) | ||
{ | ||
Value params; | ||
Value result; | ||
params[0] = path; | ||
params[1] = field; | ||
client->Call("getStringProperty", params, result); | ||
|
||
return QString::fromStdString(result.GetString()); | ||
} | ||
|
||
void invokeMethod(std::string path, std::string field, const std::vector<std::string> functionParameter) | ||
{ | ||
Value params; | ||
Value result; | ||
|
||
Value parameters; | ||
parameters.SetArray(functionParameter.size()); | ||
for (int i = 0; i < functionParameter.size(); ++i) { | ||
parameters[i] = functionParameter.at(i); | ||
} | ||
|
||
params[0] = path; | ||
params[1] = field; | ||
params[2] = parameters; | ||
client->Call("invokeMethod", params, result); | ||
} | ||
}; | ||
|
||
QtTestExample::QtTestExample() | ||
{ | ||
} | ||
|
||
QtTestExample::~QtTestExample() | ||
{ | ||
} | ||
|
||
void QtTestExample::initTestCase() | ||
{ | ||
client = std::make_shared<anyrpc::XmlHttpClient>(); | ||
client->SetServer("127.0.0.1", 9000); | ||
client->SetTimeout(10000); | ||
} | ||
|
||
void QtTestExample::cleanupTestCase() | ||
{ | ||
} | ||
|
||
void QtTestExample::test_case1() | ||
{ | ||
setProperty("mainWindow/results", "text", ""); | ||
|
||
mouseClick("mainWindow/Button_1"); | ||
waitFor(500); | ||
mouseClick("mainWindow/Button_2"); | ||
waitFor(500); | ||
|
||
// in the "old" variant, this call also triggers mouseArea_2 | ||
// this is somehow correct, because the mouse area is the top component, | ||
// but sometimes we do not want to trigger the top most component in test cases | ||
mouseClick("mainWindow/Button_3"); | ||
waitFor(500); | ||
mouseClick("mainWindow/Button_4"); | ||
waitFor(500); | ||
|
||
mouseClick("mainWindow/mouseArea_1"); | ||
waitFor(500); | ||
mouseClick("mainWindow/mouseArea_2"); | ||
waitFor(500); | ||
|
||
auto resultText = getProperty("mainWindow/results", "text"); | ||
std::cout << resultText.toStdString() << std::endl; | ||
|
||
QCOMPARE(resultText, | ||
"Button 1 clicked\nButton 2 clicked\nButton 3 clicked\nButton 4 clicked\nMouseArea 1 clicked\nMouseArea 2 " | ||
"clicked"); | ||
} | ||
|
||
QTEST_APPLESS_MAIN(QtTestExample) | ||
|
||
#include "tst_test.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add any non project files to the .gitignore. There is already more in there than there should be actually. For files created by your editor, it is better to use a local .gitignore file: https://gist.github.com/subfuzion/db7f57fff2fb6998a16c