Skip to content
parse-pinyin-test.cpp 1.71 KiB
Newer Older
#include "parse-pinyin.h"
Yuanle Song's avatar
Yuanle Song committed
#include <iostream>

static void
test_parse_pinyin_cpp ()
Yuanle Song's avatar
Yuanle Song committed
{
	std::vector<Pinyin*>* result = parse_pinyin_cpp ("liyifeng");
Yuanle Song's avatar
Yuanle Song committed
	g_assert_cmpint (result->size (), ==, 3);

	g_assert_cmpint (result->at(0)->shengmu_i, ==, 10);
	g_assert_cmpint (result->at(0)->yunmu_i, ==, 34);
	g_assert_cmpint (result->at(0)->length, ==, 2);

	g_assert_cmpint (result->at(1)->shengmu_i, ==, 21);
	g_assert_cmpint (result->at(1)->yunmu_i, ==, 34);
	g_assert_cmpint (result->at(1)->length, ==, 2);

	g_assert_cmpint (result->at(2)->shengmu_i, ==, 5);
	g_assert_cmpint (result->at(2)->yunmu_i, ==, 32);
	g_assert_cmpint (result->at(2)->length, ==, 4);

	for (guint i = 0; i < result->size (); ++i) {
		delete result->at(i);
	}
	delete result;
}

static void
test_parse_pinyin ()
{
	GList* result = NULL;
	Pinyin* thispy = NULL;

	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, 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);

	g_list_free_full (result, g_free);
}

Yuanle Song's avatar
Yuanle Song committed
int
main (int argc, char *argv[])
{
	g_test_init (&argc, &argv, NULL);
	g_test_add_func ("/zero/test_parse_pinyin_cpp",
			 test_parse_pinyin_cpp);
Yuanle Song's avatar
Yuanle Song committed
	g_test_add_func ("/zero/test_parse_pinyin",
			 test_parse_pinyin);

	return g_test_run ();
}