Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(linux): Add more tests for keymanutil.c 🏘️ #9595

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
333 changes: 174 additions & 159 deletions linux/ibus-keyman/src/keymanutil.c

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions linux/ibus-keyman/src/keymanutil_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Internal data structures used in the implementation of keymanutil methods
// and exposed for unit testing.

#ifndef __KEYMANUTIL_INTERNAL_H__
#define __KEYMANUTIL_INTERNAL_H__

#include <gmodule.h>
#include "kmpdetails.h"

typedef struct {
GList *engines_list;
kmp_info *info;
gchar *kmp_dir;
} add_keyboard_data;

IBusEngineDesc *ibus_keyman_engine_desc_new(
gchar *file_name,
gchar *name,
gchar *description,
gchar *copyright,
gchar *lang,
gchar *license,
gchar *author,
gchar *icon,
gchar *layout,
gchar *version);

IBusEngineDesc *get_engine_for_language(
kmp_keyboard *keyboard,
kmp_info *info,
keyboard_details *kbd_details,
gchar *kmp_dir,
gchar *lang_id,
gchar *lang_name);

void keyman_add_keyboard(gpointer data, gpointer user_data);
void keyman_add_keyboards_from_dir(gpointer data, gpointer user_data);

#endif // __KEYMANUTIL_INTERNAL_H__
28 changes: 20 additions & 8 deletions linux/ibus-keyman/src/kmpdetails.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,34 @@ kmp_json_status free_keyboard_details(keyboard_details *kbd_details)
return JSON_OK;
}

void free_info(gpointer data) {
kmp_info *info = (kmp_info *)data;
if (info->name)
g_free(info->name);
if (info->version)
g_free(info->version);
if (info->copyright)
g_free(info->copyright);
if (info->author_desc)
g_free(info->author_desc);
if (info->author_url)
g_free(info->author_url);
if (info->website_desc)
g_free(info->website_desc);
if (info->website_url)
g_free(info->website_url);
}

kmp_json_status free_kmp_details(kmp_details * details)
{
g_assert(details != NULL);
g_free(details->system.fileVersion);
g_free(details->system.keymanDeveloperVersion);
g_free(details->options.readmeFile);
g_free(details->options.graphicFile);
g_free(details->info.name);
g_free(details->info.version);
g_free(details->info.copyright);
g_free(details->info.author_desc);
g_free(details->info.author_url);
g_free(details->info.website_desc);
g_free(details->info.website_url);
free_info(&details->info);
if (details->keyboards != NULL) {
g_list_free_full(details->keyboards, (GDestroyNotify)free_keyboard);
g_list_free_full(details->keyboards, (GDestroyNotify)free_keyboard);
}
if (details->files != NULL) {
g_list_free_full(details->files, (GDestroyNotify)free_fileinfo);
Expand Down
7 changes: 6 additions & 1 deletion linux/ibus-keyman/src/kmpdetails.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __KMPDETAILS_H__
#define __KMPDETAILS_H__

// kmp details from json

#include <glib.h>
Expand Down Expand Up @@ -75,4 +78,6 @@ kmp_json_status get_kmp_details(const gchar *kmp_dir, kmp_details *details);
kmp_json_status free_kmp_details(kmp_details * details);
kmp_json_status get_keyboard_details(const gchar *kmp_dir, const gchar *id, keyboard_details *details);
kmp_json_status free_keyboard_details(keyboard_details * details);
kmp_json_status print_kmp_details(kmp_details * details);
kmp_json_status print_kmp_details(kmp_details * details);

#endif // __KMPDETAILS_H__
Loading