[PATCH wfits] gtk: Add test_button.cpp and gtk/ButtonClickTest

Eoff, Ullysses A ullysses.a.eoff at intel.com
Thu May 30 15:56:29 PDT 2013


Brian,

Looks good other than a few stylistic issues and some const corrections.
Be sure to remove all trailing whitespaces (git diff should show them).  See other
comments inline.

Thanks,
U. Artie

> -----Original Message-----
> From: wayland-devel-bounces+ullysses.a.eoff=intel.com at lists.freedesktop.org
> [mailto:wayland-devel-
> bounces+ullysses.a.eoff=intel.com at lists.freedesktop.org] On Behalf Of Brian
> Lovin
> Sent: Thursday, May 30, 2013 3:22 PM
> To: wayland-devel at lists.freedesktop.org
> Cc: Lovin, Brian J
> Subject: [PATCH wfits] gtk: Add test_button.cpp and gtk/ButtonClickTest
> 
> Added test_button.cpp and the gtk+ test case
> ButtonClickTest
> 
> Signed-off-by: Brian Lovin <brian.j.lovin at intel.com>
> ---
>  src/test/gtk+/Makefile.am     |   3 +-
>  src/test/gtk+/test_button.cpp | 138
> ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 140 insertions(+), 1 deletion(-)
>  create mode 100644 src/test/gtk+/test_button.cpp
> 
> diff --git a/src/test/gtk+/Makefile.am b/src/test/gtk+/Makefile.am
> index dbdf065..33260f3 100644
> --- a/src/test/gtk+/Makefile.am
> +++ b/src/test/gtk+/Makefile.am
> @@ -7,7 +7,8 @@ noinst_LTLIBRARIES = libwfits-gtk.la
>  libwfits_gtk_la_SOURCES =		\
>  	testharness.cpp			\
>  	test_window_geometry.cpp	\
> -	test_window_fullscreen.cpp
> +	test_window_fullscreen.cpp	\
> +	test_button.cpp
> 
>  AM_CXXFLAGS =				\
>  	$(WAYLAND_CFLAGS)		\
> diff --git a/src/test/gtk+/test_button.cpp b/src/test/gtk+/test_button.cpp
> new file mode 100644
> index 0000000..d661ffc
> --- /dev/null
> +++ b/src/test/gtk+/test_button.cpp
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright © 2013 Intel Corporation
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and
> + * its documentation for any purpose is hereby granted without fee, provided
> + * that the above copyright notice appear in all copies and that both that
> + * copyright notice and this permission notice appear in supporting
> + * documentation, and that the name of the copyright holders not be used in
> + * advertising or publicity pertaining to distribution of the software
> + * without specific, written prior permission.  The copyright holders make
> + * no representations about the suitability of this software for any
> + * purpose.  It is provided "as is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
> AND
> + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
> + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> WHATSOEVER
> + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
> OF
> + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
> IN
> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include "testharness.h"
> +
> +namespace wfits {
> +namespace test {
> +namespace gtk {
> +
> +class ButtonClickTest :  public GtkTestHarness
> +{
> +public:
> +	ButtonClickTest()
> +	: GtkTestHarness::GtkTestHarness()
> +	, win_(gtk_window_new(GTK_WINDOW_TOPLEVEL))
> +	, button_(gtk_button_new_with_label("Test Button!"))
> +	, clicked_(false)
> +	, pressed_(false)
> +	, released_(false)

Please indent the initializer list by one more tab under  the constructor name.

> +	{
> +		return;
> +	}
> +
> +	~ButtonClickTest()
> +	{
> +		gtk_widget_destroy(win_);
> +	}
> +
> +	void setup()
> +	{
> +		gtk_container_add (GTK_CONTAINER(win_), button_);
> +
> +		g_signal_connect(button_, "button-press-event",
> G_CALLBACK(onPressed), this);
> +		g_signal_connect(button_, "button-release-event",
> G_CALLBACK(onReleased), this);
> +		g_signal_connect(button_, "clicked", G_CALLBACK(onClicked),
> this);
> +		gtk_widget_show (button_);

Remove space between function name and param list.

> +
> +		gtk_window_set_title(GTK_WINDOW(win_),
> fullname(*this).c_str());
> +		gtk_window_resize(GTK_WINDOW(win_), 360, 225);
> +		gtk_widget_show(win_);
> +
> +		gdk_window_set_events(
> +			gtk_widget_get_window(win_),
> +
> 	static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK |
> GDK_BUTTON_RELEASE_MASK)
> +		);
> +
> +		queueStep(boost::bind(&ButtonClickTest::test,
> boost::ref(*this)));
> +	}
> +
> +	void test()
> +	{
> +		wl_surface *surface = gdk_wayland_window_get_wl_surface(
> +			gtk_widget_get_window(win_)
> +		);
> +		ASSERT(surface != NULL);
> +
> +		Geometry geometry(getSurfaceGeometry(surface));

This should be a "const Geometry".

> +		GtkAllocation	allocation;
> +
> +		gtk_widget_get_allocation(button_, &allocation);
> +
> +		//Place pointer in center of button
> +		setGlobalPointerPosition(
> +			geometry.x + allocation.x + allocation.width / 2,
> +			geometry.y + allocation.y + allocation.height / 2
> +		);
> +
> +		ASSERT(not pressed_);
> +
> +		inputKeySend(BTN_LEFT, 1);
> +
> +		YIELD_UNTIL(pressed_)
> +
> +		ASSERT(not released_);
> +		ASSERT(not clicked_);
> +
> +		inputKeySend(BTN_LEFT, 0);
> +
> +		YIELD_UNTIL(released_ and clicked_)
> +	}
> +
> +	static void onClicked(GtkWidget *widget, gpointer data)
> +	{
> +		ButtonClickTest *test = static_cast<ButtonClickTest*>(data);
> +		test->clicked_ = true;
> +		std::cout << "...received click event" << std::endl;
> +	}
> +
> +	static gboolean onPressed(GtkWidget *widget, GdkEvent *event,
> gpointer data)
> +	{
> +		ButtonClickTest *test = static_cast<ButtonClickTest*>(data);
> +		test->pressed_ = true;
> +		std::cout << "...received press event" << std::endl;
> +
> +		return gtk_false();
> +	}
> +
> +	static gboolean onReleased(GtkWidget *widget, GdkEvent *event,
> gpointer data)
> +	{
> +		ButtonClickTest *test = static_cast<ButtonClickTest*>(data);
> +		test->released_ = true;
> +		std::cout << "...received release event" << std::endl;
> +
> +		return gtk_false();
> +	}
> +
> +private:
> +	GtkWidget	*win_;
> +	GtkWidget	*button_;
> +	gboolean	clicked_;
> +	gboolean	pressed_;
> +	gboolean	released_;

Make these last three members "bool" types.

> +};
> +
> +WFITS_GTK_HARNESS_TEST_CASE(ButtonClickTest);
> +
> +} // namespace gtk
> +} // namespace test
> +} // namespace wfits
> --
> 1.8.1.2
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list