xeme/xeme

Add a simple unit test for the input stream and fix a few issues
/*
* Copyright (C) 2023 Dodo Developers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <dodo.h>
/******************************************************************************
* Tests
*****************************************************************************/
static void
test_dodo_stream_properties(void) {
DodoStream *stream = NULL;
GCancellable *cancellable = NULL;
GCancellable *cancellable1 = NULL;
char *id = NULL;
char *to = NULL;
char *from = NULL;
char *language = NULL;
char *version = NULL;
cancellable = g_cancellable_new();
stream = g_object_new(
DODO_TYPE_STREAM,
"id", "id1",
"to", "to1",
"from", "from1",
"language", "language1",
"cancellable", cancellable,
"version", "version1",
NULL);
g_assert_true(DODO_IS_STREAM(stream));
g_object_get(
G_OBJECT(stream),
"id", &id,
"to", &to,
"from", &from,
"language", &language,
"cancellable", &cancellable1,
"version", &version,
NULL);
g_assert_cmpstr(id, ==, "id1");
g_clear_pointer(&id, g_free);
g_assert_cmpstr(to, ==, "to1");
g_clear_pointer(&to, g_free);
g_assert_cmpstr(from, ==, "from1");
g_clear_pointer(&from, g_free);
g_assert_cmpstr(language, ==, "language1");
g_clear_pointer(&language, g_free);
g_assert_true(G_IS_CANCELLABLE(cancellable1));
g_assert_true(cancellable == cancellable1);
g_clear_object(&cancellable1);
g_assert_cmpstr(version, ==, "version1");
g_clear_pointer(&version, g_free);
g_clear_object(&cancellable);
g_clear_object(&stream);
}
static void
test_dodo_stream_default_version(void) {
DodoStream *stream = g_object_new(DODO_TYPE_STREAM, NULL);
const char *version = NULL;
version = dodo_stream_get_version(stream);
g_assert_cmpstr(version, ==, DODO_STREAM_VERSION);
g_clear_object(&stream);
}
/******************************************************************************
* Main
*****************************************************************************/
int
main(int argc, char *argv[]) {
g_test_init(&argc, &argv, NULL);
g_test_add_func("/dodo/stream/properties", test_dodo_stream_properties);
g_test_add_func("/dodo/stream/default-version",
test_dodo_stream_default_version);
return g_test_run();
}