libpurple/tests/test_markup.c

Sat, 09 Aug 2025 17:37:27 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sat, 09 Aug 2025 17:37:27 +0800
branch
bird-header-fix
changeset 43304
2599d35e9750
parent 43268
515f561d53bd
permissions
-rw-r--r--

Fix the birb header path

The birb header referred would only work with birb provided by wrap casuing
build to fail because of system-installed birb dependency. The commit points
it to the correct path <birb.h>.

See: https://keep.imfreedom.org/birb/birb/file/5bf00c7d7f80/birb/meson.build#l77

/*
 * Purple - Internet Messaging Library
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glib.h>

#include <purple.h>

typedef struct {
	char *markup;
	char *xhtml;
	char *plaintext;
} MarkupTestData;

static void
test_purple_markup_strip_html(void) {
	MarkupTestData data[] = {
		{
			.markup = "",
			.plaintext = "",
		}, {
			.markup = "<a href=\"https://example.com/\">https://example.com/</a>",
			.plaintext = "https://example.com/",
		}, {
			.markup = "<a href=\"https://example.com/\">example.com</a>",
			.plaintext = "example.com (https://example.com/)",
		}, {
			.markup = "<script>/* this should be ignored */</script>",
			.plaintext = "",
		}, {
			.markup = "<style>/* this should be ignored */</style>",
			.plaintext = "",
		}, {
			.markup = "<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>",
			.plaintext = "1\t2\n3\t4\n",
		}, {
			.markup = "<p>foo</p><p>bar</p><p>baz</p>",
			.plaintext = "foo\nbar\nbaz",
		}, {
			.markup = "<div><p>foo</p><p>bar</p></div>",
			.plaintext = "foo\nbar",
		}, {
			.markup = "<hr>",
			.plaintext = "",
		}, {
			.markup = "<br>",
			.plaintext = "\n",
		}, {
			.markup = NULL,
		}
	};

	for(int i = 0; data[i].markup != NULL; i++) {
		char *plaintext = purple_markup_strip_html(data[i].markup);

		g_assert_cmpstr(plaintext, ==, data[i].plaintext);
		g_free(plaintext);
	}
}

/******************************************************************************
 * Main
 *****************************************************************************/
int
main(int argc, char **argv) {
	g_test_init(&argc, &argv, NULL);
	g_test_set_nonfatal_assertions();

	g_test_add_func("/util/markup/strip-html",
	                test_purple_markup_strip_html);

	return g_test_run();
}

mercurial