1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <aspell.h>
const uint16_t test_word[] = {'c','a','f', 0x00E9, 0};
const uint16_t test_incorrect[] = {'c','a','f', 'e', 0};
//const uint16_t test_doc[] = {'T', 'h', 'e', ' ', 'c','a','f', 0x00E9, '.', 0};
int fail = 0;
void f1() {
AspellConfig * spell_config = new_aspell_config();
aspell_config_replace(spell_config, "master", "en_US-w_accents");
aspell_config_replace(spell_config, "encoding", "ucs-2");
AspellCanHaveError * possible_err = new_aspell_speller(spell_config);
AspellSpeller * spell_checker = 0;
if (aspell_error_number(possible_err) != 0) {
fprintf(stderr, "%s", aspell_error_message(possible_err));
exit(0);
} else {
spell_checker = to_aspell_speller(possible_err);
}
int correct = aspell_speller_check_w(spell_checker, test_word, -1);
if (!correct) {
fprintf(stderr, "%s", "fail: expected word to be correct\n");
fail = 1;
}
correct = aspell_speller_check_w(spell_checker, test_incorrect, -1);
if (correct) {
fprintf(stderr, "%s", "fail: expected word to be incorrect\n");
fail = 1;
}
const AspellWordList * suggestions = aspell_speller_suggest_w(spell_checker, test_incorrect, -1);
AspellStringEnumeration * elements = aspell_word_list_elements(suggestions);
const uint16_t * word = aspell_string_enumeration_next_w(uint16_t, elements);
if (memcmp(word, test_word, sizeof(test_incorrect)) != 0) {
fprintf(stderr, "%s", "fail: first suggesion is not what is expected\n");
fail = 1;
delete_aspell_string_enumeration(elements);
}
if (fail)
printf("not ok\n");
else
printf("ok\n");
}
void f2() {
AspellConfig * spell_config = new_aspell_config();
aspell_config_replace(spell_config, "master", "en_US-w_accents");
aspell_config_replace(spell_config, "encoding", "ucs-2");
AspellCanHaveError * possible_err = new_aspell_speller(spell_config);
AspellSpeller * spell_checker = 0;
if (aspell_error_number(possible_err) != 0) {
fprintf(stderr, "%s", aspell_error_message(possible_err));
exit(0);
} else {
spell_checker = to_aspell_speller(possible_err);
}
int correct = aspell_speller_check_w(spell_checker, test_word, -1);
if (!correct) {
fprintf(stderr, "%s", "fail: expected word to be correct\n");
fail = 1;
}
correct = aspell_speller_check_w(spell_checker, test_incorrect, -1);
if (correct) {
fprintf(stderr, "%s", "fail: expected word to be incorrect\n");
fail = 1;
}
const AspellWordList * suggestions = aspell_speller_suggest_w(spell_checker, test_incorrect, -1);
AspellStringEnumeration * elements = aspell_word_list_elements(suggestions);
const uint16_t * word = aspell_string_enumeration_next_w(uint16_t, elements);
if (memcmp(word, test_word, sizeof(test_incorrect)) != 0) {
fprintf(stderr, "%s", "fail: first suggesion is not what is expected\n");
fail = 1;
delete_aspell_string_enumeration(elements);
}
if (fail)
printf("not ok\n");
else
printf("ok\n");
}
|