示例#1
0
TEST_F(GQueueTest, pushNth)
{
	int testData1 = 42;
	int testData2 = 1337;
	int testData3 = 27;

	g_queue_push_nth(queue, &testData1, 0);
	ASSERT_TRUE(queue->head != NULL) << "queue head should not be empty ater inserting an element";
	ASSERT_EQ(queue->head, queue->tail) << "queue head should be equal to tail after inserting a single element";
	ASSERT_EQ(&testData1, queue->head->data) << "first queue element data should be set correctly";
	ASSERT_TRUE(queue->head->next == NULL) << "single queue element should not have a next element";
	ASSERT_TRUE(queue->head->prev == NULL) << "single queue element should not have a previous element";
	ASSERT_EQ(1, queue->length) << "queue length should be zero after inserting an element";
	GList *oldHead = queue->head;
	g_queue_push_nth(queue, &testData2, 1);
	ASSERT_EQ(oldHead, queue->head) << "queue head should not have changed after inserting another element";
	ASSERT_NE(oldHead, queue->tail) << "queue tail should have changed after pushing another element to tail";
	ASSERT_EQ(&testData2, queue->tail->data) << "second queue element data should be set correctly";
	ASSERT_TRUE(queue->tail->next == NULL) << "queue tail should not have a next element";
	ASSERT_EQ(queue->head, queue->tail->prev) << "queue tail should have head as previous element";
	ASSERT_EQ(queue->tail, queue->head->next) << "queue head should have tail as next element";
	ASSERT_TRUE(queue->head->prev == NULL) << "queue head should not have a previous element";
	ASSERT_EQ(&testData1, queue->head->data) << "first queue element data should be set correctly";
	ASSERT_EQ(2, queue->length) << "queue length should be two after inserting another element";
	GList *oldTail = queue->tail;
	g_queue_push_nth(queue, &testData3, 1);
	ASSERT_EQ(oldHead, queue->head) << "queue head should not have changed after inserting another element";
	ASSERT_EQ(oldTail, queue->tail) << "queue tail should not have changed after inserting another element";
	ASSERT_EQ(oldHead->next, oldTail->prev) << "third element should have been inserted between head and tail";
	ASSERT_EQ(&testData3, oldTail->prev->data) << "third element data should be set correctly";
	ASSERT_EQ(oldTail, oldTail->prev->next) << "third element next should point to tail";
	ASSERT_EQ(oldHead, oldTail->prev->prev) << "third element previous should point to head";
	ASSERT_EQ(3, queue->length) << "queue length should be three after inserting another element";
}
示例#2
0
void		my_layer_shift_down_shape		(MyLayer *self, MyShape *theShape) {
	
	
	GQueue *shapes = MY_LAYER_GET_PRIVATE (self)->shapes;
	guint shapeCount, j;
	MyShape *shape;
	shapeCount = my_layer_shape_count (self);
	
	assert (theShape);
	for (j = shapeCount - 1; j >= 0; j--) {
		shape = my_layer_peek_nth (self, j);
		if (shape == theShape) {
			g_queue_pop_nth (shapes, j);
			break;
		}
	}
	assert (shape == theShape);
	
	shape = g_queue_peek_nth (shapes, j - 1);
	if (shape->isControlShape) {
		g_queue_push_nth (shapes, theShape, j);		
	} else {
		g_queue_push_nth (shapes, theShape, j - 1);		
	}
}
示例#3
0
void
account_list_move_down(guint account_index)
{
    if (account_index != accountQueue->length) {
        gpointer acc = g_queue_pop_nth(accountQueue, account_index);
        g_queue_push_nth(accountQueue, acc, account_index + 1);
    }
}
示例#4
0
void
account_list_move_up(guint account_index)
{
    if (account_index != 0) {
        gpointer acc = g_queue_pop_nth(accountQueue, account_index);
        g_queue_push_nth(accountQueue, acc, account_index - 1);
    }
}
示例#5
0
void account_list_set_current(account_t *current)
{
    // 2 steps:
    // 1 - retrieve the index of the current account in the Queue
    // 2 - then set it as first
    guint pos = account_list_get_position(current);

    if (pos > 0) {
        gpointer acc = g_queue_pop_nth(accountQueue, pos);
        g_queue_push_nth(accountQueue, acc, 0);
    }
}
示例#6
0
文件: path.c 项目: FabianHahn/kalisko
API bool setStorePath(Store *store, char *pathFormat, void *value, ...)
{
	va_list va;
	char path[MAX_PATH_LEN];

	va_start(va, value);
	vsnprintf(path, MAX_PATH_LEN, pathFormat, va);

	bool result = false;
	GPtrArray *array = splitStorePath(path);
	char **parts = (char **) array->pdata;
	char *key = parts[array->len - 1];
	parts[array->len - 1] = NULL; // cut off last element

	char *parentpath = g_strjoinv("/", parts);

	Store *parent = getStorePath(store, "%s", parentpath);

	int i;

	if(parent != NULL) {
		switch(parent->type) {
			case STORE_ARRAY:
				g_hash_table_insert(parent->content.array, key, value);
				result = true;
				// key doesn't need to be freed here since the hash table takes care of that
			break;
			case STORE_LIST:
				i = atoi(key);
				g_queue_push_nth(parent->content.list, value, i);
				result = true;
				free(key);
			break;
			default: // cannot write into a leaf value
				result = false;
				free(key);
			break;
		}
	} else {
		result = false;
	}

	// Cleanup
	free(parentpath);
	for(i = 0; i < array->len - 1; i++) {
		free(parts[i]);
	}
	g_ptr_array_free(array, TRUE);

	return result;
}