TEST_F(GQueueTest, popTailLink) { int testData1 = 42; int testData2 = 1337; g_queue_push_tail(queue, &testData1); g_queue_push_tail(queue, &testData2); GList *head = g_queue_pop_tail_link(queue); ASSERT_TRUE(head != NULL) << "popped queue element should not be NULL"; ASSERT_EQ(&testData2, head->data) << "popped queue head should have correct value"; ASSERT_TRUE(head->next == NULL) << "poppoed queue head should not have a next element"; ASSERT_TRUE(head->prev == NULL) << "poppoed queue head should not have a next element"; ASSERT_TRUE(queue->head != NULL) << "queue head should not be NULL after removing one element"; ASSERT_EQ(queue->head, queue->tail) << "queue tail should be equal to head after removing one element"; ASSERT_TRUE(queue->head->next == NULL) << "queue element should not have a next element"; ASSERT_TRUE(queue->head->prev == NULL) << "queue element should not have a previous element"; ASSERT_EQ(1, queue->length) << "queue should have one element left after popping one"; g_list_free(head); head = g_queue_pop_tail_link(queue); ASSERT_TRUE(head != NULL) << "popped queue element should not be NULL"; ASSERT_EQ(&testData1, head->data) << "popped queue head should have correct value"; ASSERT_TRUE(head->next == NULL) << "poppoed queue head should not have a next element"; ASSERT_TRUE(head->prev == NULL) << "poppoed queue head should not have a next element"; ASSERT_TRUE(queue->head == NULL) << "queue head should be NULL after popping another element"; ASSERT_TRUE(queue->tail == NULL) << "queue tail should be NULL after popping another element"; ASSERT_EQ(0, queue->length) << "queue length should be zero after popping another element"; g_list_free(head); head = g_queue_pop_tail_link(queue); ASSERT_TRUE(head == NULL) << "popped queue element of empty queue should be NULL"; }
int main() { GQueue *q; GList *node; gpointer data; q = g_queue_new (); g_assert (g_queue_is_empty (q) == TRUE); g_queue_push_head (q, GINT_TO_POINTER (2)); g_assert (g_queue_peek_head (q) == GINT_TO_POINTER (2)); g_assert (g_queue_is_empty (q) == FALSE); g_assert (g_list_length (q->head) == 1); g_assert (q->head == q->tail); g_queue_push_head (q, GINT_TO_POINTER (1)); g_assert (q->head->next == q->tail); g_assert (q->tail->prev == q->head); g_assert (g_list_length (q->head) == 2); g_assert (q->tail->data == GINT_TO_POINTER (2)); g_assert (q->head->data == GINT_TO_POINTER (1)); g_queue_push_tail (q, GINT_TO_POINTER (3)); g_assert (g_list_length (q->head) == 3); g_assert (q->head->data == GINT_TO_POINTER (1)); g_assert (q->head->next->data == GINT_TO_POINTER (2)); g_assert (q->head->next->next == q->tail); g_assert (q->head->next == q->tail->prev); g_assert (q->tail->data == GINT_TO_POINTER (3)); g_queue_push_tail (q, GINT_TO_POINTER (4)); g_assert (g_list_length (q->head) == 4); g_assert (q->head->data == GINT_TO_POINTER (1)); g_assert (g_queue_peek_tail (q) == GINT_TO_POINTER (4)); g_queue_push_tail (q, GINT_TO_POINTER (5)); g_assert (g_list_length (q->head) == 5); g_assert (g_queue_is_empty (q) == FALSE); g_assert (q->length == 5); g_assert (q->head->prev == NULL); g_assert (q->head->data == GINT_TO_POINTER (1)); g_assert (q->head->next->data == GINT_TO_POINTER (2)); g_assert (q->head->next->next->data == GINT_TO_POINTER (3)); g_assert (q->head->next->next->next->data == GINT_TO_POINTER (4)); g_assert (q->head->next->next->next->next->data == GINT_TO_POINTER (5)); g_assert (q->head->next->next->next->next->next == NULL); g_assert (q->head->next->next->next->next == q->tail); g_assert (q->tail->data == GINT_TO_POINTER (5)); g_assert (q->tail->prev->data == GINT_TO_POINTER (4)); g_assert (q->tail->prev->prev->data == GINT_TO_POINTER (3)); g_assert (q->tail->prev->prev->prev->data == GINT_TO_POINTER (2)); g_assert (q->tail->prev->prev->prev->prev->data == GINT_TO_POINTER (1)); g_assert (q->tail->prev->prev->prev->prev->prev == NULL); g_assert (q->tail->prev->prev->prev->prev == q->head); g_assert (g_queue_peek_tail (q) == GINT_TO_POINTER (5)); g_assert (g_queue_peek_head (q) == GINT_TO_POINTER (1)); g_assert (g_queue_pop_head (q) == GINT_TO_POINTER (1)); g_assert (g_list_length (q->head) == 4 && q->length == 4); g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (5)); g_assert (g_list_length (q->head) == 3); g_assert (g_queue_pop_head_link (q)->data == GINT_TO_POINTER (2)); g_assert (g_list_length (q->head) == 2); g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (4)); g_assert (g_list_length (q->head) == 1); g_assert (g_queue_pop_head_link (q)->data == GINT_TO_POINTER (3)); g_assert (g_list_length (q->head) == 0); g_assert (g_queue_pop_tail (q) == NULL); g_assert (g_list_length (q->head) == 0); g_assert (g_queue_pop_head (q) == NULL); g_assert (g_list_length (q->head) == 0); g_assert (g_queue_is_empty (q) == TRUE); /************************/ g_queue_push_head (q, GINT_TO_POINTER (1)); g_assert (g_list_length (q->head) == 1 && 1 == q->length); g_queue_push_head (q, GINT_TO_POINTER (2)); g_assert (g_list_length (q->head) == 2 && 2 == q->length); g_queue_push_head (q, GINT_TO_POINTER (3)); g_assert (g_list_length (q->head) == 3 && 3 == q->length); g_queue_push_head (q, GINT_TO_POINTER (4)); g_assert (g_list_length (q->head) == 4 && 4 == q->length); g_queue_push_head (q, GINT_TO_POINTER (5)); g_assert (g_list_length (q->head) == 5 && 5 == q->length); g_assert (g_queue_pop_head (q) == GINT_TO_POINTER (5)); g_assert (g_list_length (q->head) == 4); node = q->tail; g_assert (node == g_queue_pop_tail_link (q)); g_assert (g_list_length (q->head) == 3); data = q->head->data; g_assert (data == g_queue_pop_head (q)); g_assert (g_list_length (q->head) == 2); g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (2)); g_assert (g_list_length (q->head) == 1); g_assert (q->head == q->tail); g_assert (g_queue_pop_tail (q) == GINT_TO_POINTER (3)); g_assert (g_list_length (q->head) == 0); g_assert (g_queue_pop_head (q) == NULL); g_assert (g_queue_pop_head_link (q) == NULL); g_assert (g_list_length (q->head) == 0); g_assert (g_queue_pop_tail_link (q) == NULL); g_assert (g_list_length (q->head) == 0); g_queue_free (q); return 0; }
static void _eventd_nd_notification_refresh_list(EventdPluginContext *context, EventdNdQueue *queue) { if ( queue->more_notification != NULL ) { g_queue_pop_tail_link(queue->queue); queue->more_notification->visible = FALSE; } while ( ( g_queue_get_length(queue->queue) < queue->limit ) && ( ! g_queue_is_empty(queue->wait_queue) ) ) { GList *link; link = g_queue_pop_head_link(queue->wait_queue); if ( queue->reverse ) g_queue_push_tail_link(queue->queue, link); else g_queue_push_head_link(queue->queue, link); EventdNdNotification *self = link->data; gint timeout; timeout = eventd_nd_style_get_bubble_timeout(self->style); if ( timeout > 0 ) self->timeout = g_timeout_add_full(G_PRIORITY_DEFAULT, timeout, _eventd_nd_event_timedout, self, NULL); self->visible = TRUE; } if ( queue->more_indicator ) { if ( ! g_queue_is_empty(queue->wait_queue) ) { if ( queue->more_notification == NULL ) queue->more_notification = eventd_nd_notification_new(context, NULL, context->style); else { _eventd_nd_notification_update(queue->more_notification, NULL); g_queue_push_tail_link(queue->queue, queue->more_notification->link); } queue->more_notification->visible = TRUE; } else if ( queue->more_notification != NULL ) eventd_nd_notification_free(queue->more_notification); } gpointer data = NULL; if ( context->backend->move_begin != NULL ) data = context->backend->move_begin(context->backend->context, g_queue_get_length(queue->queue)); gboolean right, center, bottom; right = ( queue->anchor == EVENTD_ND_ANCHOR_TOP_RIGHT ) || ( queue->anchor == EVENTD_ND_ANCHOR_BOTTOM_RIGHT ); center = ( queue->anchor == EVENTD_ND_ANCHOR_TOP ) || ( queue->anchor == EVENTD_ND_ANCHOR_BOTTOM ); bottom = ( queue->anchor == EVENTD_ND_ANCHOR_BOTTOM_LEFT ) || ( queue->anchor == EVENTD_ND_ANCHOR_BOTTOM ) || ( queue->anchor == EVENTD_ND_ANCHOR_BOTTOM_RIGHT ); gint bx, by; bx = queue->margin_x; by = queue->margin_y; if ( center ) bx = context->geometry.w; else if ( right ) bx = context->geometry.w - bx; if ( bottom ) by = context->geometry.h - by; GList *self_; for ( self_ = g_queue_peek_head_link(queue->queue) ; self_ != NULL ; self_ = g_list_next(self_) ) { EventdNdNotification *self = self_->data; if ( bottom ) by -= self->border_size.height; gint x, y; x = center ? ( ( bx / 2 ) - ( self->border_size.width / 2 ) ) : right ? ( bx - self->border_size.width ) : bx; y = by; x -= self->offset.x; y -= self->offset.y; context->backend->move_surface(self->surface, x, y, data); if ( bottom ) by -= queue->spacing; else by += self->border_size.height + queue->spacing; } if ( context->backend->move_end != NULL ) context->backend->move_end(context->backend->context, data); }