2017-05-16 00:58:16 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 16/05/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "../fish_shell/fish_utils.h"
|
|
|
|
#include "../fish_shell/fish_types.h"
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(crash_crash_Test, crash){
|
2017-05-16 00:58:16 +00:00
|
|
|
ASSERT_DEATH(crash(), "[A-z]+");
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(get_getInsult_Test, getInsult){
|
2017-05-16 00:58:16 +00:00
|
|
|
ASSERT_EQ(typeid(char*), typeid(getInsult()));
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(create_createWordList_Test, createWordList){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
ASSERT_FALSE(list == NULL);
|
|
|
|
ASSERT_TRUE(list->first == NULL);
|
|
|
|
ASSERT_TRUE(list->last == NULL);
|
|
|
|
ASSERT_TRUE(list->size == 0);
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(add_addBegin__Test, addBeginWordList){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
char test1[] = "Test1";
|
|
|
|
char test2[] = "Test2";
|
|
|
|
char test3[] = "Test3";
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addBeginWordList(list, test1);
|
|
|
|
ASSERT_EQ(list->size, 1);
|
|
|
|
ASSERT_FALSE(list->first == NULL);
|
|
|
|
ASSERT_FALSE(list->last == NULL);
|
|
|
|
ASSERT_EQ(list->first, list->last);
|
|
|
|
ASSERT_FALSE(list->first->word == NULL);
|
|
|
|
ASSERT_STREQ(list->first->word, test1);
|
|
|
|
ASSERT_FALSE(list->first->word == test1);
|
|
|
|
|
|
|
|
addBeginWordList(list, test2);
|
|
|
|
ASSERT_EQ(list->size, 2);
|
|
|
|
ASSERT_FALSE(list->first == list->last);
|
|
|
|
ASSERT_STREQ(list->first->word, test2);
|
|
|
|
ASSERT_STREQ(list->last->word, test1);
|
|
|
|
ASSERT_STRNE(list->first->word, test1);
|
|
|
|
|
|
|
|
addBeginWordList(list, test3);
|
|
|
|
ASSERT_EQ(list->size, 3);
|
|
|
|
ASSERT_FALSE(list->first == list->last);
|
|
|
|
ASSERT_STREQ(list->last->word, test1);
|
|
|
|
ASSERT_STREQ(list->first->next->word, test2);
|
|
|
|
ASSERT_STREQ(list->first->word, test3);
|
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(add_addEndWordList_Test, addEndWordList){
|
|
|
|
WordList *list = createWordList();
|
|
|
|
char test1[] = "Test1";
|
|
|
|
char test2[] = "Test2";
|
|
|
|
char test3[] = "Test3";
|
|
|
|
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
ASSERT_TRUE(list->size == 1);
|
|
|
|
ASSERT_TRUE(list->first != NULL);
|
|
|
|
ASSERT_TRUE(list->last != NULL);
|
|
|
|
ASSERT_TRUE(list->first == list->last);
|
|
|
|
ASSERT_TRUE(list->first->word != NULL);
|
|
|
|
ASSERT_FALSE(strcmp(list->first->word, test1));
|
|
|
|
ASSERT_FALSE(list->first->word == test1);
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test2);
|
2017-05-16 00:58:16 +00:00
|
|
|
ASSERT_TRUE(list->size == 2);
|
|
|
|
ASSERT_TRUE(list->first != list->last);
|
|
|
|
ASSERT_FALSE(strcmp(list->last->word, test2));
|
|
|
|
ASSERT_FALSE(strcmp(list->first->word, test1));
|
|
|
|
ASSERT_TRUE(strcmp(list->first->word, test2));
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test3);
|
2017-05-16 00:58:16 +00:00
|
|
|
ASSERT_TRUE(list->size == 3);
|
|
|
|
ASSERT_TRUE(list->first != list->last);
|
|
|
|
ASSERT_FALSE(strcmp(list->first->word, test1));
|
|
|
|
ASSERT_FALSE(strcmp(list->last->word, test3));
|
|
|
|
ASSERT_TRUE(strcmp(list->last->word, test2));
|
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(remove_removeWordList_Test, removeWordList){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
char word[] = "lel";
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, word);
|
|
|
|
addEndWordList(list, word);
|
|
|
|
addEndWordList(list, word);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(list->size == 3);
|
|
|
|
|
|
|
|
removeWordList(list);
|
|
|
|
|
|
|
|
ASSERT_TRUE(list->size == 2);
|
|
|
|
|
|
|
|
removeWordList(list);
|
|
|
|
|
|
|
|
ASSERT_TRUE(list->size == 1);
|
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(free_freeWordList_Test, freeWordList){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
char word[] = "lel";
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, word);
|
|
|
|
addEndWordList(list, word);
|
|
|
|
addEndWordList(list, word);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
|
|
|
|
list = createWordList();
|
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(word_wordListToWordArray_Test, wordListToWordArray){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
WordListElement *elem = NULL;
|
|
|
|
WordArray *array = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
char test1[] = "Test1";
|
|
|
|
char test2[] = "Test2";
|
|
|
|
char test3[] = "Test3";
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
array = wordListToWordArray(list);
|
|
|
|
ASSERT_FALSE(array == NULL);
|
|
|
|
ASSERT_FALSE(array->words == NULL);
|
|
|
|
|
|
|
|
list = createWordList();
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(list->size, array->size);
|
|
|
|
|
|
|
|
elem = list->first;
|
|
|
|
|
|
|
|
for (i=0; i<array->size; i++){
|
|
|
|
ASSERT_FALSE(strcmp(array->words[i], elem->word));
|
|
|
|
elem = elem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_TRUE(array->words[array->size] == NULL);
|
|
|
|
|
|
|
|
freeWordList(list);
|
|
|
|
freeWordArray(array);
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(word_wordArrayToWordList_Test, wordArrayToWordList){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
WordList *list2 = NULL;
|
|
|
|
WordListElement *elem = NULL;
|
|
|
|
WordArray *array = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
char test1[] = "Test1";
|
|
|
|
char test2[] = "Test2";
|
|
|
|
char test3[] = "Test3";
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
array = wordListToWordArray(list);
|
|
|
|
list2 = wordArrayToWordList(array);
|
|
|
|
|
|
|
|
list = createWordList();
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
array = wordListToWordArray(list);
|
|
|
|
|
|
|
|
ASSERT_TRUE(list2 != NULL);
|
|
|
|
ASSERT_EQ(array->size, list2->size);
|
|
|
|
|
|
|
|
elem = list2->first;
|
|
|
|
|
|
|
|
for (i=0;i<array->size;i++){
|
|
|
|
ASSERT_FALSE(strcmp(array->words[i], elem->word));
|
|
|
|
elem = elem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
freeWordList(list2);
|
|
|
|
freeWordArray(array);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
TEST(free_freeWordArray_Test, freeWordArray){
|
2017-05-16 00:58:16 +00:00
|
|
|
WordList *list = createWordList();
|
|
|
|
WordArray *array = NULL;
|
|
|
|
|
|
|
|
char test1[] = "Test1";
|
|
|
|
char test2[] = "Test2";
|
|
|
|
char test3[] = "Test3";
|
|
|
|
|
2017-05-20 14:25:00 +00:00
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test2);
|
|
|
|
addEndWordList(list, test3);
|
|
|
|
addEndWordList(list, test1);
|
|
|
|
addEndWordList(list, test1);
|
2017-05-16 00:58:16 +00:00
|
|
|
|
|
|
|
array = wordListToWordArray(list);
|
|
|
|
|
|
|
|
freeWordArray(array);
|
2017-05-20 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(split_splitWord__Test, slpitWord){
|
|
|
|
char test1[] = "ls&&ls";
|
|
|
|
char test2[] = "&&";
|
|
|
|
char *splited = splitWord(test1, 2, 2);
|
|
|
|
|
|
|
|
ASSERT_STREQ(test1, "ls");
|
|
|
|
ASSERT_STREQ(splited, "ls");
|
|
|
|
|
|
|
|
free(splited);
|
|
|
|
|
|
|
|
splited = splitWord(test2, 0, 2);
|
|
|
|
|
|
|
|
ASSERT_STREQ(test2, "");
|
|
|
|
ASSERT_STREQ(splited, "");
|
|
|
|
|
|
|
|
free(splited);
|
2017-05-16 00:58:16 +00:00
|
|
|
}
|