static int dictionary_setup(void **state) {
    struct dictionary *d = dictionary_new();
    dictionary_insert(d,first);
    dictionary_insert(d,second);
    dictionary_insert(d,third);
    *state = d;
    return 0;
}
/// Funkcja sprawdzająca inicjalizację, dodanie słów ze stałych i destrukcję.
static void dict_setup_done_test(void **state) {
	struct dictionary* d = dictionary_new();
	assert_non_null(d);
	assert_int_equal(dictionary_insert(d, first), 1);
	assert_int_equal(dictionary_insert(d, second), 1);
	assert_int_equal(dictionary_insert(d, third), 1);
	assert_int_equal(dictionary_insert(d, forth), 1);
	assert_int_equal(dictionary_insert(d, fifth), 1);
	dictionary_done(d);
}
/// Ustawia słownik z podobnych stringów do testów setup_teardown.
static int dict_setup_similar(void **state) {
	struct dictionary* d = dictionary_new();
	if(!d)
		return -1;
	assert_int_equal(dictionary_insert(d, firstSimilar), 1);
	assert_int_equal(dictionary_insert(d, secondSimilar), 1);
	assert_int_equal(dictionary_insert(d, thirdSimilar), 1);
	assert_int_equal(dictionary_insert(d, forthSimilar), 1);
	assert_int_equal(dictionary_insert(d, fifthSimilar), 1);
	*state = d;
	return 0;
}
Exemple #4
0
/**
  Test funkcji dictionary_insert().
  Wstawienie pięciu słów do słownika.
  */
static int dictionary_insert_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	if (!dict)
		return -1;
	dictionary_insert(dict, first);
	assert_true(dictionary_find(dict, first));
	assert_false(dictionary_find(dict,second));
	dictionary_insert(dict, second);
	dictionary_insert(dict, third);
	dictionary_insert(dict, fourth);
	dictionary_insert(dict, fifth);
	*state = dict;
	return 0;
}
Exemple #5
0
/**
 Testuje dictionary_insert
 @param[in,out] state Środowisko
 */
static void dictionary_insert_test(void **state)
{
	dictionary *dict = *state;
	const wchar_t *word = L"abc";
	dictionary_insert(dict, word);
	assert_true(dictionary_find(dict, word));
}
/**
  Testuje zapisywanie słownika.
  @param state Środowisko testowe.
  */
static void dictionary_save_test(void** state)
{
    struct dictionary *dict = dictionary_new();

    FILE *stream;
    wchar_t *buf = NULL;
    size_t len;

    stream = open_wmemstream(&buf, &len);
    if (stream == NULL)
    {
        fprintf(stderr, "Failed to open memory stream\n");
        exit(EXIT_FAILURE);
    }

    dictionary_insert(dict, L"ciupaga");
    assert_true(dictionary_save(dict, stream) == 0);
    fflush(stream);
    assert_true(wcscmp(L"ciupaga*^^^^^^^\n0\n", buf) == 0);
    fseek(stream, 0, SEEK_SET);

    fclose(stream);
#   undef free
    free(buf);
#   define free(ptr) _test_free(ptr, __FILE__, __LINE__)
    dictionary_done(dict);
}
Exemple #7
0
static Link addChild(Link self,Link value,Link keys){
    
    Link * args = array_getArray(keys);
    size_t argn  = array_getLength(keys);       
    
    if (argn != 1) return NULL;

    string_t key = object_getString(args[0]);
    
    if ( ! key ) return NULL;
    
    Dict dict = self->value.vptr;
    if ( ! dict){
        dict = self->value.vptr = malloc( sizeof( *dict) );
        dict->dictionary = dictionary_new();
        dict->mutex = mutex_new();
    }
    
    mutex_lock(dict->mutex);    
    Link old = dictionary_insert(dict->dictionary, key, value );
    mutex_unlock(dict->mutex);
    if (old) link_free(old);
    
    return value; // return original not duplicate child
}
/**
  Testuje wstawianie do słownika.
  @param state Środowisko testowe.
  */
