summaryrefslogtreecommitdiff
path: root/tests/test-repo-finder-avahi.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-repo-finder-avahi.c')
-rw-r--r--tests/test-repo-finder-avahi.c117
1 files changed, 57 insertions, 60 deletions
diff --git a/tests/test-repo-finder-avahi.c b/tests/test-repo-finder-avahi.c
index 932c80b1..a187b2f0 100644
--- a/tests/test-repo-finder-avahi.c
+++ b/tests/test-repo-finder-avahi.c
@@ -23,15 +23,15 @@
#include "config.h"
#include <gio/gio.h>
-#include <glib.h>
#include <glib-object.h>
+#include <glib.h>
#include <locale.h>
#include <string.h>
#include "ostree-autocleanups.h"
-#include "ostree-repo-finder.h"
-#include "ostree-repo-finder-avahi.h"
#include "ostree-repo-finder-avahi-private.h"
+#include "ostree-repo-finder-avahi.h"
+#include "ostree-repo-finder.h"
/* FIXME: Upstream this */
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiStringList, avahi_string_list_free)
@@ -40,8 +40,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiStringList, avahi_string_list_free)
static void
test_repo_finder_avahi_init (void)
{
- g_autoptr(OstreeRepoFinderAvahi) finder = NULL;
- g_autoptr(GMainContext) context = NULL;
+ g_autoptr (OstreeRepoFinderAvahi) finder = NULL;
+ g_autoptr (GMainContext) context = NULL;
/* Default main context. */
finder = ostree_repo_finder_avahi_new (NULL);
@@ -58,36 +58,34 @@ static void
test_repo_finder_avahi_txt_records_parse (void)
{
struct
- {
- const guint8 *txt;
- gsize txt_len;
- const gchar *expected_key; /* (nullable) to indicate parse failure */
- const guint8 *expected_value; /* (nullable) to allow for valueless keys */
- gsize expected_value_len;
- }
- vectors[] =
- {
- { (const guint8 *) "", 0, NULL, NULL, 0 },
- { (const guint8 *) "\x00", 1, NULL, NULL, 0 },
- { (const guint8 *) "\xff", 1, NULL, NULL, 0 },
- { (const guint8 *) "k\x00", 2, NULL, NULL, 0 },
- { (const guint8 *) "k\xff", 2, NULL, NULL, 0 },
- { (const guint8 *) "=", 1, NULL, NULL, 0 },
- { (const guint8 *) "=value", 6, NULL, NULL, 0 },
- { (const guint8 *) "k=v", 3, "k", (const guint8 *) "v", 1 },
- { (const guint8 *) "key=value", 9, "key", (const guint8 *) "value", 5 },
- { (const guint8 *) "k=v=", 4, "k", (const guint8 *) "v=", 2 },
- { (const guint8 *) "k=", 2, "k", (const guint8 *) "", 0 },
- { (const guint8 *) "k", 1, "k", NULL, 0 },
- { (const guint8 *) "k==", 3, "k", (const guint8 *) "=", 1 },
- { (const guint8 *) "k=\x00\x01\x02", 5, "k", (const guint8 *) "\x00\x01\x02", 3 },
- };
+ {
+ const guint8 *txt;
+ gsize txt_len;
+ const gchar *expected_key; /* (nullable) to indicate parse failure */
+ const guint8 *expected_value; /* (nullable) to allow for valueless keys */
+ gsize expected_value_len;
+ } vectors[] = {
+ { (const guint8 *)"", 0, NULL, NULL, 0 },
+ { (const guint8 *)"\x00", 1, NULL, NULL, 0 },
+ { (const guint8 *)"\xff", 1, NULL, NULL, 0 },
+ { (const guint8 *)"k\x00", 2, NULL, NULL, 0 },
+ { (const guint8 *)"k\xff", 2, NULL, NULL, 0 },
+ { (const guint8 *)"=", 1, NULL, NULL, 0 },
+ { (const guint8 *)"=value", 6, NULL, NULL, 0 },
+ { (const guint8 *)"k=v", 3, "k", (const guint8 *)"v", 1 },
+ { (const guint8 *)"key=value", 9, "key", (const guint8 *)"value", 5 },
+ { (const guint8 *)"k=v=", 4, "k", (const guint8 *)"v=", 2 },
+ { (const guint8 *)"k=", 2, "k", (const guint8 *)"", 0 },
+ { (const guint8 *)"k", 1, "k", NULL, 0 },
+ { (const guint8 *)"k==", 3, "k", (const guint8 *)"=", 1 },
+ { (const guint8 *)"k=\x00\x01\x02", 5, "k", (const guint8 *)"\x00\x01\x02", 3 },
+ };
gsize i;
for (i = 0; i < G_N_ELEMENTS (vectors); i++)
{
- g_autoptr(AvahiStringList) string_list = NULL;
- g_autoptr(GHashTable) attributes = NULL;
+ g_autoptr (AvahiStringList) string_list = NULL;
+ g_autoptr (GHashTable) attributes = NULL;
g_test_message ("Vector %" G_GSIZE_FORMAT, i);
@@ -98,18 +96,17 @@ test_repo_finder_avahi_txt_records_parse (void)
if (vectors[i].expected_key != NULL)
{
GBytes *value;
- g_autoptr(GBytes) expected_value = NULL;
+ g_autoptr (GBytes) expected_value = NULL;
- g_assert_true (g_hash_table_lookup_extended (attributes,
- vectors[i].expected_key,
- NULL,
- (gpointer *) &value));
+ g_assert_true (g_hash_table_lookup_extended (attributes, vectors[i].expected_key, NULL,
+ (gpointer *)&value));
g_assert_cmpuint (g_hash_table_size (attributes), ==, 1);
if (vectors[i].expected_value != NULL)
{
g_assert_nonnull (value);
- expected_value = g_bytes_new_static (vectors[i].expected_value, vectors[i].expected_value_len);
+ expected_value
+ = g_bytes_new_static (vectors[i].expected_value, vectors[i].expected_value_len);
g_assert_true (g_bytes_equal (value, expected_value));
}
else
@@ -129,10 +126,10 @@ test_repo_finder_avahi_txt_records_parse (void)
static void
test_repo_finder_avahi_txt_records_duplicates (void)
{
- g_autoptr(AvahiStringList) string_list = NULL;
- g_autoptr(GHashTable) attributes = NULL;
+ g_autoptr (AvahiStringList) string_list = NULL;
+ g_autoptr (GHashTable) attributes = NULL;
GBytes *value;
- g_autoptr(GBytes) expected_value = NULL;
+ g_autoptr (GBytes) expected_value = NULL;
/* Reverse the list before using it, as they are built in reverse order.
* (See the #AvahiStringList documentation.) */
@@ -153,17 +150,14 @@ test_repo_finder_avahi_txt_records_duplicates (void)
static void
test_repo_finder_avahi_txt_records_case_sensitivity (void)
{
- g_autoptr(AvahiStringList) string_list = NULL;
- g_autoptr(GHashTable) attributes = NULL;
+ g_autoptr (AvahiStringList) string_list = NULL;
+ g_autoptr (GHashTable) attributes = NULL;
GBytes *value1, *value2;
- g_autoptr(GBytes) expected_value1 = NULL, expected_value2 = NULL;
+ g_autoptr (GBytes) expected_value1 = NULL, expected_value2 = NULL;
/* Reverse the list before using it, as they are built in reverse order.
* (See the #AvahiStringList documentation.) */
- string_list = avahi_string_list_new ("k=value1",
- "K=value2",
- "KeY2=v",
- NULL);
+ string_list = avahi_string_list_new ("k=value1", "K=value2", "KeY2=v", NULL);
string_list = avahi_string_list_reverse (string_list);
attributes = _ostree_txt_records_parse (string_list);
@@ -189,14 +183,12 @@ test_repo_finder_avahi_txt_records_case_sensitivity (void)
static void
test_repo_finder_avahi_txt_records_empty_and_missing (void)
{
- g_autoptr(AvahiStringList) string_list = NULL;
- g_autoptr(GHashTable) attributes = NULL;
+ g_autoptr (AvahiStringList) string_list = NULL;
+ g_autoptr (GHashTable) attributes = NULL;
GBytes *value1, *value2;
- g_autoptr(GBytes) expected_value1 = NULL;
+ g_autoptr (GBytes) expected_value1 = NULL;
- string_list = avahi_string_list_new ("empty=",
- "missing",
- NULL);
+ string_list = avahi_string_list_new ("empty=", "missing", NULL);
attributes = _ostree_txt_records_parse (string_list);
g_assert_cmpuint (g_hash_table_size (attributes), ==, 2);
@@ -206,22 +198,27 @@ test_repo_finder_avahi_txt_records_empty_and_missing (void)
expected_value1 = g_bytes_new_static ("", 0);
g_assert_true (g_bytes_equal (value1, expected_value1));
- g_assert_true (g_hash_table_lookup_extended (attributes, "missing", NULL, (gpointer *) &value2));
+ g_assert_true (g_hash_table_lookup_extended (attributes, "missing", NULL, (gpointer *)&value2));
g_assert_null (value2);
}
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/repo-finder-avahi/init", test_repo_finder_avahi_init);
- g_test_add_func ("/repo-finder-avahi/txt-records/parse", test_repo_finder_avahi_txt_records_parse);
- g_test_add_func ("/repo-finder-avahi/txt-records/duplicates", test_repo_finder_avahi_txt_records_duplicates);
- g_test_add_func ("/repo-finder-avahi/txt-records/case-sensitivity", test_repo_finder_avahi_txt_records_case_sensitivity);
- g_test_add_func ("/repo-finder-avahi/txt-records/empty-and-missing", test_repo_finder_avahi_txt_records_empty_and_missing);
+ g_test_add_func ("/repo-finder-avahi/txt-records/parse",
+ test_repo_finder_avahi_txt_records_parse);
+ g_test_add_func ("/repo-finder-avahi/txt-records/duplicates",
+ test_repo_finder_avahi_txt_records_duplicates);
+ g_test_add_func ("/repo-finder-avahi/txt-records/case-sensitivity",
+ test_repo_finder_avahi_txt_records_case_sensitivity);
+ g_test_add_func ("/repo-finder-avahi/txt-records/empty-and-missing",
+ test_repo_finder_avahi_txt_records_empty_and_missing);
/* FIXME: Add tests for service processing, probably by splitting the
* code in OstreeRepoFinderAvahi around found_services. */
- return g_test_run();
+ return g_test_run ();
}