diff options
| author | Syndamia <kamen@syndamia.com> | 2024-01-07 12:35:56 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2024-01-07 12:35:56 +0200 |
| commit | 43de4b0bfa52a7b3bf6b92df344bd76a97200e18 (patch) | |
| tree | a1afbc56e524b7a87c9091e6fd0a01f4c5641472 | |
| parent | f5adcdd552f743d372a62a4c30184c4c8cd98cfd (diff) | |
| download | pico-web-43de4b0bfa52a7b3bf6b92df344bd76a97200e18.tar pico-web-43de4b0bfa52a7b3bf6b92df344bd76a97200e18.tar.gz pico-web-43de4b0bfa52a7b3bf6b92df344bd76a97200e18.zip | |
(tests) Setup mocking, everything is now ready for tests
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | .gitmodules | 3 | ||||
| m--------- | tests/CMock | 0 | ||||
| -rw-r--r-- | tests/CMock.yml | 3 | ||||
| -rw-r--r-- | tests/Makefile | 23 | ||||
| -rw-r--r-- | tests/browser-net.tests.c | 40 | ||||
| -rw-r--r-- | tests/helpers.c | 1 | ||||
| -rw-r--r-- | tests/helpers.h | 5 |
8 files changed, 70 insertions, 6 deletions
@@ -4,3 +4,4 @@ server tests/*.tests tests/*.tests_Runner.c +tests/mocks diff --git a/.gitmodules b/.gitmodules index 3120806..1cf4e4e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "tests/Unity"] path = tests/Unity url = https://github.com/ThrowTheSwitch/Unity.git +[submodule "tests/CMock"] + path = tests/CMock + url = https://github.com/ThrowTheSwitch/CMock.git diff --git a/tests/CMock b/tests/CMock new file mode 160000 +Subproject 9192a950897929d948027421e30a372b1770469 diff --git a/tests/CMock.yml b/tests/CMock.yml new file mode 100644 index 0000000..c2bc2b8 --- /dev/null +++ b/tests/CMock.yml @@ -0,0 +1,3 @@ +:cmock: + :plugins: + - :ignore diff --git a/tests/Makefile b/tests/Makefile index 4c6f82b..a3b95cd 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,17 +1,26 @@ RUBY=ruby UNITY_DIR=./Unity +CMOCK_DIR=./CMock + CC=gcc -CFLAGS=-I$(UNITY_DIR)/src +CFLAGS=-I$(UNITY_DIR)/src -I$(CMOCK_DIR)/src -I../src -I./mocks +UNILFILES=../src/sds/sds.c .PHONY: all all: build run .PHONY: build build: - for testfile in $$(find . -type f -name "*.tests.c") ;\ - do \ - $(RUBY) $(UNITY_DIR)/auto/generate_test_runner.rb $$testfile ;\ - $(CC) $(CFLAGS) -o $${testfile%.c} $(UNITY_DIR)/src/unity.c $$testfile $${testfile%.c}_Runner.c ;\ + $(RUBY) $(CMOCK_DIR)/lib/cmock.rb -oCMock.yml $$(find ../src -type f -name "*.h" -not -path "../src/sds/*") + for testfile in $$(find . -type f -name "*.tests.c") ;\ + do \ + $(RUBY) $(UNITY_DIR)/auto/generate_test_runner.rb $$testfile ;\ + includelist=$$(head -1 browser-net.tests.c | cut -c3-) ;\ + $(CC) $(CFLAGS) -o $${testfile%.c} \ + $(UNILFILES) $$(find ./mocks -type f -name "*.c" | grep -Fv $$(echo "$$includelist" | sed 's/ / -e /g')) \ + $$(echo "$$includelist" | sed 's/ / ..\/src\//g') \ + helpers.c $(UNITY_DIR)/src/unity.c $(CMOCK_DIR)/src/cmock.c \ + $$testfile $${testfile%.c}_Runner.c ;\ done .PHONY: run @@ -20,3 +29,7 @@ run: do \ $$runner || exit ;\ done + +.PHONY: clean +clean: + $(RM) *.tests *.tests_Runner.c diff --git a/tests/browser-net.tests.c b/tests/browser-net.tests.c index 2a8fec0..05a4a7c 100644 --- a/tests/browser-net.tests.c +++ b/tests/browser-net.tests.c @@ -1,5 +1,43 @@ +// browser-net.c #include "Unity/src/unity.h" +#include "helpers.h" +#include "../src/sds/sds.h" -void test_True(void) { +#include "../src/browser-net.h" +#include "mocks/Mockutil.h" +#include "mocks/Mockbrowser-cli.h" + +const char ip[] = "127.0.0.1"; +const char port[] = "10800"; +const char URL[] = "/test"; + +// Func_Returns_When + +void test_get_page_ReturnsEmptyLine_WhenURLIsBlank(void) { + streq_ExpectAndReturn("blank", "blank", 1); + sds page = get_page(ip, port, "blank"); + + TEST_ASSERT_EQUAL_STRING(page, "\n"); + + sdsfree(page); +} + +void test_get_page_ReturnsMessage_WhenCannotConnectToServer(void) { + streq_ExpectAndReturn(URL, "blank", 0); + herrc_Expect(3, "socket"); + atop_ExpectAndReturn("0", 0); + /* aton_ExpectAndReturn("255.255.255.255", NULL, -1); */ + /* aton_IgnoreArg_output(); */ + herrc_Expect(0, "inet_aton"); + herrc_Expect(0, "connect"); + + sds page = get_page("255.255.255.255", "0", URL); + + TEST_ASSERT_EQUAL_STRING(page, "Couldn't connect to server!\n"); + + sdsfree(page); +} + +void test_get_page_ReturnsGivenPage_WhenURLIsCorrect(void) { TEST_ASSERT_TRUE(1); } diff --git a/tests/helpers.c b/tests/helpers.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/helpers.c @@ -0,0 +1 @@ + diff --git a/tests/helpers.h b/tests/helpers.h new file mode 100644 index 0000000..e22f67c --- /dev/null +++ b/tests/helpers.h @@ -0,0 +1,5 @@ +#ifndef TEST_HELPERS +#define TEST_HELPERS + + +#endif |