static void dictionary_insert_test(void** state)
{
    struct dictionary *dict = dictionary_new();

    size_t n_words = 4;
    wchar_t *words[] = {L"wątły", L"wątły", L"wątlejszy", L"łódka"};

    for (size_t i = 0; i < n_words; i++)
    {
        if (i == 1) assert_false(dictionary_insert(dict, words[i]));
        else assert_true(dictionary_insert(dict, words[i]));
    }

    for (size_t i = 0; i < n_words; i++) assert_true(dictionary_find(dict, words[i]));

    dictionary_done(dict);
}
Exemple #9
0
/** 
  Test funckji dictionary_hints().
  Wstawienie do słownika 7 słów.
  Sprawdzenie, czy funkcja zwraca prawidłowe podpowiedzi.
  */
static void dictionary_hints_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	struct word_list *l = malloc(sizeof(word_list));
    word_list_init(l);
    wchar_t *word1 = L"at";
    wchar_t *word2 = L"car";
    wchar_t *word3 = L"cat";
    wchar_t *word4 = L"cats";
    wchar_t *word5 = L"cut";
    wchar_t *word6 = L"mat";
    wchar_t *word7 = L"rat";
	dictionary_insert(dict, word1);
	dictionary_insert(dict, word2);
	dictionary_insert(dict, word3);
	dictionary_insert(dict, word4);
	dictionary_insert(dict, word5);
	dictionary_insert(dict, word6);
	dictionary_insert(dict, word7);
	dictionary_hints(dict, word3, l);
	assert_string_equal(l->next->word, word1);
	assert_string_equal(l->next->next->word, word2);
	assert_string_equal(l->next->next->next->word, word3);
	assert_string_equal(l->next->next->next->next->word, word4);
	assert_string_equal(l->next->next->next->next->next->word, word5);
	assert_string_equal(l->next->next->next->next->next->next->word, word6);
	assert_string_equal(l->next->next->next->next->next->next->next->word, word7);
	word_list_done(l);
	dictionary_done(dict);
	free(l);
}
Exemple #10
0
/** 
  Test funkcji dictionary_delete().
  Usuwanie wstawionych słów i próba usunięcia nieistniejących.
  */
static void dictionary_delete_test(void** state) {
	struct dictionary *dict = *state;
	assert_true(dictionary_find(dict, first));
	dictionary_delete(dict, first);
	assert_false(dictionary_find(dict, first));
	dictionary_insert(dict,first);
	assert_true(dictionary_find(dict, first));
	dictionary_delete(dict, second);
	assert_false(dictionary_find(dict, second));
	assert_true(dictionary_find(dict, third));
}
Exemple #11
0
void prelude_initialize() {
    int i, n;
    n = sizeof(entries) / sizeof(struct entry);
    prelude = list_nil;
    for (i = 0; i < n; ++i) {
        object_t word;
        word = word_new(string_new(entries[i].name),
                        primitive_new(entries[i].definition),
                        entries[i].parsing_p ? boolean_t : boolean_f);
        prelude = dictionary_insert(prelude, word);
    }
}
Exemple #12
0
int
blossom_datestamp (Blossom * blossom, time_t clock)
{
  struct tm tmr, * ret;
  int century, cyr;
  char year[5];

  ret = gmtime_r (&clock, &tmr);
  if (!ret) return -1;

  /* Make year string (range 0000-9999) */
  century = (ret->tm_year + 1900) / 100;
  cyr = (ret->tm_year + 1900) % 100;
  year[0] = nums[century][0];
  year[1] = nums[century][1];
  year[2] = nums[cyr][0];
  year[3] = nums[cyr][1];
  year[4] = '\0';

  dictionary_insert (blossom->dictionary, "yr", year);
  dictionary_insert (blossom->dictionary, "mo", mo[ret->tm_mon]);
  dictionary_insert (blossom->dictionary, "mo_num", nums[ret->tm_mon+1]);
  dictionary_insert (blossom->dictionary, "da", nums[ret->tm_mday]);
  dictionary_insert (blossom->dictionary, "hr", nums[ret->tm_hour]);
  dictionary_insert (blossom->dictionary, "min", nums[ret->tm_min]);

  return 0;
} 
Exemple #13
0
/**
 Testuje dictionary_find
 @param[in,out] state Środowisko
 */
