/*
 * Copyright (C) 2023-2025 Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
 */

#include <glib.h>

#include <birb.h>

/******************************************************************************
 * Tests
 *****************************************************************************/
static void
test_birb_localized_string_new(void) {
	BirbLocalizedString *str = NULL;

	str = birb_localized_string_new("id", "label");
	birb_assert_type(str, BIRB_TYPE_LOCALIZED_STRING);

	g_assert_finalize_object(str);
}

static void
test_birb_localized_string_properties(void) {
	BirbLocalizedString *str = NULL;
	char *id = NULL;
	char *label = NULL;

	str = g_object_new(
		BIRB_TYPE_LOCALIZED_STRING,
		"id", "test-id",
		"label", "Test",
		NULL);

	g_object_get(
		G_OBJECT(str),
		"id", &id,
		"label", &label,
		NULL);

	g_assert_cmpstr(id, ==, "test-id");
	g_clear_pointer(&id, g_free);

	g_assert_cmpstr(label, ==, "Test");
	g_clear_pointer(&label, g_free);

	g_assert_finalize_object(str);
}

static void
test_birb_localized_string_new_accepts_null_id(void) {
	BirbLocalizedString *str = NULL;

	str = birb_localized_string_new(NULL, "NULL");

	birb_assert_type(str, BIRB_TYPE_LOCALIZED_STRING);

	g_assert_finalize_object(str);
}

static void
test_birb_localized_string_new_accepts_null_label(void) {
	BirbLocalizedString *str = NULL;

	str = birb_localized_string_new("NULL", NULL);

	birb_assert_type(str, BIRB_TYPE_LOCALIZED_STRING);

	g_assert_finalize_object(str);
}

static void
test_birb_localized_string_equal(void) {
	BirbLocalizedString *str1 = NULL;
	BirbLocalizedString *str2 = NULL;
	BirbLocalizedString *str3 = NULL;

	str1 = birb_localized_string_new(NULL, NULL);
	str2 = birb_localized_string_new("test", NULL);
	str3 = birb_localized_string_new("test", NULL);

	/* Test the NULL cases. */
	g_assert_true(birb_localized_string_equal(NULL, NULL));
	g_assert_false(birb_localized_string_equal(str1, NULL));
	g_assert_false(birb_localized_string_equal(NULL, str1));

	/* Test the FALSE cases. */
	g_assert_false(birb_localized_string_equal(str1, str2));
	g_assert_false(birb_localized_string_equal(str2, str1));
	g_assert_false(birb_localized_string_equal(str1, str3));
	g_assert_false(birb_localized_string_equal(str3, str1));

	/* And make sure a TRUE case works. */
	g_assert_true(birb_localized_string_equal(str2, str3));

	g_assert_finalize_object(str1);
	g_assert_finalize_object(str2);
	g_assert_finalize_object(str3);
}

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

	g_test_set_nonfatal_assertions();

	g_test_add_func("/birb/localized-string/new",
	                test_birb_localized_string_new);
	g_test_add_func("/birb/localized-string/properties",
	                test_birb_localized_string_properties);

	g_test_add_func("/birb/localized-string/new/accepts-null-id",
	                test_birb_localized_string_new_accepts_null_id);
	g_test_add_func("/birb/localized-string/new/accepts-null-label",
	                test_birb_localized_string_new_accepts_null_label);

	g_test_add_func("/birb/localized-string/equal",
	                test_birb_localized_string_equal);

	return g_test_run();
}
