mirror of
https://gitlab.com/klmp200/fish.git
synced 2024-11-22 00:33:20 +00:00
Tests complets de utils
This commit is contained in:
parent
e9e19fbf61
commit
b33f1ef973
@ -4,5 +4,5 @@ project(fish_shell)
|
|||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow")
|
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow")
|
||||||
|
|
||||||
file(GLOB SOURCE_FILES *)
|
set(SOURCE_FILES main.c fish_types.h fish_core.h fish_core.c fish_commands.c fish_commands.h fish_globbing.c fish_globbing.h fish_utils.c fish_utils.h)
|
||||||
add_executable(fish ${SOURCE_FILES})
|
add_executable(fish ${SOURCE_FILES})
|
@ -10,9 +10,6 @@
|
|||||||
#include "fish_core.h"
|
#include "fish_core.h"
|
||||||
#include "fish_globbing.h"
|
#include "fish_globbing.h"
|
||||||
|
|
||||||
#define FISH_BUFFER_SIZE 1024
|
|
||||||
#define FISH_TOKENS " \t\r\n\a"
|
|
||||||
|
|
||||||
void fishLoop(Settings * settings){
|
void fishLoop(Settings * settings){
|
||||||
char * line = NULL;
|
char * line = NULL;
|
||||||
WordList* splited = NULL;
|
WordList* splited = NULL;
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
#ifndef FISH_FISH_CORE_H
|
#ifndef FISH_FISH_CORE_H
|
||||||
#define FISH_FISH_CORE_H
|
#define FISH_FISH_CORE_H
|
||||||
|
|
||||||
|
#define FISH_BUFFER_SIZE 1024
|
||||||
|
#define FISH_TOKENS " \t\r\n\a"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "fish_types.h"
|
#include "fish_types.h"
|
||||||
#include "fish_commands.h"
|
#include "fish_commands.h"
|
||||||
@ -12,7 +16,7 @@
|
|||||||
|
|
||||||
/* WordArray functions */
|
/* WordArray functions */
|
||||||
|
|
||||||
WordList * split(char *string, char *separator);
|
WordList * split(char *string, char *separator); // Tested
|
||||||
|
|
||||||
/* Settings functions */
|
/* Settings functions */
|
||||||
|
|
||||||
@ -26,7 +30,7 @@ void fishLoop(Settings * settings);
|
|||||||
|
|
||||||
char * fishReadLine();
|
char * fishReadLine();
|
||||||
|
|
||||||
int countSeparators(char *string, char *separators);
|
int countSeparators(char *string, char *separators); // Tested
|
||||||
|
|
||||||
|
|
||||||
int fishLoad(WordArray *array);
|
int fishLoad(WordArray *array);
|
||||||
|
@ -50,7 +50,6 @@ void freeWordArray(WordArray *array) {
|
|||||||
free(array->words);
|
free(array->words);
|
||||||
free(array);
|
free(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,22 +7,22 @@
|
|||||||
|
|
||||||
#include "fish_types.h"
|
#include "fish_types.h"
|
||||||
|
|
||||||
void crash();
|
void crash(); // Tested
|
||||||
|
|
||||||
char *getInsult();
|
char *getInsult(); // Tested
|
||||||
|
|
||||||
void freeWordArray(WordArray *array);
|
void freeWordArray(WordArray *array); // Tested
|
||||||
|
|
||||||
WordList * createWordList();
|
WordList * createWordList(); // Tested
|
||||||
|
|
||||||
void addWordList(WordList *list, char *word);
|
void addWordList(WordList *list, char *word); // Tested
|
||||||
|
|
||||||
void removeWordList(WordList *list);
|
void removeWordList(WordList *list); // Tested
|
||||||
|
|
||||||
void freeWordList(WordList *list);
|
void freeWordList(WordList *list); // Tested
|
||||||
|
|
||||||
WordArray * wordListToWordArray(WordList *list);
|
WordArray * wordListToWordArray(WordList *list); // Tested
|
||||||
|
|
||||||
WordList * wordArrayToWordList(WordArray * array);
|
WordList * wordArrayToWordList(WordArray * array); // Tested
|
||||||
|
|
||||||
#endif //FISH_FISH_UTILS_H
|
#endif //FISH_FISH_UTILS_H
|
||||||
|
@ -11,7 +11,7 @@ include_directories(
|
|||||||
"${source_dir}/googlemock/include"
|
"${source_dir}/googlemock/include"
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB SOURCE_FILES_TESTS *)
|
set(SOURCE_FILES_TESTS main.cpp FishCoreTests.cpp FishUtilsTests.cpp)
|
||||||
|
|
||||||
add_executable(fish_tests ${SOURCE_FILES_TESTS})
|
add_executable(fish_tests ${SOURCE_FILES_TESTS})
|
||||||
|
|
||||||
|
@ -2,16 +2,9 @@
|
|||||||
// Created by Antoine Bartuccio on 15/05/2017.
|
// Created by Antoine Bartuccio on 15/05/2017.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "FishCoreTests.h"
|
#include "gtest/gtest.h"
|
||||||
#include "../fish_shell/fish_core.c"
|
#include "../fish_shell/fish_types.h"
|
||||||
#include "../fish_shell/fish_utils.c"
|
#include "../fish_shell/fish_core.h"
|
||||||
#include "../fish_shell/fish_commands.c"
|
|
||||||
#include "../fish_shell/fish_globbing.c"
|
|
||||||
|
|
||||||
|
|
||||||
//TEST_F(FishCoreTests, split){
|
|
||||||
// ASSERT_TRUE(true);
|
|
||||||
//}
|
|
||||||
|
|
||||||
TEST(command_split, split){
|
TEST(command_split, split){
|
||||||
char input[] = "git push --force";
|
char input[] = "git push --force";
|
||||||
@ -34,3 +27,7 @@ TEST(command_split, split){
|
|||||||
freeWordList(list);
|
freeWordList(list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(count_tokens, countSeparators){
|
||||||
|
ASSERT_TRUE(countSeparators((char*) "Ceci est un super \n test", (char*) FISH_TOKENS) == 6);
|
||||||
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Antoine Bartuccio on 15/05/2017.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef FISH_FISH_CORE_TESTS_H
|
|
||||||
#define FISH_FISH_CORE_TESTS_H
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
class FishCoreTests : public ::testing::Test {
|
|
||||||
void SetUp() {}
|
|
||||||
void TearDown(){}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //FISH_FISH_CORE_TESTS_H
|
|
210
fish_shell_tests/FishUtilsTests.cpp
Normal file
210
fish_shell_tests/FishUtilsTests.cpp
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
//
|
||||||
|
// Created by Antoine Bartuccio on 16/05/2017.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "../fish_shell/fish_utils.h"
|
||||||
|
#include "../fish_shell/fish_types.h"
|
||||||
|
|
||||||
|
TEST(crash_test, crash){
|
||||||
|
ASSERT_DEATH(crash(), "[A-z]+");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(get_an_insult, getInsult){
|
||||||
|
ASSERT_EQ(typeid(char*), typeid(getInsult()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_list_init, createWordList){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
ASSERT_FALSE(list == NULL);
|
||||||
|
ASSERT_TRUE(list->first == NULL);
|
||||||
|
ASSERT_TRUE(list->last == NULL);
|
||||||
|
ASSERT_TRUE(list->size == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_list_add, addWordList){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
char test1[] = "Test1";
|
||||||
|
char test2[] = "Test2";
|
||||||
|
char test3[] = "Test3";
|
||||||
|
|
||||||
|
addWordList(list, test1);
|
||||||
|
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);
|
||||||
|
|
||||||
|
addWordList(list, test2);
|
||||||
|
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));
|
||||||
|
|
||||||
|
addWordList(list, test3);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_list_remove, removeWordList){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
char word[] = "lel";
|
||||||
|
|
||||||
|
addWordList(list, word);
|
||||||
|
addWordList(list, word);
|
||||||
|
addWordList(list, word);
|
||||||
|
|
||||||
|
ASSERT_TRUE(list->size == 3);
|
||||||
|
|
||||||
|
removeWordList(list);
|
||||||
|
|
||||||
|
ASSERT_TRUE(list->size == 2);
|
||||||
|
|
||||||
|
removeWordList(list);
|
||||||
|
|
||||||
|
ASSERT_TRUE(list->size == 1);
|
||||||
|
|
||||||
|
freeWordList(list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_list_free, freeWordList){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
char word[] = "lel";
|
||||||
|
addWordList(list, word);
|
||||||
|
addWordList(list, word);
|
||||||
|
addWordList(list, word);
|
||||||
|
|
||||||
|
freeWordList(list);
|
||||||
|
|
||||||
|
list = createWordList();
|
||||||
|
|
||||||
|
freeWordList(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_list_to_word_array, wordListToWordArray){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
WordListElement *elem = NULL;
|
||||||
|
WordArray *array = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
char test1[] = "Test1";
|
||||||
|
char test2[] = "Test2";
|
||||||
|
char test3[] = "Test3";
|
||||||
|
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test1);
|
||||||
|
|
||||||
|
array = wordListToWordArray(list);
|
||||||
|
ASSERT_FALSE(array == NULL);
|
||||||
|
ASSERT_FALSE(array->words == NULL);
|
||||||
|
|
||||||
|
list = createWordList();
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test1);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_array_to_word_list, wordArrayToWordList){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
WordList *list2 = NULL;
|
||||||
|
WordListElement *elem = NULL;
|
||||||
|
WordArray *array = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
char test1[] = "Test1";
|
||||||
|
char test2[] = "Test2";
|
||||||
|
char test3[] = "Test3";
|
||||||
|
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test1);
|
||||||
|
|
||||||
|
array = wordListToWordArray(list);
|
||||||
|
list2 = wordArrayToWordList(array);
|
||||||
|
|
||||||
|
list = createWordList();
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test1);
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(word_array_free, freeWordArray){
|
||||||
|
WordList *list = createWordList();
|
||||||
|
WordArray *array = NULL;
|
||||||
|
|
||||||
|
char test1[] = "Test1";
|
||||||
|
char test2[] = "Test2";
|
||||||
|
char test3[] = "Test3";
|
||||||
|
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test2);
|
||||||
|
addWordList(list, test3);
|
||||||
|
addWordList(list, test1);
|
||||||
|
addWordList(list, test1);
|
||||||
|
|
||||||
|
array = wordListToWordArray(list);
|
||||||
|
|
||||||
|
freeWordArray(array);
|
||||||
|
}
|
@ -3,6 +3,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "../fish_shell/fish_core.c"
|
||||||
|
#include "../fish_shell/fish_utils.c"
|
||||||
|
#include "../fish_shell/fish_commands.c"
|
||||||
|
#include "../fish_shell/fish_globbing.c"
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user