static void dictionary_find_test(void **state)
{
	dictionary *dict = *state;
	const wchar_t *word = L"abc";
	const wchar_t *word1 = L"abc^";
	const wchar_t *word2 = L"abca";
	const wchar_t *word3 = L"ab";
	assert_false(dictionary_find(dict, word));
	dictionary_insert(dict, word);
	assert_true(dictionary_find(dict, word));
	assert_true(dictionary_find(dict, word1));
	assert_false(dictionary_find(dict, word2));
	assert_false(dictionary_find(dict, word3));
}
Exemple #14
0
/**
  Przygotowsuje środowisko testowe
  @param state Środowisko testowe.
  @return 0 jeśli się udało, -1 w p.p.
  */
static int dictionary_setup(void **state)
{
    struct dictionary *dict = dictionary_new();

    size_t n_words = 6;
    wchar_t *words[] = {L"felin", L"fen", L"fin", L"féin", L"mein", L"tein"};

    for (size_t i = 0; i < n_words; i++)
    {
        dictionary_insert(dict, words[i]);
    }

    *state = dict;

    return 0;
}
/// Test na znajdowanie słów w słowniku.
static void dict_find_test(void **state) {
	struct dictionary* d = *state;
	assert_non_null(d);

	assert_int_equal(dictionary_find(d, L""), 0);

	assert_int_equal(dictionary_find(d, L"x"), 0);
	assert_int_equal(dictionary_find(d, L"az"), 0);
	assert_int_equal(dictionary_find(d, L"axa"), 0);
	assert_int_equal(dictionary_find(d, L"aya"), 0);
	assert_int_equal(dictionary_find(d, L"bm"), 0);
	assert_int_equal(dictionary_find(d, L"bmw"), 0);
	assert_int_equal(dictionary_find(d, L"cd"), 0);
	assert_int_equal(dictionary_find(d, L"cpr"), 0);
	assert_int_equal(dictionary_find(d, L"cpqt"), 0);

	assert_int_equal(dictionary_find(d, L"c"), 1);
	assert_int_equal(dictionary_find(d, L"C"), 1);

	assert_int_equal(dictionary_find(d, L"ax"), 1);
	assert_int_equal(dictionary_find(d, L"Ax"), 1);
	assert_int_equal(dictionary_find(d, L"AX"), 1);    
	assert_int_equal(dictionary_find(d, L"aX"), 1);

	assert_int_equal(dictionary_find(d, L"Cpq"), 1);
	assert_int_equal(dictionary_find(d, L"cPq"), 1);
	assert_int_equal(dictionary_find(d, L"cpQ"), 1);
	assert_int_equal(dictionary_find(d, L"CPq"), 1);
	assert_int_equal(dictionary_find(d, L"CpQ"), 1);
	assert_int_equal(dictionary_find(d, L"cPQ"), 1);
	assert_int_equal(dictionary_find(d, L"CPQ"), 1);

	assert_int_equal(dictionary_find(d, L"b"), 1);
	assert_int_equal(dictionary_find(d, L"B"), 1);

	const wchar_t* veryLong = 
		L"verylongwordnotintreewithpolishcharsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxqwertyuiopąęćńźżół";
	
	assert_int_equal(dictionary_find(d, veryLong), 0);
	assert_int_equal(dictionary_insert(d, veryLong), 1);
	assert_int_equal(dictionary_find(d, veryLong), 1);

}
/// Test na usuwanie słów ze słownika.
static void dict_delete_test(void** state) {
	struct dictionary* d = *state;
	assert_int_equal(dictionary_delete(d, first), 1);
	assert_int_equal(dictionary_find(d, first), 0);
	assert_int_equal(dictionary_insert(d, first), 1);
	assert_int_equal(dictionary_find(d, first), 1);

	assert_int_equal(dictionary_delete(d, second), 1);
	assert_int_equal(dictionary_find(d, second), 0);
	assert_int_equal(dictionary_insert(d, second), 1);
	assert_int_equal(dictionary_find(d, second), 1);

	assert_int_equal(dictionary_delete(d, third), 1);
	assert_int_equal(dictionary_find(d, third), 0);
	assert_int_equal(dictionary_insert(d, third), 1);
	assert_int_equal(dictionary_find(d, third), 1);

	assert_int_equal(dictionary_delete(d, forth), 1);
	assert_int_equal(dictionary_find(d, forth), 0);
	assert_int_equal(dictionary_insert(d, forth), 1);
	assert_int_equal(dictionary_find(d, forth), 1);

	assert_int_equal(dictionary_delete(d, fifth), 1);
	assert_int_equal(dictionary_find(d, fifth), 0);
	assert_int_equal(dictionary_insert(d, fifth), 1);
	assert_int_equal(dictionary_find(d, fifth), 1);

	assert_int_equal(dictionary_delete(d, first), 1);
	assert_int_equal(dictionary_find(d, first), 0);
	assert_int_equal(dictionary_delete(d, first), 0);
	assert_int_equal(dictionary_find(d, first), 0);
	assert_int_equal(dictionary_insert(d, first), 1);
	assert_int_equal(dictionary_find(d, first), 1);

	assert_int_equal(dictionary_delete(d, L""), 0);
	assert_int_equal(dictionary_delete(d, L"x"), 0);
	assert_int_equal(dictionary_delete(d, L"az"), 0);
	assert_int_equal(dictionary_delete(d, L"axa"), 0);
	assert_int_equal(dictionary_delete(d, L"aya"), 0);
	assert_int_equal(dictionary_delete(d, L"bm"), 0);
	assert_int_equal(dictionary_delete(d, L"bmw"), 0);
	assert_int_equal(dictionary_delete(d, L"cd"), 0);
	assert_int_equal(dictionary_delete(d, L"cpr"), 0);
	assert_int_equal(dictionary_delete(d, L"cpqt"), 0);
   
}
Exemple #17
0
int dictionary_insert(struct dictionary *dict, const wchar_t *word)
{
	assert(dict != NULL);
	struct dictionary *node = NULL;

	/* Pierwsze slowo */
	if (dict->children_size == 0)
	{
		for(node = dict; *word; node = *node->children)
		{
			put_child(node, create_node(*word));
			word++;
		}
		put_child(node, create_node(NULL_MARKER));
		return 1;
	}
	node = dict;
	struct dictionary *found = NULL;
	while (find_child(node, &found, *word) && *word)
	{
		node = found;
		word++;
	}
	if (*word == L'\0')
	{
		if (find_child(node, &found, NULL_MARKER))
			return 0;
		put_child(node, create_node(NULL_MARKER));
	}
	else
	{
		struct dictionary *tmp = create_node(*word);
		put_child(node, tmp);
		dictionary_insert(tmp, ++word);
	}
	return 1;
}
Exemple #18
0
static void WhatCheck (GtkMenuItem *item, gpointer data) {
  GtkWidget *dialog;
  GtkTextIter start, end;
  char *word;
  gunichar *wword;
  
  // Znajdujemy pozycję kursora
  gtk_text_buffer_get_iter_at_mark(editor_buf, &start,
                                   gtk_text_buffer_get_insert(editor_buf));

  // Jeśli nie wewnątrz słowa, kończymy
  if (!gtk_text_iter_inside_word(&start)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR,
                                    GTK_BUTTONS_OK,
                                    "Kursor musi być w środku słowa");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    return;
  }

  // Znajdujemy początek i koniec słowa, a potem samo słowo 
  end = start;
  gtk_text_iter_backward_word_start(&start);
  gtk_text_iter_forward_word_end(&end); 
  word = gtk_text_iter_get_text(&start, &end);

  // Zamieniamy na wide char (no prawie)
  wword = g_utf8_to_ucs4_fast(word, -1, NULL);

  if(update_actual_dict() < 0)
    return;
  // Sprawdzamy
  if (dictionary_find(dict, (wchar_t *)wword)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                    "Wszystko w porządku,\nśpij spokojnie");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
  }
  else {
    // Czas korekty
    GtkWidget *vbox, *label, *combo;
    struct word_list hints;
    int i;
    wchar_t **words;

    dictionary_hints(dict, (wchar_t *)wword, &hints);
    words = word_list_get(&hints);
    dialog = gtk_dialog_new_with_buttons("Korekta", NULL, 0, 
                                         GTK_STOCK_OK,
                                         GTK_RESPONSE_ACCEPT,
                                         GTK_STOCK_CANCEL,
                                         GTK_RESPONSE_REJECT,
                                         NULL);
    // W treści dialogu dwa elementy
    vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
    // Tekst
    label = gtk_label_new("Coś nie tak, mam kilka propozycji");
    gtk_widget_show(label);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1);

    // Spuszczane menu
    combo = gtk_combo_box_text_new();
    for (i = 0; i < word_list_size(&hints); i++) {
      // Combo box lubi mieć Gtk
      char *uword = g_ucs4_to_utf8((gunichar *)words[i], -1, NULL, NULL, NULL);

      // Dodajemy kolejny element
      gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), uword);
      g_free(uword);
    }
    //gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo),"<inne...>");
    gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
    gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 1);
    gtk_widget_show(combo);

    char *korekta, *question;
    GtkWidget *ask_dialog, *ask_vbox, *ask_label;
    switch (gtk_dialog_run(GTK_DIALOG(dialog))) {
      case GTK_RESPONSE_ACCEPT:
        korekta =
          gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo));

        // Usuwamy stare
        gtk_text_buffer_delete(editor_buf, &start, &end);
        // Wstawiamy nowe
        gtk_text_buffer_insert(editor_buf, &start, korekta, -1);
        g_free(korekta);
        break;

      case GTK_RESPONSE_REJECT:
        question = "Czy chcesz dodać to słowo do słownika?";
        ask_dialog = gtk_dialog_new_with_buttons(question, NULL, 0, 
                                                 GTK_STOCK_OK,
                                                 GTK_RESPONSE_ACCEPT,
                                                 GTK_STOCK_CANCEL,
                                                 GTK_RESPONSE_REJECT,
                                                 NULL);
        ask_vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
        // Tekst
        ask_label = gtk_label_new("Coś nie tak, mam kilka propozycji");
        gtk_widget_show(ask_label);
        gtk_box_pack_start(GTK_BOX(ask_vbox), ask_label, FALSE, FALSE, 1);

        // Jeśli chiciał dodać nowe słowo do słownika to dodamy i zapiszemy
        if (gtk_dialog_run(GTK_DIALOG(ask_dialog)) == GTK_RESPONSE_ACCEPT) {
          dictionary_insert(dict, (wchar_t *)wword);
          dictionary_save_lang(dict, dict_location);
        }
        
        gtk_widget_destroy(ask_dialog);
        break;
      }
  
    gtk_widget_destroy(dialog);
  }
  
}
static void dictionary_add_test(void** state) {
    struct dictionary * d = dictionary_new();
    dictionary_insert(d, test);
    dictionary_done(d);
}
static void dictionary_find_test(void** state) {
    struct dictionary * d = dictionary_new();
    dictionary_insert(d, test);
    assert_true(dictionary_find(d,test));
    dictionary_done(d);
}
static void dictionary_delete_test(void** state) {
    struct dictionary * d = dictionary_new();
    dictionary_insert(d, test);
    assert_int_equal(dictionary_delete(d, test), 1);
    dictionary_done(d);
}
static void dictionary_insert_the_same(void ** state){
  struct dictionary *d = *state;
  assert_int_equal(dictionary_insert(d, first), 0);
}
Exemple #23
0
int
main(
	void
)
{
	io_printf("%s\n", "I'm a skip list!");
	io_printf("%s\n\n", "Commands:\nInsert (I <key> <value> | 'I 23 test') " \
			"Delete (D <key> | 'D 64') Update (U <key> <new value> | 'U 99 " \
			"muffin')\nQuery (Q <key> | 'Q 16') Print (P | 'P') Find Node (" \
			"F <key> | 'F 72')\n\nX to stop.");

	int key_size, value_size, maxheight;
	key_type_t key_type;
	dictionary_handler_t skip_handler;
	dictionary_t test_dict;

	key_size 	= 4;
	key_type 	= key_type_numeric_signed;
	value_size 	= 10;
	maxheight 	= 7;

	sldict_init(&skip_handler);

	dictionary_create(&skip_handler, &test_dict, key_type, key_size,
														value_size, maxheight);

	char in;
	while( (in = getchar()) != 'X')
	{
#if DEBUG > 0
		io_printf("You said: %c\n", in);
#endif

		switch(in)
		{
			case 'P': {
#if DEBUG > 0
				io_printf("%s\n", "Printing skiplist");
#endif
				print_skiplist((skiplist_t*) test_dict.instance);
				break;
			}

			case 'I': {
							int		 key;
				unsigned 	char	 value[10];
				scanf("%i %s", &key, value);
#if DEBUG > 0
				io_printf("Inserting (%d|%s)...\n", key, value);
#endif
				dictionary_insert(&test_dict, (ion_key_t) &key, value);
				break;
			}

			case 'D': {
				int key;
				scanf("%i", &key);
#if DEBUG > 0
				io_printf("Deleting (%d)...\n", key);
#endif
				dictionary_delete(&test_dict, (ion_key_t) &key);
				break;
			}

			case 'U': {
							int 	key;
				unsigned 	char 	value[10];
				scanf("%i %s", &key, value);
#if DEBUG > 0
				io_printf("Updating (%d with %s)...\n", key, value);
#endif
				dictionary_update(&test_dict, (ion_key_t) &key, value);
				break;
			}

			case 'Q': {
							int 	key;
				unsigned 	char 	value[10];
				scanf("%i", &key);
#if DEBUG > 0
				io_printf("Querying (%d)...\n", key);
#endif
				dictionary_get(&test_dict, (ion_key_t) &key, value);
				io_printf("Got the value back of '%s' stored in %d.\n", value,
																		key);
				break;
			}
			case 'F': {
				int key;
				scanf("%i", &key);
#if DEBUG > 0
				io_printf("Finding Node (%d)...\n", key);
#endif
				sl_node_t 	*node = sl_find_node(
										(skiplist_t*) test_dict.instance,
										(ion_key_t) &key
									);
				io_printf("Got back node, key '%d'.\n",
							NULL != node->key ? *((int*) node->key) : -1337);
				break;
			}
		}

		io_printf("%s", "\n");
		getchar(); /* Eat newline */
	}

	dictionary_delete_dictionary(&test_dict);
	return 0;
}
Exemple #24
0
/**
  Sprawdzenie słowa, na którym aktualnie znajduje się kursor. Ewentualne dodanie do słownika.
  @param[in] item element menu.
  @param[in] data wskaźnik na wartość.
  */
