Commit e7afac3c authored by Yuanle Song's avatar Yuanle Song

v0.6.1 change code format.

format code using myastyle.
removed space after function name.
put pointer on variable name side.
parent 0fbbb875
This diff is collapsed.
# -*- mode: conf -*-
project('zero-pinyin-service', ['c', 'cpp'],
version: '0.6.0',
version: '0.6.1',
license: 'GPL',
default_options: [
'warning_level=2',
......
......@@ -4,79 +4,79 @@
#include <glib/gprintf.h>
static void
test_parse_pinyin ()
test_parse_pinyin()
{
GList* result = NULL;
Pinyin* thispy = NULL;
GList *result = NULL;
Pinyin *thispy = NULL;
result = parse_pinyin ("liyifeng", 15);
g_assert_cmpint (g_list_length (result), ==, 3);
result = parse_pinyin("liyifeng", 15);
g_assert_cmpint(g_list_length(result), ==, 3);
thispy = (Pinyin*) g_list_nth_data (result, 0);
g_assert_cmpint (thispy->shengmu_i, ==, 10);
g_assert_cmpint (thispy->yunmu_i, ==, 34);
g_assert_cmpint (thispy->length, ==, 2);
thispy = (Pinyin *) g_list_nth_data(result, 0);
g_assert_cmpint(thispy->shengmu_i, ==, 10);
g_assert_cmpint(thispy->yunmu_i, ==, 34);
g_assert_cmpint(thispy->length, ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 1);
g_assert_cmpint (thispy->shengmu_i, ==, 21);
g_assert_cmpint (thispy->yunmu_i, ==, 34);
g_assert_cmpint (thispy->length, ==, 2);
thispy = (Pinyin *) g_list_nth_data(result, 1);
g_assert_cmpint(thispy->shengmu_i, ==, 21);
g_assert_cmpint(thispy->yunmu_i, ==, 34);
g_assert_cmpint(thispy->length, ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 2);
g_assert_cmpint (thispy->shengmu_i, ==, 5);
g_assert_cmpint (thispy->yunmu_i, ==, 32);
g_assert_cmpint (thispy->length, ==, 4);
thispy = (Pinyin *) g_list_nth_data(result, 2);
g_assert_cmpint(thispy->shengmu_i, ==, 5);
g_assert_cmpint(thispy->yunmu_i, ==, 32);
g_assert_cmpint(thispy->length, ==, 4);
g_list_free_full (result, g_free);
g_list_free_full(result, g_free);
}
/**
* print GList of Pinyin.
*/
static void
print_parse_result (GList* result)
print_parse_result(GList *result)
{
GList* iter = result;
Pinyin* thispy = NULL;
GList *iter = result;
Pinyin *thispy = NULL;
while (iter != NULL) {
thispy = (Pinyin*) iter->data;
g_printf ("shengmu_i=%i yunmu_i=%i length=%u\n",
thispy->shengmu_i, thispy->yunmu_i, thispy->length);
thispy = (Pinyin *) iter->data;
g_printf("shengmu_i=%i yunmu_i=%i length=%u\n",
thispy->shengmu_i, thispy->yunmu_i, thispy->length);
iter = iter->next;
}
}
static void
test_parse_pinyin_incomplete_pinyin ()
test_parse_pinyin_incomplete_pinyin()
{
GList* result = NULL;
Pinyin* thispy = NULL;
GList *result = NULL;
Pinyin *thispy = NULL;
result = parse_pinyin ("zhey", 15);
print_parse_result (result);
g_assert_cmpint (g_list_length (result), ==, 2);
result = parse_pinyin("zhey", 15);
print_parse_result(result);
g_assert_cmpint(g_list_length(result), ==, 2);
thispy = (Pinyin*) g_list_nth_data (result, 0);
g_assert_cmpint (thispy->shengmu_i, ==, 23);
g_assert_cmpint (thispy->yunmu_i, ==, 29);
g_assert_cmpint (thispy->length, ==, 3);
thispy = (Pinyin *) g_list_nth_data(result, 0);
g_assert_cmpint(thispy->shengmu_i, ==, 23);
g_assert_cmpint(thispy->yunmu_i, ==, 29);
g_assert_cmpint(thispy->length, ==, 3);
thispy = (Pinyin*) g_list_nth_data (result, 1);
g_assert_cmpint (thispy->shengmu_i, ==, 21);
g_assert_cmpint (thispy->yunmu_i, ==, 0);
g_assert_cmpint (thispy->length, ==, 1);
thispy = (Pinyin *) g_list_nth_data(result, 1);
g_assert_cmpint(thispy->shengmu_i, ==, 21);
g_assert_cmpint(thispy->yunmu_i, ==, 0);
g_assert_cmpint(thispy->length, ==, 1);
g_list_free_full (result, g_free);
g_list_free_full(result, g_free);
}
int
main (int argc, char *argv[])
main(int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/zero/test_parse_pinyin",
test_parse_pinyin);
g_test_add_func ("/zero/test_parse_pinyin incomplete pinyin",
test_parse_pinyin_incomplete_pinyin);
g_test_init(&argc, &argv, NULL);
g_test_add_func("/zero/test_parse_pinyin",
test_parse_pinyin);
g_test_add_func("/zero/test_parse_pinyin incomplete pinyin",
test_parse_pinyin_incomplete_pinyin);
return g_test_run ();
return g_test_run();
}
......@@ -3,20 +3,20 @@
#include "../PinyinParser.h"
#include "../Const.h"
GList*
parse_pinyin (const char* preedit_str, const guint max_pinyin)
GList *
parse_pinyin(const char *preedit_str, const guint max_pinyin)
{
GList* result = NULL;
GList *result = NULL;
PyZy::PinyinArray pyar = {0};
Pinyin* thispy = NULL;
Pinyin *thispy = NULL;
const guint FLAGS = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL | PINYIN_FUZZY_ALL;
PyZy::PinyinParser::parse (preedit_str, strlen(preedit_str), FLAGS, pyar, max_pinyin);
PyZy::PinyinParser::parse(preedit_str, strlen(preedit_str), FLAGS, pyar, max_pinyin);
for (guint i = 0; i < pyar.size(); ++i) {
thispy = g_new (Pinyin, 1);
thispy = g_new(Pinyin, 1);
thispy->shengmu_i = (int) pyar[i].pinyin->pinyin_id[0].sheng;
thispy->yunmu_i = (int) pyar[i].pinyin->pinyin_id[0].yun;
thispy->length = pyar[i].len;
result = g_list_append (result, thispy);
result = g_list_append(result, thispy);
}
return result;
}
......@@ -13,7 +13,7 @@ extern "C"
* parse preedit_str to groups of pinyin.
* caller should free each Pinyin and the GList after use.
*/
GList* parse_pinyin (const char* preedit_str, const guint max_pinyin);
GList *parse_pinyin(const char *preedit_str, const guint max_pinyin);
#ifdef __cplusplus
}
......
#include "zero-pinyin-service.h"
static void
test_GString ()
test_GString()
{
GString* s = NULL;
s = g_string_new (NULL);
g_string_append_printf (s, "s0=%d ", 1);
GString *s = NULL;
s = g_string_new(NULL);
g_string_append_printf(s, "s0=%d ", 1);
g_assert_cmpstr (s->str, ==, "s0=1 ");
g_assert_cmpstr(s->str, ==, "s0=1 ");
g_string_free (s, TRUE);
g_string_free(s, TRUE);
}
static void
test_build_s_y_fields ()
test_build_s_y_fields()
{
gchar* result = NULL;
result = build_s_y_fields (1);
g_assert_cmpstr (result, ==, ", s0, y0 ");
g_free (result);
gchar *result = NULL;
result = build_s_y_fields(1);
g_assert_cmpstr(result, ==, ", s0, y0 ");
g_free(result);
result = build_s_y_fields (2);
g_assert_cmpstr (result, ==, ", s0, y0, s1, y1 ");
g_free (result);
result = build_s_y_fields(2);
g_assert_cmpstr(result, ==, ", s0, y0, s1, y1 ");
g_free(result);
}
int
main (int argc, char *argv[])
main(int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/zero/test_GString", test_GString);
g_test_add_func ("/zero/test_build_s_y_fields", test_build_s_y_fields);
return g_test_run ();
g_test_init(&argc, &argv, NULL);
g_test_add_func("/zero/test_GString", test_GString);
g_test_add_func("/zero/test_build_s_y_fields", test_build_s_y_fields);
return g_test_run();
}
This diff is collapsed.
......@@ -29,10 +29,10 @@ typedef struct {
/**
* an implementation of get_candidates() with simple test data.
*/
void get_candidates_test (const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder);
void get_candidates_test(const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder);
/**
* fetch candidates for preedit_str.
......@@ -42,12 +42,12 @@ void get_candidates_test (const char *preedit_str,
* @candidates_builder candidates will be added to this builder
* @matched_lengths_builder matched preedit_str length will be added to this builder
*/
void get_candidates (sqlite3 *db,
const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder,
GVariantBuilder *candidates_pinyin_indices);
void get_candidates(sqlite3 *db,
const char *preedit_str,
const guint fetch_size,
GVariantBuilder *candidates_builder,
GVariantBuilder *matched_lengths_builder,
GVariantBuilder *candidates_pinyin_indices);
/**
* commit candidate.
......@@ -55,12 +55,12 @@ void get_candidates (sqlite3 *db,
* This will save candidate in user db so it's available in the future.
* It also update user_freq for given candidate.
*/
void commit_candidate (sqlite3 *db,
const gchar *candidate,
GVariant *candidate_pinyin_indices);
void commit_candidate(sqlite3 *db,
const gchar *candidate,
GVariant *candidate_pinyin_indices);
/* for test only */
char* build_s_y_fields (const guint n);
char *build_s_y_fields(const guint n);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment