summaryrefslogtreecommitdiff
path: root/standalone-clients
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2012-02-06 12:42:50 -0500
committerTarmac <>2012-02-06 12:42:50 -0500
commitf4034244f9ea2a2d9231a058921f5b81e897b75f (patch)
tree886bab45a8447a0029debcd6c558b035b92498b1 /standalone-clients
parent7426e5507aae1180e3407e96a8765674f475f568 (diff)
parent7fae0e8d124aded47f94480e916a490bb4558798 (diff)
Fixed the drawing of the radios or checkmarks quicklist menu items
When using quicklist menu-items containing radios or checkmarks, unity draws them incorrectly. First of all, the Active logic is inverted (unactive items were marked, while active were not), then the disabled status was causing an incorrect drawing. This is an example code that underlines the issue: http://paste.ubuntu.com/788515/ You can see the issue in this screenshot: http://go.3v1n0.net/vhgofi This branch fixes these issues, and this is the expected result: http://ubuntuone.com/5avZ10Lrd8MFxnBmRIOJfQ (of course now it works well also when an item is prelighted) I've not added a manual test since for the graphic nature of the issue, I guess it's hard to automatically test it (and autopilot doesn't help at all, clearly). So, let me know if this is ok.. Fixes: https://bugs.launchpad.net/bugs/910286. Approved by Andrea Azzarone. (bzr r1901)
Diffstat (limited to 'standalone-clients')
-rw-r--r--standalone-clients/CMakeLists.txt24
-rw-r--r--standalone-clients/TestFilterBar.cpp2
-rw-r--r--standalone-clients/TestFilters.cpp10
-rw-r--r--standalone-clients/nux_automated_test_framework.cpp461
-rw-r--r--standalone-clients/nux_automated_test_framework.h127
-rw-r--r--standalone-clients/nux_test_framework.cpp129
-rw-r--r--standalone-clients/nux_test_framework.h61
-rw-r--r--standalone-clients/ui/TestQuicklist.cpp428
-rw-r--r--standalone-clients/ui/TestQuicklistVisuals.cpp52
9 files changed, 1062 insertions, 232 deletions
diff --git a/standalone-clients/CMakeLists.txt b/standalone-clients/CMakeLists.txt
index 1e2092e55..3345dc4e3 100644
--- a/standalone-clients/CMakeLists.txt
+++ b/standalone-clients/CMakeLists.txt
@@ -8,7 +8,7 @@ set(UNITY_SRC ../plugins/unityshell/src)
# Unit tests
#
find_package (PkgConfig)
-set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0")
+set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0 xtst")
pkg_check_modules (TEST_UNIT_DEPS REQUIRED ${TEST_DEPS})
set (TESTDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
@@ -26,7 +26,7 @@ set (CFLAGS
)
add_definitions (${CFLAGS})
-set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU")
+set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU -lXtst")
link_libraries (${LIBS})
set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})
@@ -182,6 +182,8 @@ add_executable (switcher
${UNITY_SRC}/WindowManager.cpp
${UNITY_SRC}/IconRenderer.cpp
${UNITY_SRC}/IconRenderer.h
+ ${UNITY_SRC}/Introspectable.cpp
+ ${UNITY_SRC}/Introspectable.h
${UNITY_SRC}/MockLauncherIcon.h
${UNITY_SRC}/BackgroundEffectHelper.h
${UNITY_SRC}/BackgroundEffectHelper.cpp
@@ -255,6 +257,8 @@ add_executable (launcher
${UNITY_SRC}/BackgroundEffectHelper.cpp
${UNITY_SRC}/StaticCairoText.cpp
${UNITY_SRC}/StaticCairoText.h
+ ${UNITY_SRC}/SoftwareCenterLauncherIcon.cpp
+ ${UNITY_SRC}/SoftwareCenterLauncherIcon.h
${UNITY_SRC}/Introspectable.cpp
${UNITY_SRC}/Introspectable.h
${UNITY_SRC}/QuicklistMenuItem.cpp
@@ -290,8 +294,10 @@ add_dependencies (keyutil unity-core-${UNITY_API_VERSION})
add_executable (quicklist
ui/TestQuicklist.cpp
- ui/EventFaker.cpp
- ui/EventFaker.h
+ nux_test_framework.cpp
+ nux_test_framework.h
+ nux_automated_test_framework.cpp
+ nux_automated_test_framework.h
${UNITY_SRC}/Introspectable.cpp
${UNITY_SRC}/Introspectable.h
${UNITY_SRC}/QuicklistMenuItem.cpp
@@ -351,16 +357,18 @@ add_dependencies(filters unity-core-${UNITY_API_VERSION})
add_executable (filter-bar
TestFilterBar.cpp
+ ${UNITY_SRC}/FilterAllButton.cpp
+ ${UNITY_SRC}/FilterBar.cpp
+ ${UNITY_SRC}/FilterBasicButton.cpp
${UNITY_SRC}/FilterExpanderLabel.cpp
${UNITY_SRC}/FilterFactory.cpp
- ${UNITY_SRC}/FilterBasicButton.cpp
- ${UNITY_SRC}/FilterRatingsButton.cpp
- ${UNITY_SRC}/FilterRatingsWidget.cpp
${UNITY_SRC}/FilterMultiRangeWidget.cpp
${UNITY_SRC}/FilterMultiRangeButton.cpp
${UNITY_SRC}/FilterGenreButton.cpp
${UNITY_SRC}/FilterGenreWidget.cpp
- ${UNITY_SRC}/FilterBar.cpp
+ ${UNITY_SRC}/FilterRatingsButton.cpp
+ ${UNITY_SRC}/FilterRatingsWidget.cpp
+ ${UNITY_SRC}/FilterWidget.cpp
${UNITY_SRC}/DashStyle.cpp
${UNITY_SRC}/JSONParser.cpp
)
diff --git a/standalone-clients/TestFilterBar.cpp b/standalone-clients/TestFilterBar.cpp
index 020a4ffb7..e12e2dd06 100644
--- a/standalone-clients/TestFilterBar.cpp
+++ b/standalone-clients/TestFilterBar.cpp
@@ -53,7 +53,7 @@ TestRunner::~TestRunner ()
void TestRunner::Init ()
{
- unity::FilterBar *filterbar = new unity::FilterBar(NUX_TRACKER_LOCATION);
+ auto *filterbar = new unity::dash::FilterBar(NUX_TRACKER_LOCATION);
layout = new nux::VLayout(NUX_TRACKER_LOCATION);
diff --git a/standalone-clients/TestFilters.cpp b/standalone-clients/TestFilters.cpp
index 1e4689b13..cddf2ac0d 100644
--- a/standalone-clients/TestFilters.cpp
+++ b/standalone-clients/TestFilters.cpp
@@ -57,13 +57,13 @@ TestRunner::~TestRunner ()
void TestRunner::Init ()
{
- unity::FilterBasicButton *button = new unity::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION);
- unity::FilterRatingsWidget *ratings = new unity::FilterRatingsWidget (NUX_TRACKER_LOCATION);
- unity::FilterGenreButton *genre_button = new unity::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION);
+ auto *button = new unity::dash::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION);
+ auto *ratings = new unity::dash::FilterRatingsWidget (NUX_TRACKER_LOCATION);
+ auto *genre_button = new unity::dash::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION);
- unity::FilterGenre *genre = new unity::FilterGenre(NUX_TRACKER_LOCATION);
+ auto *genre = new unity::dash::FilterGenre(3, NUX_TRACKER_LOCATION);
- unity::FilterMultiRange *multi_range = new unity::FilterMultiRange (NUX_TRACKER_LOCATION);
+ auto *multi_range = new unity::dash::FilterMultiRange (NUX_TRACKER_LOCATION);
layout = new nux::VLayout(NUX_TRACKER_LOCATION);
diff --git a/standalone-clients/nux_automated_test_framework.cpp b/standalone-clients/nux_automated_test_framework.cpp
new file mode 100644
index 000000000..970db58ea
--- /dev/null
+++ b/standalone-clients/nux_automated_test_framework.cpp
@@ -0,0 +1,461 @@
+/*
+ * Copyright 2010 Inalogic Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
+ *
+ */
+
+#include "Nux/Nux.h"
+#include <X11/extensions/XTest.h>
+#include <X11/keysym.h>
+#include "nux_automated_test_framework.h"
+
+
+int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; // milliseconds
+int NuxAutomatedTestFramework::mouse_click_time_span = 300; // milliseconds
+int NuxAutomatedTestFramework::minimum_sleep_time = 600; // milliseconds
+int NuxAutomatedTestFramework::safety_border_inside_view = 1; // pixels
+
+NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread)
+{
+ ready_to_start_ = false;
+ display_ = NULL;
+ window_thread_ = window_thread;
+ window_x_ = 0;
+ window_y_ = 0;
+ window_width_ = 0;
+ window_height_ = 0;
+ terminate_when_test_over_ = false;
+}
+
+NuxAutomatedTestFramework::~NuxAutomatedTestFramework()
+{
+ XCloseDisplay(display_);
+}
+
+void NuxAutomatedTestFramework::SetTerminateProgramWhenDone(bool terminate)
+{
+ terminate_when_test_over_ = terminate;
+}
+
+bool NuxAutomatedTestFramework::WhenDoneTerminateProgram()
+{
+ return terminate_when_test_over_;
+}
+
+void NuxAutomatedTestFramework::Startup()
+{
+ display_ = XOpenDisplay(NULL);
+ nux::Geometry rect = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
+ //nuxDebugMsg("Window geometry: (%d, %d, %d, %d)", rect.x, rect.y, rect.width, rect.height);
+
+ window_x_ = rect.x;
+ window_y_ = rect.y;
+ window_width_ = rect.width;
+ window_height_ = rect.height;
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseClick(nux::View *view, int button)
+{
+ nux::Rect r;
+ if (view)
+ {
+ r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2);
+ }
+ else
+ {
+ r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
+ r.OffsetPosition(r.width/2, r.height/2);
+ }
+
+ SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
+ SendFakeMouseEvent(button, true);
+ nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span);
+ SendFakeMouseEvent(button, false);
+
+ XSync(display_, False);
+ nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseDoubleClick(nux::View *view, int button)
+{
+ nux::Rect r;
+ if (view)
+ {
+ r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2);
+ }
+ else
+ {
+ r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
+ r.OffsetPosition(r.width/2, r.height/2);
+ }
+
+ // Send the mouse to the center of the view
+ SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
+
+ XTestFakeButtonEvent(display_, button, true, CurrentTime);
+ XTestFakeButtonEvent(display_, button, false, CurrentTime);
+ XTestFakeButtonEvent(display_, button, true, CurrentTime);
+ XTestFakeButtonEvent(display_, button, false, CurrentTime);
+ XSync(display_, False);
+ nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button)
+{
+ XEvent event;
+ /* Get the current pointer position */
+ XQueryPointer(display_, RootWindow(display_, 0),
+ &event.xbutton.root, &event.xbutton.window,
+ &event.xbutton.x_root, &event.xbutton.y_root,
+ &event.xbutton.x, &event.xbutton.y,
+ &event.xbutton.state);
+
+ int current_x = event.xbutton.x - window_x_;
+ int current_y = event.xbutton.y - window_y_;
+
+ nux::Rect r = view->GetAbsoluteGeometry();
+
+ if (!r.IsInside(nux::Point(current_x, current_y)))
+ {
+ // The mouse pointer is not inside the view.
+ // Move the mouse pointer to the center of the view.
+ r.OffsetPosition(window_x_, window_y_);
+
+ // Go to the center of the view
+ int view_center_x = r.x + r.width/2;
+ int view_center_y = r.y + r.height/2;
+ SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
+ nux::SleepForMilliseconds(minimum_sleep_time);
+ }
+ SendFakeMouseEvent(button, true);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseUp(nux::View *view, int button)
+{
+ // nux::Rect r = view->GetAbsoluteGeometry();
+ // r.OffsetPosition(window_x_, window_y_);
+
+ // int view_center_x = r.x + r.width/2;
+ // int view_center_y = r.y + r.height/2;
+
+ // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000);
+ // nux::SleepForMilliseconds(minimum_sleep_time);
+ SendFakeMouseEvent(button, false);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseDrag(nux::View *view, int button_index, int x0, int y0, int x1, int y1)
+{
+ nux::Rect r0 = view->GetAbsoluteGeometry();
+ nux::Rect r1 = view->GetAbsoluteGeometry();
+ r0.OffsetPosition(window_x_ + x0, window_y_ + y0);
+ r1.OffsetPosition(window_x_ + x1, window_y_ + y1);
+
+ // Go to first point
+ SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span);
+ nux::SleepForMilliseconds(minimum_sleep_time);
+
+ // Mouse down
+ ViewSendMouseDown(view, button_index);
+
+ // Drag to second point
+ SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span);
+ nux::SleepForMilliseconds(minimum_sleep_time);
+
+ // Mouse up
+ ViewSendMouseUp(view, button_index);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionTo(nux::View *view, int x, int y)
+{
+ nux::Rect r;
+ if (view)
+ {
+ r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_ + x, window_y_ + y);
+ }
+ else
+ {
+ r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
+ r.OffsetPosition(x, y);
+ }
+
+ SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionToCenter(nux::View *view)
+{
+ nux::Rect r;
+ if (view)
+ {
+ r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_, window_y_);
+ }
+ else
+ {
+ r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
+ }
+
+ int view_center_x = r.x + r.width/2;
+ int view_center_y = r.y + r.height/2;
+
+ SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionToTopLeft(nux::View *view)
+{
+ nux::Rect r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_, window_y_);
+
+ SendFakeMouseMotionEvent(r.x + safety_border_inside_view, r.y + safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionToTopRight(nux::View *view)
+{
+ nux::Rect r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_, window_y_);
+
+ SendFakeMouseMotionEvent(r.x + r.width-1, r.y+safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomLeft(nux::View *view)
+{
+ nux::Rect r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_, window_y_);
+
+ SendFakeMouseMotionEvent(r.x+safety_border_inside_view, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomRight(nux::View *view)
+{
+ nux::Rect r = view->GetAbsoluteGeometry();
+ r.OffsetPosition(window_x_, window_y_);
+
+ SendFakeMouseMotionEvent(r.x + r.width-1, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span);
+}
+
+void NuxAutomatedTestFramework::ViewSendChar(const char c)
+{
+ KeySym modifier = 0;
+
+ if ((c >= 'A') && (c <= 'Z'))
+ {
+ modifier = XK_Shift_L;
+ }
+
+ std::string s(1, c);
+ SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
+ nux::SleepForMilliseconds(300);
+}
+
+void NuxAutomatedTestFramework::ViewSendString(const std::string &str)
+{
+ int l = str.length();
+ if (l == 0)
+ return;
+
+ int i = 0;
+
+ while (i < l)
+ {
+ KeySym modifier = 0;
+ char c = str[i++];
+
+ if ((c >= 'A') && (c <= 'Z'))
+ {
+ modifier = XK_Shift_L;
+ }
+
+ std::string s(1, c);
+ SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
+ nux::SleepForMilliseconds(300);
+ }
+}
+
+void NuxAutomatedTestFramework::ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c)
+{
+ KeyCode keycode = 0;
+ KeyCode modcode0 = 0;
+ KeyCode modcode1 = 0;
+ KeyCode modcode2 = 0;
+
+ std::string s(1, c);
+ keycode = XKeysymToKeycode(display_, XStringToKeysym(s.c_str()));
+ XTestGrabControl(display_, True);
+
+ /* Generate modkey press */
+ if (modsym0 != 0)
+ {
+ modcode0 = XKeysymToKeycode(display_, modsym0);
+ XTestFakeKeyEvent(display_, modcode0, True, 0);
+ }
+ if (modsym1 != 0)
+ {
+ modcode1 = XKeysymToKeycode(display_, modsym1);
+ XTestFakeKeyEvent(display_, modcode1, True, 0);
+ }
+ if (modsym2 != 0)
+ {
+ modcode2 = XKeysymToKeycode(display_, modsym2);
+ XTestFakeKeyEvent(display_, modcode2, True, 0);
+ }
+
+ /* Generate regular key press and release */
+ XTestFakeKeyEvent(display_, keycode, True, 0);
+ XTestFakeKeyEvent(display_, keycode, False, 0);
+
+ /* Generate modkey release */
+ if (modsym0 != 0)
+ {
+ XTestFakeKeyEvent(display_, modcode0, False, 0);
+ }
+ if (modsym1 != 0)
+ {
+ XTestFakeKeyEvent(display_, modcode1, False, 0);
+ }
+ if (modsym2 != 0)
+ {
+ XTestFakeKeyEvent(display_, modcode2, False, 0);
+ }
+
+ XSync(display_, False);
+ XTestGrabControl(display_, False);
+}
+
+void NuxAutomatedTestFramework::ViewSendCtrlA()
+{
+ ViewSendKeyCombo(XK_Control_L, 0, 0, 'a');
+}
+
+void NuxAutomatedTestFramework::ViewSendDelete()
+{
+ SendFakeKeyEvent(XK_Delete, 0);
+}
+
+void NuxAutomatedTestFramework::ViewSendBackspace()
+{
+ SendFakeKeyEvent(XK_BackSpace, 0);
+}
+
+void NuxAutomatedTestFramework::ViewSendEscape()
+{
+ SendFakeKeyEvent(XK_Escape, 0);
+}
+
+void NuxAutomatedTestFramework::ViewSendTab()
+{
+ SendFakeKeyEvent(XK_Tab, 0);
+}
+
+void NuxAutomatedTestFramework::ViewSendReturn()
+{
+ SendFakeKeyEvent(XK_Return, 0);
+}
+
+void NuxAutomatedTestFramework::PutMouseAt(int x, int y)
+{
+ XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
+ XSync(display_, False);
+}
+
+void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym)
+{
+ KeyCode keycode = 0;
+ KeyCode modcode = 0;
+
+ keycode = XKeysymToKeycode(display_, keysym);
+ XTestGrabControl(display_, True);
+
+ /* Generate modkey press */
+ if (modsym != 0)
+ {
+ modcode = XKeysymToKeycode(display_, modsym);
+ XTestFakeKeyEvent(display_, modcode, True, 0);
+ }
+
+ /* Generate regular key press and release */
+ XTestFakeKeyEvent(display_, keycode, True, 0);
+ XTestFakeKeyEvent(display_, keycode, False, 0);
+
+ /* Generate modkey release */
+ if (modsym != 0)
+ {
+ XTestFakeKeyEvent(display_, modcode, False, 0);
+ }
+
+ XSync(display_, False);
+ XTestGrabControl(display_, False);
+}
+
+void NuxAutomatedTestFramework::SendFakeMouseEvent(int mouse_button_index, bool pressed)
+{
+ XTestFakeButtonEvent(display_, mouse_button_index, pressed, CurrentTime);
+ XSync(display_, False);
+}
+
+void NuxAutomatedTestFramework::SendFakeMouseMotionEvent(int x, int y, int ms_delay)
+{
+ XEvent event;
+ /* Get the current pointer position */
+ XQueryPointer(display_, RootWindow(display_, 0),
+ &event.xbutton.root, &event.xbutton.window,
+ &event.xbutton.x_root, &event.xbutton.y_root,
+ &event.xbutton.x, &event.xbutton.y,
+ &event.xbutton.state);
+
+ int old_x = event.xbutton.x;
+ int old_y = event.xbutton.y;
+
+ int n_iteration = ms_delay / 16.0f;
+
+ //nuxDebugMsg("n_iteration: %d", n_iteration);
+
+ if (n_iteration < 1)
+ {
+ n_iteration = 1;
+ }
+
+ XSync(display_, False);
+
+ for (int i = 0; i < n_iteration; i++)
+ {
+ float t = ((float)i + 1.0f) / n_iteration;
+
+ int cx = (1.0f - t) * old_x + t * x;
+ int cy = (1.0f - t) * old_y + t * y;
+ XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), cx, cy, CurrentTime);
+ XSync(display_, False);
+ usleep(16*1000);
+ }
+
+ XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
+ XSync(display_, False);
+ nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
+}
+
+void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg)
+{
+ if (b)
+ {
+ nuxOkMsg("%s: %s", msg, "Ok");
+ }
+ else
+ {
+ nuxAlertMsg("%s: %s", msg, "Failed");
+ }
+} \ No newline at end of file
diff --git a/standalone-clients/nux_automated_test_framework.h b/standalone-clients/nux_automated_test_framework.h
new file mode 100644
index 000000000..63c9b52d7
--- /dev/null
+++ b/standalone-clients/nux_automated_test_framework.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2010 Inalogic Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
+ *
+ */
+
+#include <X11/extensions/XTest.h>
+#include <X11/keysym.h>
+
+#ifndef NUX_AUTOMATED_TEST_FRAMEWORK_H
+#define NUX_AUTOMATED_TEST_FRAMEWORK_H
+
+class NuxAutomatedTestFramework
+{
+public:
+ NuxAutomatedTestFramework(nux::WindowThread *window_thread);
+ virtual ~NuxAutomatedTestFramework();
+
+ //! Initialize the testing framework.
+ void Startup();
+
+ //! Simulate a mouse click event on a view.
+ /*!
+ Move the mouse to the middle of the view (if it isn't there already) and perform a click event.
+ */
+ void ViewSendMouseClick(nux::View *view, int button);
+ //! Simulate a mouse double click event on a view.
+ /*!
+ Move the mouse to the middle of the view (if it isn't there already) and perform a double click event.
+ */
+ void ViewSendMouseDoubleClick(nux::View *view, int button);
+ //! Simulate a mouse down event on a view.
+ void ViewSendMouseDown(nux::View *view, int button);
+ //! Simulate a mouse up event on a view.
+ void ViewSendMouseUp(nux::View *view, int button);
+ //! Simulate a drag event on a view from (x0, y0) to (x1, y1).
+ void ViewSendMouseDrag(nux::View *view, int button, int x0, int y0, int x1, int y1);
+ //! Simulate mouse motion to (x, y).
+ void ViewSendMouseMotionTo(nux::View *view, int x, int y);
+ //! Simulate mouse motion to the center of a view.
+ void ViewSendMouseMotionToCenter(nux::View *view);
+ //! Simulate mouse motion to the top left corner of a view.
+ void ViewSendMouseMotionToTopLeft(nux::View *view);
+ //! Simulate mouse motion to the top right corner of a view.
+ void ViewSendMouseMotionToTopRight(nux::View *view);
+ //! Simulate mouse motion to the bottom left corner of a view.
+ void ViewSendMouseMotionToBottomLeft(nux::View *view);
+ //! Simulate mouse motion to the bottom right corner of a view.
+ void ViewSendMouseMotionToBottomRight(nux::View *view);
+
+ //! Simulate a key event.
+ void ViewSendChar(const char c);
+ //! Simulate a succession of key events.
+ void ViewSendString(const std::string &str);
+ //! Simulate a key combo.
+ void ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c);
+ //! Simulate Ctrl+a.
+ void ViewSendCtrlA();
+ //! Simulate Delete key.
+ void ViewSendDelete();
+ //! Simulate Backspace key.
+ void ViewSendBackspace();
+ //! Simulate Escape key.
+ void ViewSendEscape();
+ //! Simulate Tab key.
+ void ViewSendTab();
+ //! Simulate Return key.
+ void ViewSendReturn();
+
+ //! Put the mouse pointer anywhere on the display.
+ void PutMouseAt(int x, int y);
+
+ //! Simulate a mouse event.
+ void SendFakeMouseEvent(int mouse_button_index, bool pressed);
+ //! Simulate a key event.
+ void SendFakeKeyEvent(KeySym keysym, KeySym modsym);
+ //! Simulate a mouse motion event.
+ void SendFakeMouseMotionEvent(int x, int y, int ms_delay);
+
+ /*!
+ Set the test thread to terminae the program when testing is over.
+ */
+ void SetTerminateProgramWhenDone(bool terminate);
+ /*!
+ Return true if the test thread is allowed to terminate the program after testing is over.
+ */
+ bool WhenDoneTerminateProgram();
+
+ /*!
+ Print a report message to the console.
+ */
+ void TestReportMsg(bool b, const char* msg);
+
+private:
+ void WindowConfigSignal(int x, int y, int width, int height);
+
+ bool ready_to_start_;
+ Display* display_;
+ nux::WindowThread *window_thread_;
+ int window_x_;
+ int window_y_;
+ int window_width_;
+ int window_height_;
+ bool terminate_when_test_over_;
+
+ static int mouse_motion_time_span; // in milliseconds
+ static int mouse_click_time_span; // in milliseconds
+ static int minimum_sleep_time; // in milliseconds
+ static int safety_border_inside_view; // in pixels
+};
+
+#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H
+
diff --git a/standalone-clients/nux_test_framework.cpp b/standalone-clients/nux_test_framework.cpp
new file mode 100644
index 000000000..f839e169e
--- /dev/null
+++ b/standalone-clients/nux_test_framework.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2010 Inalogic Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
+ *
+ */
+
+#include "Nux/Nux.h"
+#include "Nux/VLayout.h"
+#include "Nux/HLayout.h"
+#include "Nux/WindowThread.h"
+#include "Nux/TextEntry.h"
+#include "nux_test_framework.h"
+
+
+NuxTestFramework::NuxTestFramework(const char* program_name,
+ int window_width,
+ int window_height,
+ int program_life_span)
+{
+ ready_to_go_ = false;
+ window_width_ = window_width;
+ window_height_ = window_height;
+
+ if (window_width_ < 100)
+ window_width_ = 100;
+
+ if (window_height_ < 100)
+ window_height_ = 100;
+
+ timeout_signal_ = NULL;
+ window_thread_ = NULL;
+ program_name_ = program_name;
+ program_life_span_ = program_life_span;
+
+ if (program_life_span_ > 0 && program_life_span_ < 1000)
+ {
+ // Minimum life span is 1 second.
+ program_life_span_ = 1000;
+ }
+}
+
+NuxTestFramework::~NuxTestFramework()
+{
+ if (window_thread_)
+ delete window_thread_;
+}
+
+void NuxTestFramework::Startup()
+{
+ nux::NuxInitialize(0);
+ window_thread_ = nux::CreateGUIThread(program_name_.c_str(), window_width_, window_height_, NULL, NULL, NULL);
+
+ window_thread_->window_configuration.connect(sigc::mem_fun(this, &NuxTestFramework::WaitForConfigureEvent));
+}
+
+void NuxTestFramework::UserInterfaceSetup()
+{
+ // nux::VLayout *MainVLayout = new nux::VLayout(NUX_TRACKER_LOCATION);
+ // nux::TextEntry *text_entry_0 = new nux::TextEntry(TEXT("0123456789abcdefghij"), NUX_TRACKER_LOCATION);
+
+ // MainVLayout->AddView(text_entry_0, 0, nux::eCenter, nux::eFull);
+ // MainVLayout->SetVerticalInternalMargin(10);
+ // MainVLayout->SetContentDistribution(nux::eStackCenter);
+
+ // nux::GetWindowThread()->SetLayout(MainVLayout);
+ // nux::ColorLayer background(nux::Color(0xFF4D4D4D));
+ // window_thread_->SetWindowBackgroundPaintLayer(&background);
+}
+
+void NuxTestFramework::Run()
+{
+ if (window_thread_ == NULL)
+ return;
+
+ if (program_life_span_ > 0)
+ {
+ timeout_signal_ = new nux::TimeOutSignal();
+ timeout_signal_->time_expires.connect(sigc::mem_fun(this, &NuxTestFramework::ProgramExitCall));
+ window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL);
+ }
+
+ window_thread_->Run(NULL);
+}
+
+bool NuxTestFramework::ReadyToGo()
+{
+ return window_thread_;
+}
+
+nux::WindowThread* NuxTestFramework::GetWindowThread()
+{
+ return window_thread_;
+}
+
+void NuxTestFramework::ProgramExitCall(void *data)
+{
+ if (window_thread_)
+ window_thread_->ExitMainLoop();
+}
+
+void NuxTestFramework::WaitForConfigureEvent(int x, int y, int width, int height)
+{
+ ready_to_go_ = true;
+}
+
+
+// int main(int argc, char **argv)
+// {
+// NuxTestFramework test("Text Entry", 300, 300, 3000);
+// test.Startup();
+// test.UserInterfaceSetup();
+// test.Run();
+
+// return 0;
+// }
diff --git a/standalone-clients/nux_test_framework.h b/standalone-clients/nux_test_framework.h
new file mode 100644
index 000000000..59855c986
--- /dev/null
+++ b/standalone-clients/nux_test_framework.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Inalogic Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Jay Taoko <jaytaoko@inalogic.com>
+ *
+ */
+
+#include "Nux/Nux.h"
+#include "Nux/VLayout.h"
+#include "Nux/HLayout.h"
+#include "Nux/WindowThread.h"
+#include "Nux/TextEntry.h"
+
+#ifndef NUXTESTFRAMEWORK_H
+#define NUXTESTFRAMEWORK_H
+
+class NuxTestFramework
+{
+public:
+ NuxTestFramework(const char* program_name, int window_width, int window_height, int program_life_span);
+ virtual ~NuxTestFramework();
+
+ virtual void Startup();
+ virtual void UserInterfaceSetup();
+ virtual void Run();
+
+ bool ReadyToGo();
+
+ nux::WindowThread* GetWindowThread();
+
+public:
+ std::string program_name_;
+ int program_life_span_; //!< The program will auto-terminate after a delay in milliseconds.
+ nux::TimeOutSignal *timeout_signal_;
+
+ nux::WindowThread *window_thread_;
+
+ int window_width_;
+ int window_height_;
+
+private:
+ void ProgramExitCall(void *data);
+ void WaitForConfigureEvent(int x, int y, int width, int height);
+ bool ready_to_go_;
+};
+
+#endif // NUXTESTFRAMEWORK_H
+
diff --git a/standalone-clients/ui/TestQuicklist.cpp b/standalone-clients/ui/TestQuicklist.cpp
index 7b484e5af..75ac309fc 100644
--- a/standalone-clients/ui/TestQuicklist.cpp
+++ b/standalone-clients/ui/TestQuicklist.cpp
@@ -14,11 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Mirco Müller <mirco.mueller@canonical.com>
+ * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
*/
#include <glib.h>
#include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
#include "Nux/Nux.h"
#include "Nux/VLayout.h"
@@ -31,101 +31,175 @@
#include "QuicklistMenuItemCheckmark.h"
#include "QuicklistMenuItemRadio.h"
-#include "EventFaker.h"
-#include <X11/Xlib.h>
+#include "nux_test_framework.h"
+#include "nux_automated_test_framework.h"
#define WIN_WIDTH 400
-#define WIN_HEIGHT 300
+#define WIN_HEIGHT 400
-gboolean gResult[3] = {false, false, false};
+class TestQuicklist: public NuxTestFramework
+{
+public:
+ TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span);
+ ~TestQuicklist();
+
+ virtual void UserInterfaceSetup();
+ int ItemNaturalPosition(QuicklistMenuItem* item);
+ bool HasNthItemActivated(unsigned int index);
+
+ QuicklistView* quicklist_;
+ std::map<QuicklistMenuItem*,bool> activated_;
+
+private:
+ QuicklistMenuItemSeparator* createSeparatorItem();
+ QuicklistMenuItemLabel* createLabelItem(std::string const& label, bool enabled = true);
+ QuicklistMenuItemCheckmark* createCheckmarkItem(std::string const& label, bool enabled, bool checked);
+ QuicklistMenuItemRadio* createRadioItem(std::string const& label, bool enabled, bool checked);
+ void AddItem(QuicklistMenuItem* item);
+
+ void connectToActivatedSignal(DbusmenuMenuitem* item);
+ static void activatedCallback(DbusmenuMenuitem* item, int time, gpointer data);
+
+ std::map<DbusmenuMenuitem*, QuicklistMenuItem*> menus2qitem_;
+};
+
+TestQuicklist::TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span)
+ : NuxTestFramework(program_name, window_width, window_height, program_life_span),
+ quicklist_(nullptr)
+{}
+
+TestQuicklist::~TestQuicklist()
+{
+ if (quicklist_)
+ quicklist_->UnReference();
+}
+
+int TestQuicklist::ItemNaturalPosition(QuicklistMenuItem* item)
+{
+ int pos = 1;
+
+ for (auto it : quicklist_->GetChildren())
+ {
+ if (it == item)
+ return pos;
+
+ if (it->GetItemType() != MENUITEM_TYPE_SEPARATOR)
+ pos++;
+ }
-QuicklistView* gQuicklist = NULL;
-QuicklistMenuItemCheckmark* gCheckmark = NULL;
-QuicklistMenuItemRadio* gRadio = NULL;
-QuicklistMenuItemLabel* gLabel = NULL;
+ return -1;
+}
-void
-activatedCallback (DbusmenuMenuitem* item,
- int time,
- gpointer data)
+bool TestQuicklist::HasNthItemActivated(unsigned int index)
{
- gboolean* result = (gboolean*) data;
+ return activated_[quicklist_->GetNthItems(index)];
+}
- *result = true;
+void TestQuicklist::activatedCallback(DbusmenuMenuitem* item, int time, gpointer data)
+{
+ auto self = static_cast<TestQuicklist*>(data);
+ QuicklistMenuItem* qitem = self->menus2qitem_[item];
+
+ if (!self->activated_[qitem])
+ {
+ self->activated_[qitem] = true;
+ g_debug("Quicklist-item %d activated", self->ItemNaturalPosition(qitem));
+ }
+}
- g_print ("Quicklist-item activated\n");
+void TestQuicklist::connectToActivatedSignal(DbusmenuMenuitem* item)
+{
+ g_signal_connect (item,
+ DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
+ G_CALLBACK (&TestQuicklist::activatedCallback),
+ this);
}
-QuicklistMenuItemCheckmark*
-createCheckmarkItem ()
+QuicklistMenuItemSeparator* TestQuicklist::createSeparatorItem()
{
DbusmenuMenuitem* item = NULL;
- QuicklistMenuItemCheckmark* checkmark = NULL;
+ QuicklistMenuItemSeparator* separator = NULL;
+
+ item = dbusmenu_menuitem_new ();
+
+ dbusmenu_menuitem_property_set_bool (item,
+ DBUSMENU_MENUITEM_PROP_ENABLED,
+ true);
+
+ separator = new QuicklistMenuItemSeparator (item, true);
+ menus2qitem_[item] = separator;
+
+ return separator;
+}
+
+QuicklistMenuItemRadio* TestQuicklist::createRadioItem(std::string const& label, bool enabled, bool checked)
+{
+ DbusmenuMenuitem* item = NULL;
+ QuicklistMenuItemRadio* radio = NULL;
item = dbusmenu_menuitem_new ();
dbusmenu_menuitem_property_set (item,
DBUSMENU_MENUITEM_PROP_LABEL,
- "Unchecked");
+ label.c_str());
dbusmenu_menuitem_property_set (item,
DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
- DBUSMENU_MENUITEM_TOGGLE_CHECK);
+ DBUSMENU_MENUITEM_TOGGLE_RADIO);
dbusmenu_menuitem_property_set_bool (item,
DBUSMENU_MENUITEM_PROP_ENABLED,
- true);
+ enabled);
dbusmenu_menuitem_property_set_int (item,
DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
+ (checked ?
+ DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
+ DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
+ ));
- checkmark = new QuicklistMenuItemCheckmark (item, true);
-
- g_signal_connect (item,
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK (activatedCallback),
- &gResult[0]);
+ connectToActivatedSignal(item);
+ radio = new QuicklistMenuItemRadio (item, true);
+ menus2qitem_[item] = radio;
- return checkmark;
+ return radio;
}
-QuicklistMenuItemRadio*
-createRadioItem ()
+QuicklistMenuItemCheckmark* TestQuicklist::createCheckmarkItem(std::string const& label, bool enabled, bool checked)
{
- DbusmenuMenuitem* item = NULL;
- QuicklistMenuItemRadio* radio = NULL;
+ DbusmenuMenuitem* item = NULL;
+ QuicklistMenuItemCheckmark* checkmark = NULL;
item = dbusmenu_menuitem_new ();
dbusmenu_menuitem_property_set (item,
DBUSMENU_MENUITEM_PROP_LABEL,
- "Radio Active");
+ label.c_str());
dbusmenu_menuitem_property_set (item,
DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
- DBUSMENU_MENUITEM_TOGGLE_RADIO);
+ DBUSMENU_MENUITEM_TOGGLE_CHECK);
dbusmenu_menuitem_property_set_bool (item,
DBUSMENU_MENUITEM_PROP_ENABLED,
- false);
+ enabled);
dbusmenu_menuitem_property_set_int (item,
DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
+ (checked ?
+ DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
+ DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
+ ));
- radio = new QuicklistMenuItemRadio (item, true);
+ connectToActivatedSignal(item);
- g_signal_connect (item,
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK (activatedCallback),
- &gResult[1]);
+ checkmark = new QuicklistMenuItemCheckmark (item, true);
+ menus2qitem_[item] = checkmark;
- return radio;
+ return checkmark;
}
-QuicklistMenuItemLabel*
-createLabelItem ()
+QuicklistMenuItemLabel* TestQuicklist::createLabelItem(std::string const& title, bool enabled)
{
DbusmenuMenuitem* item = NULL;
QuicklistMenuItemLabel* label = NULL;
@@ -134,172 +208,144 @@ createLabelItem ()
dbusmenu_menuitem_property_set (item,
DBUSMENU_MENUITEM_PROP_LABEL,
- "A Label");
+ title.c_str());
dbusmenu_menuitem_property_set_bool (item,
DBUSMENU_MENUITEM_PROP_ENABLED,
- true);
+ enabled);
- label = new QuicklistMenuItemLabel (item, true);
+ connectToActivatedSignal(item);
- g_signal_connect (item,
- DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK (activatedCallback),
- &gResult[2]);
+ label = new QuicklistMenuItemLabel (item, true);
+ menus2qitem_[item] = label;
return label;
}
-void
-ThreadWidgetInit (nux::NThread* thread,
- void* initData)
+void TestQuicklist::AddItem(QuicklistMenuItem* item)
{
- gQuicklist = new QuicklistView ();
- gQuicklist->Reference ();
+ if (!quicklist_)
+ return;
- gCheckmark = createCheckmarkItem ();
- gQuicklist->AddMenuItem (gCheckmark);
- gRadio = createRadioItem ();
- gQuicklist->AddMenuItem (gRadio);
- gLabel = createLabelItem ();
- gQuicklist->AddMenuItem (gLabel);
+ quicklist_->AddMenuItem(item);
+}
+
+void TestQuicklist::UserInterfaceSetup()
+{
+ QuicklistMenuItem *item;
- gQuicklist->EnableQuicklistForTesting (true);
+ quicklist_ = new QuicklistView();
+ quicklist_->EnableQuicklistForTesting(true);
+ quicklist_->SetBaseXY(0, 0);
- gQuicklist->SetBaseXY (0, 0);
- gQuicklist->ShowWindow (true);
+ item = createLabelItem("Item1, normal");
+ AddItem(item);
+
+ item = createSeparatorItem();
+ AddItem(item);
+
+ item = createRadioItem("Item2, radio, checked", true, true);
+ AddItem(item);
+
+ item = createRadioItem("Item3, radio, unchecked", true, false);
+ AddItem(item);
+
+ item = createRadioItem("Item4, disabled radio, checked", false, true);
+ AddItem(item);
+
+ item = createRadioItem("Item5, disabled radio, unchecked", false, false);
+ AddItem(item);
+
+ item = createCheckmarkItem("Item6, checkmark, checked", true, true);
+ AddItem(item);
+
+ item = createCheckmarkItem("Item7, checkmark, unchecked", true, false);
+ AddItem(item);
+
+ item = createCheckmarkItem("Item8, disabled checkmark, checked", false, true);
+ AddItem(item);
+
+ item = createCheckmarkItem("Item9, disabled checkmark, unchecked", false, false);
+ AddItem(item);
+
+ item = createLabelItem("Item10, disabled", false);
+ AddItem(item);
+
+ quicklist_->ShowWindow(true);
+
+ auto wt = static_cast<nux::WindowThread*>(window_thread_);
+ nux::ColorLayer background (nux::Color (0x772953));
+ wt->SetWindowBackgroundPaintLayer(&background);
}
-void
-ControlThread (nux::NThread* thread,
- void* data)
+TestQuicklist *test_quicklist = NULL;
+
+void TestingThread(nux::NThread *thread, void *user_data)
{
- // sleep for 3 seconds
- nux::SleepForMilliseconds (3000);
- printf ("ControlThread successfully started\n");
-
- nux::WindowThread* mainWindowThread = NUX_STATIC_CAST (nux::WindowThread*,
- data);
-
- mainWindowThread->SetFakeEventMode (true);
- Display* display = mainWindowThread->GetWindow ().GetX11Display ();
-
- // assemble first button-click event
- XEvent buttonPressEvent;
- buttonPressEvent.xbutton.type = ButtonPress;
- buttonPressEvent.xbutton.serial = 0;
- buttonPressEvent.xbutton.send_event = False;
- buttonPressEvent.xbutton.display = display;
- buttonPressEvent.xbutton.window = 0;
- buttonPressEvent.xbutton.root = 0;
- buttonPressEvent.xbutton.subwindow = 0;
- buttonPressEvent.xbutton.time = CurrentTime;
- buttonPressEvent.xbutton.x = 50;
- buttonPressEvent.xbutton.y = 30;
- buttonPressEvent.xbutton.x_root = 0;
- buttonPressEvent.xbutton.y_root = 0;
- buttonPressEvent.xbutton.state = 0;
- buttonPressEvent.xbutton.button = Button1;
- buttonPressEvent.xbutton.same_screen = True;
-
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonPressEvent);
-
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- XEvent buttonReleaseEvent;
- buttonReleaseEvent.xbutton.type = ButtonRelease;
- buttonReleaseEvent.xbutton.serial = 0;
- buttonReleaseEvent.xbutton.send_event = False;
- buttonReleaseEvent.xbutton.display = display;
- buttonReleaseEvent.xbutton.window = 0;
- buttonReleaseEvent.xbutton.root = 0;
- buttonReleaseEvent.xbutton.subwindow = 0;
- buttonReleaseEvent.xbutton.time = CurrentTime;
- buttonReleaseEvent.xbutton.x = 50;
- buttonReleaseEvent.xbutton.y = 30;
- buttonReleaseEvent.xbutton.x_root = 0;
- buttonReleaseEvent.xbutton.y_root = 0;
- buttonReleaseEvent.xbutton.state = 0;
- buttonReleaseEvent.xbutton.button = Button1;
- buttonReleaseEvent.xbutton.same_screen = True;
-
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonReleaseEvent);
-
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- // assemble second button-click event
- buttonPressEvent.xbutton.time = CurrentTime;
- buttonPressEvent.xbutton.x = 50;
- buttonPressEvent.xbutton.y = 50;
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonPressEvent);
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- buttonReleaseEvent.xbutton.time = CurrentTime;
- buttonReleaseEvent.xbutton.x = 50;
- buttonReleaseEvent.xbutton.y = 50;
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonReleaseEvent);
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- // assemble third button-click event
- buttonPressEvent.xbutton.time = CurrentTime;
- buttonPressEvent.xbutton.x = 50;
- buttonPressEvent.xbutton.y = 70;
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonPressEvent);
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- buttonReleaseEvent.xbutton.time = CurrentTime;
- buttonReleaseEvent.xbutton.x = 50;
- buttonReleaseEvent.xbutton.y = 70;
- mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
- (XEvent*) &buttonReleaseEvent);
- while (!mainWindowThread->ReadyForNextFakeEvent ())
- nux::SleepForMilliseconds (10);
-
- mainWindowThread->SetFakeEventMode (false);
+ while (test_quicklist->ReadyToGo() == false)
+ {
+ nuxDebugMsg("Waiting to start");
+ nux::SleepForMilliseconds(300);
+ }
+
+ nux::SleepForMilliseconds(1300);
+
+ auto *wnd_thread = static_cast<nux::WindowThread*>(user_data);
+
+ NuxAutomatedTestFramework test(wnd_thread);
+
+ test.Startup();
+
+ for (auto child : test_quicklist->quicklist_->GetChildren())
+ {
+ test.ViewSendMouseMotionToCenter(child);
+ test.ViewSendMouseClick(child, 1);
+ bool activated = test_quicklist->activated_[child];
+ bool should_be_activated = (child->GetItemType() != MENUITEM_TYPE_SEPARATOR && child->GetEnabled());
+
+ std::string msg = std::string(child->GetLabel());
+ msg += should_be_activated ? " | Activated" : " | NOT Activated";
+
+ test.TestReportMsg(activated == should_be_activated, msg.c_str());
+ nux::SleepForMilliseconds(200);
+ }
+
+ if (test.WhenDoneTerminateProgram())
+ {
+ wnd_thread->ExitMainLoop();
+ }
+ nuxDebugMsg("Exit testing thread");
}
int
main (int argc, char **argv)
{
- nux::WindowThread* wt = NULL;
- nux::SystemThread* st = NULL;
-
- g_type_init ();
-
- gtk_init (&argc, &argv);
- dbus_g_thread_init ();
- nux::NuxInitialize (0);
-
- wt = nux::CreateGUIThread (TEXT ("Unity Quicklist"),
- WIN_WIDTH,
- WIN_HEIGHT,
- 0,
- &ThreadWidgetInit,
- NULL);
-
- st = nux::CreateSystemThread (NULL, ControlThread, wt);
- if (st)
- st->Start (NULL);
-
- wt->Run (NULL);
-
- gQuicklist->UnReference ();
- delete st;
- delete wt;
-
- g_assert_cmpint (gResult[0], ==, true);
- g_assert_cmpint (gResult[1], ==, true);
- g_assert_cmpint (gResult[2], ==, true);
+ gtk_init(&argc, &argv);
+ nuxAssertMsg(XInitThreads() > 0, "XInitThreads has failed");
+
+ test_quicklist = new TestQuicklist("Quicklist Test", WIN_WIDTH, WIN_HEIGHT, 100000);
+ test_quicklist->Startup();
+ test_quicklist->UserInterfaceSetup();
+
+ auto *test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_quicklist->GetWindowThread());
+ test_thread->Start(test_quicklist);
+
+ test_quicklist->Run();
+
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(0), ==, true);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(1), ==, false);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(2), ==, true);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(3), ==, true);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(4), ==, false);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(5), ==, false);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(6), ==, true);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(7), ==, true);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(8), ==, false);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(9), ==, false);
+ g_assert_cmpint (test_quicklist->HasNthItemActivated(10), ==, false);
+
+ delete test_thread;
+ delete test_quicklist;
return 0;
}
diff --git a/standalone-clients/ui/TestQuicklistVisuals.cpp b/standalone-clients/ui/TestQuicklistVisuals.cpp
index 03ff93672..107412668 100644
--- a/standalone-clients/ui/TestQuicklistVisuals.cpp
+++ b/standalone-clients/ui/TestQuicklistVisuals.cpp
@@ -18,7 +18,6 @@
#include <glib.h>
#include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
#include "Nux/Nux.h"
#include "Nux/VLayout.h"
@@ -60,14 +59,12 @@ createRadioItem (const gchar* label,
DBUSMENU_MENUITEM_PROP_ENABLED,
enabled);
- if (checked)
- dbusmenu_menuitem_property_set_int (item,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
- else
- dbusmenu_menuitem_property_set_int (item,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
+ dbusmenu_menuitem_property_set_int (item,
+ DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
+ (checked ?
+ DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
+ DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
+ ));
radio = new QuicklistMenuItemRadio (item, true);
@@ -96,14 +93,12 @@ createCheckmarkItem (const gchar* label,
DBUSMENU_MENUITEM_PROP_ENABLED,
enabled);
- if (checked)
- dbusmenu_menuitem_property_set_int (item,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
- else
- dbusmenu_menuitem_property_set_int (item,
- DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
- DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
+ dbusmenu_menuitem_property_set_int (item,
+ DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
+ (checked ?
+ DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
+ DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
+ ));
checkmark = new QuicklistMenuItemCheckmark (item, true);
@@ -111,7 +106,7 @@ createCheckmarkItem (const gchar* label,
}
QuicklistMenuItemLabel*
-createLabelItem (const gchar* string)
+createLabelItem (const gchar* string, bool enabled = true)
{
DbusmenuMenuitem* item = NULL;
QuicklistMenuItemLabel* label = NULL;
@@ -124,7 +119,7 @@ createLabelItem (const gchar* string)
dbusmenu_menuitem_property_set_bool (item,
DBUSMENU_MENUITEM_PROP_ENABLED,
- true);
+ enabled);
label = new QuicklistMenuItemLabel (item, true);
@@ -170,7 +165,8 @@ ThreadWidgetInit (nux::NThread* thread,
gQuicklists[0]->AddMenuItem (radio);
separator = createSeparatorItem ();
gQuicklists[0]->AddMenuItem (separator);
- label = createLabelItem ("Application Name");
+ label = createLabelItem ("<b>Application Name</b>");
+ label->EnableLabelMarkup(true);
gQuicklists[0]->AddMenuItem (label);
separator = createSeparatorItem ();
gQuicklists[0]->AddMenuItem (separator);
@@ -193,7 +189,8 @@ ThreadWidgetInit (nux::NThread* thread,
gQuicklists[1]->AddMenuItem (checkmark);
separator = createSeparatorItem ();
gQuicklists[1]->AddMenuItem (separator);
- label = createLabelItem ("Application Name");
+ label = createLabelItem ("<b>Application Name</b>");
+ label->EnableLabelMarkup(true);
gQuicklists[1]->AddMenuItem (label);
separator = createSeparatorItem ();
gQuicklists[1]->AddMenuItem (separator);
@@ -214,11 +211,12 @@ ThreadWidgetInit (nux::NThread* thread,
gQuicklists[2]->AddMenuItem (separator);
checkmark = createCheckmarkItem ("Option 03", false, true);
gQuicklists[2]->AddMenuItem (checkmark);
- checkmark = createCheckmarkItem ("Option 04", false, true);
- gQuicklists[2]->AddMenuItem (checkmark);
+ label = createLabelItem ("Option 04", false);
+ gQuicklists[2]->AddMenuItem (label);
separator = createSeparatorItem ();
gQuicklists[2]->AddMenuItem (separator);
- label = createLabelItem ("Application Name");
+ label = createLabelItem ("<b>Application Name</b>");
+ label->EnableLabelMarkup(true);
gQuicklists[2]->AddMenuItem (label);
separator = createSeparatorItem ();
gQuicklists[2]->AddMenuItem (separator);
@@ -227,6 +225,9 @@ ThreadWidgetInit (nux::NThread* thread,
gQuicklists[2]->EnableQuicklistForTesting (true);
gQuicklists[2]->SetBaseXY (45, 290);
gQuicklists[2]->ShowWindow (true);
+
+ nux::ColorLayer background (nux::Color (0x772953));
+ static_cast<nux::WindowThread*>(thread)->SetWindowBackgroundPaintLayer(&background);
}
int
@@ -234,10 +235,7 @@ main (int argc, char **argv)
{
nux::WindowThread* wt = NULL;
- g_type_init ();
-
gtk_init (&argc, &argv);
- dbus_g_thread_init ();
nux::NuxInitialize (0);
wt = nux::CreateGUIThread (TEXT ("Unity visual Quicklist-test"),