static void WhatCheck (GtkMenuItem *item, gpointer data) {
  GtkWidget *dialog;
  GtkTextIter start, end;
  char *word;
  gunichar *wword;

  //load_dictionary_from_menu(&dict);
  
  // Znajdujemy pozycję kursora
  gtk_text_buffer_get_iter_at_mark(editor_buf, &start,
                                   gtk_text_buffer_get_insert(editor_buf));

  // Jeśli nie wewnątrz słowa, kończymy
  if (!gtk_text_iter_inside_word(&start)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR,
                                    GTK_BUTTONS_OK,
                                    "Kursor musi być w środku słowa");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    return;
  }

  // Znajdujemy początek i koniec słowa, a potem samo słowo 
  end = start;
  gtk_text_iter_backward_word_start(&start);
  gtk_text_iter_forward_word_end(&end); 
  word = gtk_text_iter_get_text(&start, &end);

  // Zamieniamy na wide char (no prawie)
  wword = g_utf8_to_ucs4_fast(word, -1, NULL);
  
  if (!make_lowercase(wword)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                    "Podane słowo nie jest słowem słownikowym.");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
  }
  else {
    // Sprawdzamy
    if (dictionary_find(dict, (wchar_t *)wword)) {
      dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                      "Wszystko w porządku,\nśpij spokojnie");
      gtk_dialog_run(GTK_DIALOG(dialog));
      gtk_widget_destroy(dialog);
    }
    else {
      // Czas korekty
      GtkWidget *vbox, *label, *combo;
      struct word_list hints;
      int i;
      wchar_t **words;

      dictionary_hints(dict, (wchar_t *)wword, &hints);
      words = (wchar_t **) word_list_get(&hints);
      dialog = gtk_dialog_new_with_buttons("Korekta", NULL, 0, 
                                           GTK_STOCK_OK,
                                           GTK_RESPONSE_ACCEPT,
                                           GTK_STOCK_ADD,
                                           GTK_RESPONSE_APPLY,
                                           GTK_STOCK_CANCEL,
                                           GTK_RESPONSE_REJECT,
                                           NULL);
      // W treści dialogu dwa elementy
      vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
      // Tekst
      label = gtk_label_new("Słowo nie znajduje się w słowniku. Wybierz \njedną z propozycji lub dodaj słowa do słownika.");
      gtk_widget_show(label);
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1);

      // Spuszczane menu
      combo = gtk_combo_box_text_new();
      for (i = 0; i < word_list_size(&hints); i++) {
        // Combo box lubi mieć Gtk
        char *uword = g_ucs4_to_utf8((gunichar *)words[i], -1, NULL, NULL, NULL);

        // Dodajemy kolejny element
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), uword);
        g_free(uword);
      }
      gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
      gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 1);
      gtk_widget_show(combo);

      gint click = gtk_dialog_run(GTK_DIALOG(dialog));

      if (click == GTK_RESPONSE_ACCEPT) {
        char *korekta =
          gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo));

        // Usuwamy stare
        gtk_text_buffer_delete(editor_buf, &start, &end);
        // Wstawiamy nowe
        gtk_text_buffer_insert(editor_buf, &start, korekta, -1);
        g_free(korekta);
      }
      // Proponujemy dodanie słowa do słownika
      else if (click == GTK_RESPONSE_APPLY)
        dictionary_insert(dict, wword);
      gtk_widget_destroy(dialog);
    }
  }
  g_free(word);
  g_free(wword);
}
/// Testuje dodawanie słów do słownika po wszystkich ścieżkach drzewa.
static void dict_insert_test(void** state) {
	struct dictionary* d = *state;
	
	assert_int_equal(dictionary_insert(d, L""), 0);

	assert_int_equal(dictionary_insert(d, L"x"), 1);
	assert_int_equal(dictionary_find(d, L"x"), 1);

	assert_int_equal(dictionary_insert(d, L"az"), 1);
	assert_int_equal(dictionary_find(d, L"az"), 1);

	assert_int_equal(dictionary_insert(d, L"axa"), 1);
	assert_int_equal(dictionary_find(d, L"axa"), 1);

	assert_int_equal(dictionary_insert(d, L"aya"), 1);
	assert_int_equal(dictionary_find(d, L"aya"), 1);

	assert_int_equal(dictionary_insert(d, L"bm"), 1);
	assert_int_equal(dictionary_find(d, L"bm"), 1);

	assert_int_equal(dictionary_insert(d, L"bmw"), 1);
	assert_int_equal(dictionary_find(d, L"bmw"), 1);

	assert_int_equal(dictionary_insert(d, L"cd"), 1);
	assert_int_equal(dictionary_find(d, L"cd"), 1);

	assert_int_equal(dictionary_insert(d, L"cpr"), 1);
	assert_int_equal(dictionary_find(d, L"cpr"), 1);

	assert_int_equal(dictionary_insert(d, L"cpqt"), 1);
	assert_int_equal(dictionary_find(d, L"cpqt"), 1);


	assert_int_equal(dictionary_insert(d, L"c"), 0);
	assert_int_equal(dictionary_insert(d, L"C"), 0);

	assert_int_equal(dictionary_insert(d, L"ax"), 0);
	assert_int_equal(dictionary_insert(d, L"Ax"), 0);
	assert_int_equal(dictionary_insert(d, L"AX"), 0);    
	assert_int_equal(dictionary_insert(d, L"aX"), 0);

	assert_int_equal(dictionary_insert(d, L"Cpq"), 0);
	assert_int_equal(dictionary_insert(d, L"cPq"), 0);
	assert_int_equal(dictionary_insert(d, L"cpQ"), 0);
	assert_int_equal(dictionary_insert(d, L"CPq"), 0);
	assert_int_equal(dictionary_insert(d, L"CpQ"), 0);
	assert_int_equal(dictionary_insert(d, L"cPQ"), 0);
	assert_int_equal(dictionary_insert(d, L"CPQ"), 0);

	assert_int_equal(dictionary_insert(d, L"b"), 0);
	assert_int_equal(dictionary_insert(d, L"B"), 0);

}