[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kcwsh] tests: add old test case
From: Patrick Spendrin <ps_ml () gmx ! de>
Date: 2015-11-30 13:09:35
Message-ID: E1a3OD1-0002um-5B () scm ! kde ! org
[Download RAW message or body]
Git commit 6097809c366a79cd0173e0aecbf490d4a1cb6a49 by Patrick Spendrin.
Committed on 30/11/2015 at 13:08.
Pushed by sengels into branch 'master'.
add old test case
M +3 -0 tests/CMakeLists.txt
A +100 -0 tests/processtester.cpp [License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/kcwsh/6097809c366a79cd0173e0aecbf490d4a1cb6a49
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7246da8..ea3b264 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -5,9 +5,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# simple applications that provoke a specific behaviour
add_executable(scrolltester scrolltester.cpp)
add_executable(titletester titletester.cpp)
+add_executable(processtester processtester.cpp)
+target_link_libraries(processtester kcw)
add_executable(terminaltest terminaltest.cpp)
target_link_libraries(terminaltest kcwsh)
add_test(NAME simpletest COMMAND terminaltest simple echo)
add_test(NAME titletest COMMAND terminaltest title $<TARGET_FILE:titletester> )
add_test(NAME resizetest COMMAND terminaltest resize echo)
+add_test(NAME processtest COMMAND terminaltest process $<TARGET_FILE:processtester>)
diff --git a/tests/processtester.cpp b/tests/processtester.cpp
new file mode 100644
index 0000000..e76e874
--- /dev/null
+++ b/tests/processtester.cpp
@@ -0,0 +1,100 @@
+#include <iostream>
+#include <vector>
+#include <string>
+
+#include <windows.h>
+
+#include <kcweventloop.h>
+#include <kcwprocess.h>
+
+using namespace std;
+
+class ProcessTest : public KcwEventLoop {
+ public:
+ ProcessTest() : m_runningProcesses(0) {}
+ ~ProcessTest() {
+ while(!m_processes.empty()) {
+ delete m_processes.back();
+ m_processes.pop_back();
+ }
+ }
+ void case1(const wstring& executable) {
+ KcwProcess *p1 = new KcwProcess;
+ p1->setCmd(executable + L" " + L" stop");
+ p1->setIsStartedAsPaused(true); p1->setStartupAsHidden();
+ p1->start();
+ addCallback(p1->process(), CB(processFinished));
+ p1->resume();
+ m_runningProcesses++;
+ m_processes.push_back(p1);
+ Sleep(1000);
+ KcwProcess *p2 = new KcwProcess;
+ p2->setCmd(executable + L" " + L" fork");
+ p2->setIsStartedAsPaused(true); p2->setStartupAsHidden();
+ p2->start();
+ addCallback(p2->process(), CB(processFinished));
+ p2->resume();
+ m_runningProcesses++;
+ m_processes.push_back(p2);
+ }
+
+ void case2fork(const wstring& executable) {
+ KcwProcess *p1 = new KcwProcess;
+ p1->setCmd(executable + L" " + L" stop");
+ p1->setIsStartedAsPaused(true); p1->setStartupAsHidden();
+ p1->start();
+ addCallback(p1->process(), CB(processFinished));
+ p1->resume();
+ m_runningProcesses++;
+ m_processes.push_back(p1);
+ Sleep(1000);
+ KcwProcess *p2 = new KcwProcess;
+ p2->setCmd(executable + L" " + L" stop");
+ p2->setIsStartedAsPaused(true); p2->setStartupAsHidden();
+ p2->start();
+ addCallback(p2->process(), CB(processFinished));
+ p2->resume();
+ m_runningProcesses++;
+ m_processes.push_back(p2);
+ }
+
+ KCW_CALLBACK(ProcessTest, processFinished);
+
+ vector<KcwProcess*> m_processes;
+ int m_runningProcesses;
+};
+
+void ProcessTest::processFinished() {
+ if(!(m_runningProcesses--)) quit();
+}
+
+int main() {
+ int argc;
+ wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+ vector<wstring> args;
+ for(int i = 0; i < argc; i++) args.push_back(wstring(argv[i]));
+ wcout << "another process called" << endl;
+ ProcessTest l;
+ switch(argc) {
+ case 1: l.case1(args[0]); break;
+ case 2: {
+ if(args[1] == L"stop") {
+ Sleep(5000);
+ return 0;
+ } else if(args[1] == L"fork") {
+ l.case2fork(args[0]); break;
+ return 0;
+ } else {
+ return 0;
+ }
+ break;
+ }
+ default: {
+ wcout << L"test executable for kcwsh, plz read source code" << endl;
+ return -1;
+ }
+ };
+ l.exec();
+ Sleep(1000);
+ return 0;
+}
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic