[gtkmm] Gdk::RGBA: Add fairly simple test of our additions
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Gdk::RGBA: Add fairly simple test of our additions
- Date: Tue, 18 Dec 2018 18:05:51 +0000 (UTC)
commit 37d4ab71eebece0fc1be46dd3538d3446cedb8a6
Author: Daniel Boles <dboles src gnome org>
Date: Mon Dec 17 21:12:09 2018 +0000
Gdk::RGBA: Add fairly simple test of our additions
Test the new constructor from #40, the fix for #42, and some other bits
that we add. Most other tests should be added to GTK itself, not gtkmm.
https://gitlab.gnome.org/GNOME/gtkmm/merge_requests/8#note_389465
tests/Makefile.am | 3 +++
tests/gdk_rgba/main.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fce2d663..01e3466c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ check_PROGRAMS = \
child_widget_managed/test \
delete_cpp_child/test \
dialog_deletethis/test \
+ gdk_rgba/test \
main_with_options/test \
menu_destruction/test \
object_move/test \
@@ -34,6 +35,7 @@ check_PROGRAMS = \
wrap_existing/test
TESTS = object_move/test \
+ gdk_rgba/test \
test_validate_docs_xhtml.sh
builder_test_SOURCES = builder/main.cc
@@ -44,6 +46,7 @@ child_widget2_test_SOURCES = child_widget2/main.cc
child_widget_managed_test_SOURCES = child_widget_managed/main.cc
delete_cpp_child_test_SOURCES = delete_cpp_child/main.cc
dialog_deletethis_test_SOURCES = dialog_deletethis/main.cc
+gdk_rgba_test_SOURCES = gdk_rgba/main.cc
main_with_options_test_SOURCES = main_with_options/main.cc
menu_destruction_test_SOURCES = menu_destruction/main.cc
object_move_test_SOURCES = object_move/main.cc
diff --git a/tests/gdk_rgba/main.cc b/tests/gdk_rgba/main.cc
new file mode 100644
index 00000000..d692cffd
--- /dev/null
+++ b/tests/gdk_rgba/main.cc
@@ -0,0 +1,55 @@
+#include <gdkmm/rgba.h>
+#include <glib.h>
+
+int
+main()
+{
+ // A default-constructed RGBA is black and fully transparent
+ auto rgba = Gdk::RGBA{};
+ g_assert_cmpfloat(rgba.get_red (), ==, 0.0);
+ g_assert_cmpfloat(rgba.get_green(), ==, 0.0);
+ g_assert_cmpfloat(rgba.get_blue (), ==, 0.0);
+ g_assert_cmpfloat(rgba.get_alpha(), ==, 0.0);
+
+ // Test that when passing r,g,b the alpha defaults to 1
+ rgba.set_rgba(0.0, 0.0, 0.0);
+ g_assert_cmpfloat(rgba.get_alpha(), ==, 1.0);
+
+ // Test our get_*_u(). Note only the min/max `u`s are reliable due to rounding
+ g_assert_cmpint(rgba.get_red_u (), ==, 0x0000);
+ g_assert_cmpint(rgba.get_green_u(), ==, 0x0000);
+ g_assert_cmpint(rgba.get_blue_u (), ==, 0x0000);
+ g_assert_cmpint(rgba.get_alpha_u(), ==, 0xFFFF);
+
+ // Test constructor from doubles added in GitLab Issue #40
+ auto rgba2 = Gdk::RGBA{0.0, 0.0, 0.0, 1.0};
+ g_assert_true(rgba == rgba2);
+
+ // Test our set_*_u()
+ rgba.set_rgba(1.0, 1.0, 1.0, 1.0);
+ rgba2.set_rgba_u(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
+ g_assert_true(rgba == rgba2);
+
+ // and set_grey*()
+ rgba2.set_grey(1.0, 1.0);
+ g_assert_true(rgba == rgba2);
+ rgba2.set_grey_u(0xFFFF, 0xFFFF);
+ g_assert_true(rgba == rgba2);
+
+ // Test that hues 0° and 360° both result in red, fixed in GitLab Issue #42
+ rgba.set_hsv(0.0, 1.0, 1.0);
+ g_assert_cmpfloat(rgba.get_red (), ==, 1.0);
+ g_assert_cmpfloat(rgba.get_green(), ==, 0.0);
+ g_assert_cmpfloat(rgba.get_blue (), ==, 0.0);
+ g_assert_cmpfloat(rgba.get_alpha(), ==, 1.0);
+ rgba2.set_hsv(360.0, 1.0, 1.0);
+ g_assert_true(rgba == rgba2);
+
+ // Test HSL the same way
+ rgba2.set_hsl(0.0, 1.0, 0.5);
+ g_assert_true(rgba == rgba2);
+ rgba2.set_hsl(360.0, 1.0, 0.5);
+ g_assert_true(rgba == rgba2);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]