diff --git a/.gitignore b/.gitignore index a674747..f9b8825 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +*.o +*.d /iast +/tests/test /doc/*.gz -/*.o -/*.d diff --git a/Makefile b/Makefile index 81610e0..dc80627 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,12 @@ PREFIX=/usr .PHONY: main test install uninstall clean -CFLAGS := -Wall -SRCFILES := $(shell find . -type f -name "*.c") -OBJFILES := $(patsubst %.c, %.o, $(SRCFILES)) +OBJECTS = iast.o transliteration.o utf8.o encoder.o +TEST_OBJECTS = tests/main.o tests/translit.o +CFLAGS = -Wall +LIBS = +TEST_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags check) +TEST_LIBS = $(LIBS) $(shell pkg-config --libs check) all: iast doc/iast.1.gz @@ -12,12 +15,18 @@ all: iast doc/iast.1.gz iast: main.o $(OBJFILES) $(CC) $^ -o $@ $(CFLAGS) -test: iast - sh tests/test.sh +test: tests/test + tests/test %.o: %.c $(CC) -MMD -MP -c $< -o $@ $(CFLAGS) +tests/%.o: tests/%.c + $(CC) -MMD -MP -c $< -o $@ $(TEST_CFLAGS) $(TEST_LIBS) + +tests/test: $(OBJECTS) $(TEST_OBJECTS) + $(CC) $^ -o $@ $(TEST_CFLAGS) $(TEST_LIBS) + doc/%.gz: doc/%.adoc asciidoctor -d manpage -b manpage $< -o $(<:.adoc=) && gzip -f $(<:.adoc=) diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..a7dad47 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,32 @@ +#include "test.h" +#include "translit.h" + +static Suite *create_test_suite() +{ + Suite *suite; + TCase *test_case; + + suite = suite_create(NULL); + test_case = tcase_create(NULL); + + register_translit_tests(test_case); + suite_add_tcase(suite, test_case); + + return suite; +} + +int main(void) +{ + Suite *suite; + SRunner *runner; + int retval; + + suite = create_test_suite(); + runner = srunner_create(suite); + + srunner_run_all(runner, CK_NORMAL); + retval = srunner_ntests_failed(runner); + srunner_free(runner); + + return retval; +} diff --git a/tests/test.h b/tests/test.h new file mode 100644 index 0000000..099d2b7 --- /dev/null +++ b/tests/test.h @@ -0,0 +1,7 @@ +#ifndef __TEST_TEST_H +#define __TEST_TEST_H + +#include +#include + +#endif /* __TEST_TEST_H */ diff --git a/tests/translit.c b/tests/translit.c new file mode 100644 index 0000000..78fa5a5 --- /dev/null +++ b/tests/translit.c @@ -0,0 +1,34 @@ +#include "translit.h" +#include "../transliteration.h" + + +START_TEST(test_translit_devanagari_to_latin) +{ + char *latin; + + /* https://en.wikipedia.org/wiki/Sanskrit */ + latin = transliterate_devanagari_to_latin("संस्कृतम्"); + ck_assert_str_eq("saṃskṛtam", latin); + free(latin); + + /* https://en.wikipedia.org/wiki/Bhagavad_Gita */ + latin = transliterate_devanagari_to_latin("भगवद्गीता"); + ck_assert_str_eq("bhagavadgītā", latin); + free(latin); + + /* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */ + latin = transliterate_devanagari_to_latin("आर्यावर्त"); + ck_assert_str_eq("āryāvarta", latin); + free(latin); + + /* https://en.wikipedia.org/wiki/Mahabharata */ + latin = transliterate_devanagari_to_latin("महाभारतम्"); + ck_assert_str_eq("mahābhāratam", latin); + free(latin); +} +END_TEST + +void register_translit_tests(TCase *test_case) +{ + tcase_add_test(test_case, test_translit_devanagari_to_latin); +} diff --git a/tests/translit.h b/tests/translit.h new file mode 100644 index 0000000..9d8ad03 --- /dev/null +++ b/tests/translit.h @@ -0,0 +1,8 @@ +#ifndef __TEST_TRANSLIT_H +#define __TEST_TRANSLIT_H + +#include + +void register_translit_tests(TCase *test_case); + +#endif /* __TEST_TRANSLIT_H */