Blame testsuite/test-encoding.c

Packit a7d494
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
Packit a7d494
/* test-encoding.c
Packit a7d494
 * This file is part of GtkSourceView
Packit a7d494
 *
Packit a7d494
 * Copyright (C) 2014 - Sébastien Wilmet <swilmet@gnome.org>
Packit a7d494
 *
Packit a7d494
 * GtkSourceView is free software; you can redistribute it and/or
Packit a7d494
 * modify it under the terms of the GNU Lesser General Public
Packit a7d494
 * License as published by the Free Software Foundation; either
Packit a7d494
 * version 2.1 of the License, or (at your option) any later version.
Packit a7d494
 *
Packit a7d494
 * GtkSourceView is distributed in the hope that it will be useful,
Packit a7d494
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a7d494
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a7d494
 * Lesser General Public License for more details.
Packit a7d494
 *
Packit a7d494
 * You should have received a copy of the GNU Lesser General Public
Packit a7d494
 * License along with this library; if not, write to the Free Software
Packit a7d494
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit a7d494
 */
Packit a7d494
Packit a7d494
#include <gtksourceview/gtksource.h>
Packit a7d494
#include "gtksourceview/gtksourceencoding-private.h"
Packit a7d494
Packit a7d494
static void
Packit a7d494
test_remove_duplicates (void)
Packit a7d494
{
Packit a7d494
	GSList *list = NULL;
Packit a7d494
	const GtkSourceEncoding *utf8;
Packit a7d494
	const GtkSourceEncoding *iso;
Packit a7d494
Packit a7d494
	utf8 = gtk_source_encoding_get_utf8 ();
Packit a7d494
	iso = gtk_source_encoding_get_from_charset ("ISO-8859-15");
Packit a7d494
Packit a7d494
	/* Before: [UTF-8, ISO-8859-15, UTF-8] */
Packit a7d494
	list = g_slist_prepend (list, (gpointer) utf8);
Packit a7d494
	list = g_slist_prepend (list, (gpointer) iso);
Packit a7d494
	list = g_slist_prepend (list, (gpointer) utf8);
Packit a7d494
Packit a7d494
	/* After: [UTF-8, ISO-8859-15] */
Packit a7d494
	list = _gtk_source_encoding_remove_duplicates (list, GTK_SOURCE_ENCODING_DUPLICATES_KEEP_FIRST);
Packit a7d494
Packit a7d494
	g_assert_cmpint (2, ==, g_slist_length (list));
Packit a7d494
	g_assert (list->data == utf8);
Packit a7d494
	g_assert (list->next->data == iso);
Packit a7d494
Packit a7d494
	/* Before: [UTF-8, ISO-8859-15, UTF-8] */
Packit a7d494
	list = g_slist_append (list, (gpointer) utf8);
Packit a7d494
Packit a7d494
	/* After: [ISO-8859-15, UTF-8] */
Packit a7d494
	list = _gtk_source_encoding_remove_duplicates (list, GTK_SOURCE_ENCODING_DUPLICATES_KEEP_LAST);
Packit a7d494
Packit a7d494
	g_assert_cmpint (2, ==, g_slist_length (list));
Packit a7d494
	g_assert (list->data == iso);
Packit a7d494
	g_assert (list->next->data == utf8);
Packit a7d494
Packit a7d494
	g_slist_free (list);
Packit a7d494
}
Packit a7d494
Packit a7d494
int
Packit a7d494
main (int argc, char **argv)
Packit a7d494
{
Packit a7d494
	gtk_test_init (&argc, &argv);
Packit a7d494
Packit a7d494
	g_test_add_func ("/Encoding/remove_duplicates", test_remove_duplicates);
Packit a7d494
Packit a7d494
	return g_test_run ();
Packit a7d494
}