mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added head_unit tests
This commit is contained in:
parent
c641ebb8a4
commit
a05a65febe
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ roster
|
|||||||
*.o
|
*.o
|
||||||
*.log
|
*.log
|
||||||
*.swp
|
*.swp
|
||||||
|
testsuite
|
||||||
|
13
Makefile
13
Makefile
@ -1,9 +1,12 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
|
WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
|
||||||
LIBS = -lxml2 -lexpat -lssl -lresolv -lncurses -L ~/lib -lstrophe
|
LIBS = -lxml2 -lexpat -lssl -lresolv -lncurses -L ~/lib -lstrophe
|
||||||
|
TESTLIB = -L ~/lib -l headunit
|
||||||
|
CPPLIB = -lstdc++
|
||||||
CFLAGS = -I ~/include -O3 $(WARNS) $(LIBS)
|
CFLAGS = -I ~/include -O3 $(WARNS) $(LIBS)
|
||||||
OBJS = log.o windows.o title_bar.o status_bar.o input_win.o jabber.o \
|
OBJS = log.o windows.o title_bar.o status_bar.o input_win.o jabber.o \
|
||||||
profanity.o util.o command.o history.o main.o
|
profanity.o util.o command.o history.o main.o
|
||||||
|
TESTOBJS = test_history.o history.o
|
||||||
|
|
||||||
profanity: $(OBJS)
|
profanity: $(OBJS)
|
||||||
$(CC) -o profanity $(OBJS) $(LIBS)
|
$(CC) -o profanity $(OBJS) $(LIBS)
|
||||||
@ -20,8 +23,18 @@ command.o: command.h util.h history.h
|
|||||||
history.o: history.h
|
history.o: history.h
|
||||||
main.o: profanity.h
|
main.o: profanity.h
|
||||||
|
|
||||||
|
test_history.o: history.h
|
||||||
|
|
||||||
|
testsuite: testsuite.h $(TESTOBJS)
|
||||||
|
$(CC) $(CFLAGS) $(CPPLIB) testsuite.c $(TESTOBJS) -o testsuite $(TESTLIB)
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: testsuite
|
||||||
|
./testsuite
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f profanity
|
rm -f profanity
|
||||||
rm -f profanity.log
|
rm -f profanity.log
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
rm -f testsuite
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_HISTORY 100
|
#define MAX_HISTORY 100
|
||||||
@ -30,6 +31,10 @@ static int _pos;
|
|||||||
|
|
||||||
void history_init(void)
|
void history_init(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < _size; i++)
|
||||||
|
free(_history[i]);
|
||||||
|
|
||||||
_size = 0;
|
_size = 0;
|
||||||
_pos = -1;
|
_pos = -1;
|
||||||
}
|
}
|
||||||
|
130
test_history.c
Normal file
130
test_history.c
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <head-unit.h>
|
||||||
|
#include "history.h"
|
||||||
|
|
||||||
|
static void beforetest(void)
|
||||||
|
{
|
||||||
|
history_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void previous_returns_null_after_init(void)
|
||||||
|
{
|
||||||
|
char *prev = history_previous();
|
||||||
|
assert_true(prev == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void next_returns_null_after_init(void)
|
||||||
|
{
|
||||||
|
char *next = history_next();
|
||||||
|
assert_true(next == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_after_init_doesnt_fail(void)
|
||||||
|
{
|
||||||
|
history_append("try append");
|
||||||
|
assert_true(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_then_previous_returns_appended(void)
|
||||||
|
{
|
||||||
|
history_append("try append");
|
||||||
|
char *prev = history_previous();
|
||||||
|
assert_string_equals(prev, "try append");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_then_next_returns_null(void)
|
||||||
|
{
|
||||||
|
history_append("try append");
|
||||||
|
char *next = history_next();
|
||||||
|
assert_true(next == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hits_null_at_top(void)
|
||||||
|
{
|
||||||
|
history_append("cmd1");
|
||||||
|
history_append("cmd2");
|
||||||
|
history_previous(); // cmd2
|
||||||
|
history_previous(); // cmd1
|
||||||
|
char *prev = history_previous();
|
||||||
|
assert_true(prev == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void navigate_to_correct_item(void)
|
||||||
|
{
|
||||||
|
history_append("cmd1");
|
||||||
|
history_append("cmd2");
|
||||||
|
history_append("cmd3");
|
||||||
|
history_append("cmd4");
|
||||||
|
history_append("cmd5");
|
||||||
|
history_append("cmd6");
|
||||||
|
|
||||||
|
history_previous(); // cmd6
|
||||||
|
history_previous(); // cmd5
|
||||||
|
history_previous(); // cmd4
|
||||||
|
history_previous(); // cmd3
|
||||||
|
history_next(); // cmd4
|
||||||
|
history_previous(); // cmd3
|
||||||
|
history_previous(); // cmd2
|
||||||
|
char *str = history_next(); // cmd3
|
||||||
|
|
||||||
|
assert_string_equals(str, "cmd3");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void append_previous_item(void)
|
||||||
|
{
|
||||||
|
history_append("cmd1");
|
||||||
|
history_append("cmd2");
|
||||||
|
history_append("cmd3");
|
||||||
|
history_append("cmd4");
|
||||||
|
history_append("cmd5");
|
||||||
|
history_append("cmd6");
|
||||||
|
|
||||||
|
history_previous(); // cmd6
|
||||||
|
history_previous(); // cmd5
|
||||||
|
history_previous(); // cmd4
|
||||||
|
history_previous(); // cmd3
|
||||||
|
history_next(); // cmd4
|
||||||
|
history_previous(); // cmd3
|
||||||
|
history_previous(); // cmd2
|
||||||
|
char *str = history_next(); // cmd3
|
||||||
|
|
||||||
|
history_append(str);
|
||||||
|
|
||||||
|
char *cmd3_1 = history_previous();
|
||||||
|
assert_string_equals(cmd3_1, "cmd3");
|
||||||
|
|
||||||
|
char *cmd6 = history_previous();
|
||||||
|
assert_string_equals(cmd6, "cmd6");
|
||||||
|
|
||||||
|
char *cmd5 = history_previous();
|
||||||
|
assert_string_equals(cmd5, "cmd5");
|
||||||
|
|
||||||
|
char *cmd4 = history_previous();
|
||||||
|
assert_string_equals(cmd4, "cmd4");
|
||||||
|
|
||||||
|
char *cmd3 = history_previous();
|
||||||
|
assert_string_equals(cmd3, "cmd3");
|
||||||
|
|
||||||
|
char *cmd2 = history_previous();
|
||||||
|
assert_string_equals(cmd2, "cmd2");
|
||||||
|
|
||||||
|
char *cmd1 = history_previous();
|
||||||
|
assert_string_equals(cmd1, "cmd1");
|
||||||
|
|
||||||
|
char *end = history_previous();
|
||||||
|
assert_true(end == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_history_tests(void)
|
||||||
|
{
|
||||||
|
TEST_MODULE("history tests");
|
||||||
|
BEFORETEST(beforetest);
|
||||||
|
TEST(previous_returns_null_after_init);
|
||||||
|
TEST(next_returns_null_after_init);
|
||||||
|
TEST(append_after_init_doesnt_fail);
|
||||||
|
TEST(append_then_previous_returns_appended);
|
||||||
|
TEST(append_then_next_returns_null);
|
||||||
|
TEST(hits_null_at_top);
|
||||||
|
TEST(navigate_to_correct_item);
|
||||||
|
TEST(append_previous_item);
|
||||||
|
}
|
9
testsuite.c
Normal file
9
testsuite.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <head-unit.h>
|
||||||
|
#include "testsuite.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
register_history_tests();
|
||||||
|
run_suite();
|
||||||
|
return 0;
|
||||||
|
}
|
6
testsuite.h
Normal file
6
testsuite.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef TESTSUITE_H
|
||||||
|
#define TESTSUITE_H
|
||||||
|
|
||||||
|
void register_history_tests(void);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user