Add unit test

This commit is contained in:
Lakindu Akash 2021-12-27 01:57:01 +05:30
parent c9d2016a07
commit 53ea4b2e1d
No known key found for this signature in database
GPG Key ID: 6FB0085A614E0AC2
3 changed files with 56 additions and 1 deletions

View File

@ -8,6 +8,10 @@ install:
@echo "Installing..."
cd src && $(MAKE) install
test:
@echo "Testing..."
cd test && $(MAKE)
install-cli-only:
@echo "Installing command line interface only..."
cd src/scripts && $(MAKE) install
@ -19,7 +23,7 @@ uninstall:
clean-old:
cd src && $(MAKE) clean-old
.PHONY: clean
.PHONY: clean test
clean:
cd src && $(MAKE) clean

37
test/Makefile Normal file
View File

@ -0,0 +1,37 @@
CC=gcc
PKGCONFIG = $(shell which pkg-config)
CFLAGS=`pkg-config --cflags gtk+-3.0` -I./../src/ui
LIBS=`pkg-config --libs gtk+-3.0 --libs x11` -lstdc++ -lpng -lqrencode
ODIR=./../build
# Determine this makefile's path.
# Be sure to place this BEFORE `include` directives, if any.
THIS_FILE := $(lastword $(MAKEFILE_LIST))
_OBJ = util.o test_util.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
.PHONY: clean
all: $(OBJ) test
$(ODIR)/util.o: ../src/ui/util.c
$(CC) -c $? -o $@ $(CFLAGS)
$(ODIR)/test_util.o: test_util.c
$(CC) -c $? -o $@ $(CFLAGS)
test: $(OBJ)
$(CC) -o $(ODIR)/test $^
@$(ODIR)/test
clean:
rm -f $(OBJ)
rm -f $(ODIR)/test

14
test/test_util.c Normal file
View File

@ -0,0 +1,14 @@
#include <assert.h>
#include <stdio.h>
#include <util.h>
int main(int argc, char *argv[]){
assert(0 == isValidIPaddress("192.12.23.123"));
assert(0 == isValidIPaddress("255.255.255.255"));
assert(-1 == isValidIPaddress("255.255.255.256"));
assert(-1 == isValidIPaddress("255.255.255.2551"));
assert(-1 == isValidIPaddress("192.168.12"));
return 0;
}