[gtk+] tests: Fix assertion emission



commit c2a6dcc73c3998716e47ba66070327242041ac56
Author: Benjamin Otte <otte redhat com>
Date:   Mon Feb 6 19:27:45 2012 +0100

    tests: Fix assertion emission
    
    We want to assert() when doing the actual check, not do some
      g_assert (testing_failed());

 gtk/tests/treeview-scrolling.c |   78 ++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 47 deletions(-)
---
diff --git a/gtk/tests/treeview-scrolling.c b/gtk/tests/treeview-scrolling.c
index 63bf429..3e28d4b 100644
--- a/gtk/tests/treeview-scrolling.c
+++ b/gtk/tests/treeview-scrolling.c
@@ -315,15 +315,14 @@ get_pos_from_path (GtkTreeView   *tree_view,
 	return POS_CENTER;
 }
 
-static gboolean
-test_position_with_align (GtkTreeView  *tree_view,
-			  enum Pos      pos,
-			  gint          row_y,
-			  gint          row_start,
-			  gdouble       row_height,
-			  gdouble       row_align)
+static void
+assert_position_with_align (GtkTreeView  *tree_view,
+                            enum Pos      pos,
+                            gint          row_y,
+                            gint          row_start,
+                            gdouble       row_height,
+                            gdouble       row_align)
 {
-	gboolean passed = TRUE;
 	GtkAdjustment *vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tree_view));
 
 	/* Switch on row-align: 0.0, 0.5, 1.0 */
@@ -336,18 +335,15 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 *    - dy should be equal to the top
 			 *      y coordinate of the row.
 			 */
-			if (row_y != 0)
-				passed = FALSE;
-			if (gtk_adjustment_get_value (vadjustment) != row_start)
-				passed = FALSE;
+			g_assert (row_y == 0);
+			g_assert (gtk_adjustment_get_value (vadjustment) == row_start);
 		} else {
 			/* The row can be anywhere at the last
 			 * page of the tree view.
 			 *   - dy is set to the start of the
 			 *     last page.
 			 */
-			if (gtk_adjustment_get_value (vadjustment) != gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment))
-				passed = FALSE;
+			g_assert (gtk_adjustment_get_value (vadjustment) == gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment));
 		}
 		break;
 
@@ -360,8 +356,7 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 * show the first page.
 			 *   - dy should be zero
 			 */
-			if (gtk_adjustment_get_value (vadjustment) != 0)
-				passed = FALSE;
+			g_assert (gtk_adjustment_get_value (vadjustment) == 0);
 		} else if (pos == POS_BOTTOM
 			   && row_start >= gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment) / 2) {
 			/* For the last half of the bottom view we
@@ -370,8 +365,7 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 *   - dy should be the start of the 
 			 *     last page.
 			 */
-			if (gtk_adjustment_get_value (vadjustment) != gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment))
-				passed = FALSE;
+			g_assert (gtk_adjustment_get_value (vadjustment) == gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment));
 		} else {
 			/* The row is located in the middle of
 			 * the view.
@@ -382,8 +376,7 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 *       center of the view).
 			 */
 			gdouble middle = gtk_adjustment_get_page_size (vadjustment) / 2 - row_height / 2;
-			if (row_y != ceil (middle) && row_y != floor (middle))
-				passed = FALSE;
+			g_assert (row_y == ceil (middle) || row_y == floor (middle));
 		}
 		break;
 
@@ -394,8 +387,7 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 * first page of the tree view.
 			 *   - dy is zero.
 			 */
-			if (gtk_adjustment_get_value (vadjustment) != 0)
-				passed = FALSE;
+			g_assert (gtk_adjustment_get_value (vadjustment) == 0);
 		} else if (pos == POS_CENTER || pos == POS_BOTTOM) {
 			/* The row is the last row visible in the
 			 * view.
@@ -405,36 +397,28 @@ test_position_with_align (GtkTreeView  *tree_view,
 			 *     (ie we are not on the first page).
 			 *   - dy is greater than zero
 			 */
-			if (row_start < gtk_adjustment_get_page_size (vadjustment)
-			    && row_start + row_height < gtk_adjustment_get_page_size (vadjustment))
-				passed = FALSE;
-			if (gtk_adjustment_get_value (vadjustment) <= 0)
-				passed = FALSE;
-			if (row_y != gtk_adjustment_get_page_size (vadjustment) - row_height)
-				passed = FALSE;
+			g_assert (row_start >= gtk_adjustment_get_page_size (vadjustment)
+			          || row_start + row_height >= gtk_adjustment_get_page_size (vadjustment));
+			g_assert (gtk_adjustment_get_value (vadjustment) > 0);
+		        g_assert (row_y == gtk_adjustment_get_page_size (vadjustment) - row_height);
 		}
 		break;
 	}
-
-	return passed;
 }
 
-static gboolean
-test_position_without_align (GtkTreeView *tree_view,
-			     gdouble      row_start,
-			     gdouble      row_height)
+static void
+assert_position_without_align (GtkTreeView *tree_view,
+                               gdouble      row_start,
+                               gdouble      row_height)
 {
   GtkAdjustment *vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tree_view));
 
-	/* Without align the tree view does as less work as possible,
-	 * so basically we only have to check whether the row
-	 * is visible on the screen.
-	 */
-	if (gtk_adjustment_get_value (vadjustment) <= row_start
-	    && gtk_adjustment_get_value (vadjustment) + gtk_adjustment_get_page_size (vadjustment) >= row_start + row_height)
-		return TRUE;
-
-	return FALSE;
+  /* Without align the tree view does as less work as possible,
+   * so basically we only have to check whether the row
+   * is visible on the screen.
+   */
+  g_assert (gtk_adjustment_get_value (vadjustment) <= row_start);
+  g_assert (gtk_adjustment_get_value (vadjustment) + gtk_adjustment_get_page_size (vadjustment) >= row_start + row_height);
 }
 
 static void
@@ -482,10 +466,10 @@ test_position (GtkTreeView *tree_view,
 
 	path_str = gtk_tree_path_to_string (path);
 	if (use_align) {
-		g_assert (test_position_with_align (tree_view, pos, rect.y,
-						    row_start, rect.height, row_align));
+		assert_position_with_align (tree_view, pos, rect.y,
+                                            row_start, rect.height, row_align);
 	} else {
-		g_assert (test_position_without_align (tree_view, row_start, rect.height));
+		assert_position_without_align (tree_view, row_start, rect.height);
 	}
 
 	g_free (path_str);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]