Skip to content

Commit 7cd01f6

Browse files
authored
Merge pull request #7 from 1wErt3r/develop
Use unity for tests
2 parents 8ff1dce + 4bd5c1b commit 7cd01f6

5 files changed

Lines changed: 57 additions & 69 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build
32

43
on:
@@ -10,11 +9,13 @@ on:
109
jobs:
1110
build:
1211
runs-on: ubuntu-latest
13-
12+
1413
steps:
1514
- name: Checkout code
1615
uses: actions/checkout@v4
17-
16+
with:
17+
submodules: recursive
18+
1819
- name: Configure dpkg to skip docs
1920
run: |
2021
sudo mkdir -p /etc/dpkg/dpkg.cfg.d
@@ -47,4 +48,4 @@ jobs:
4748
run: |
4849
cd src
4950
make test_basic
50-
./test_basic
51+
./test_basic

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/unity"]
2+
path = vendor/unity
3+
url = https://github.com/ThrowTheSwitch/Unity.git

src/Makefile.am

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ eradio_SOURCES = main.c ui.c radio_player.c station_list.c http.c favorites.c \
66
eradio_CFLAGS = $(EFL_CFLAGS) $(LIBXML_CFLAGS)
77
eradio_LDADD = $(EFL_LIBS) $(LIBXML_LIBS)
88

9-
# Test program
9+
# Test program with Unity framework
1010
noinst_PROGRAMS = test_basic
1111

12-
test_basic_SOURCES = tests/test_basic.c appdata.h
13-
test_basic_CFLAGS = $(EFL_CFLAGS)
12+
# Unity framework sources
13+
UNITY_SRC = $(top_srcdir)/vendor/unity/src/unity.c
14+
UNITY_HDR = $(top_srcdir)/vendor/unity/src/unity.h
15+
16+
test_basic_SOURCES = tests/test_basic.c appdata.h $(UNITY_SRC)
17+
test_basic_CFLAGS = $(EFL_CFLAGS) -I$(top_srcdir)/vendor/unity/src
1418
test_basic_LDADD = $(EFL_LIBS_NO_CON)

src/tests/test_basic.c

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,46 @@
22
#include <stdlib.h>
33
#include <string.h>
44

5+
// Include Unity testing framework
6+
#include "unity.h"
7+
58
// Include the core data structures we want to test
69
#include "../appdata.h"
710

8-
// Simple test framework macros
9-
#define TEST_ASSERT(condition, message) \
10-
do { \
11-
if (!(condition)) { \
12-
printf("FAIL: %s\n", message); \
13-
return 0; \
14-
} else { \
15-
printf("PASS: %s\n", message); \
16-
} \
17-
} while(0)
11+
// setUp and tearDown functions (optional)
12+
void setUp(void) {
13+
// This runs before each test
14+
}
15+
16+
void tearDown(void) {
17+
// This runs after each test
18+
}
1819

1920
// Test functions
20-
int test_station_creation() {
21+
void test_station_creation(void) {
2122
Station station = {0};
2223

2324
station.name = "Test Radio Station";
2425
station.url = "http://example.com/stream";
2526
station.bitrate = 128;
2627
station.favorite = EINA_TRUE;
2728

28-
TEST_ASSERT(station.name != NULL, "Station name should be set");
29-
TEST_ASSERT(strcmp(station.name, "Test Radio Station") == 0, "Station name should match");
30-
TEST_ASSERT(station.bitrate == 128, "Station bitrate should be 128");
31-
TEST_ASSERT(station.favorite == EINA_TRUE, "Station favorite should be true");
32-
33-
return 1;
29+
TEST_ASSERT_NOT_NULL(station.name);
30+
TEST_ASSERT_EQUAL_STRING("Test Radio Station", station.name);
31+
TEST_ASSERT_EQUAL(128, station.bitrate);
32+
TEST_ASSERT_EQUAL(EINA_TRUE, station.favorite);
3433
}
3534

36-
int test_view_mode_enum() {
35+
void test_view_mode_enum(void) {
3736
ViewMode search_mode = VIEW_SEARCH;
3837
ViewMode favorites_mode = VIEW_FAVORITES;
3938

40-
TEST_ASSERT(search_mode == 0, "VIEW_SEARCH should be 0");
41-
TEST_ASSERT(favorites_mode == 1, "VIEW_FAVORITES should be 1");
42-
TEST_ASSERT(search_mode != favorites_mode, "View modes should be different");
43-
44-
return 1;
39+
TEST_ASSERT_EQUAL(0, search_mode);
40+
TEST_ASSERT_EQUAL(1, favorites_mode);
41+
TEST_ASSERT_NOT_EQUAL(search_mode, favorites_mode);
4542
}
4643

47-
int test_appdata_structure() {
44+
void test_appdata_structure(void) {
4845
AppData appdata = {0};
4946

5047
// Initialize some basic fields
@@ -53,15 +50,13 @@ int test_appdata_structure() {
5350
appdata.view_mode = VIEW_SEARCH;
5451
appdata.loading_requests = 5;
5552

56-
TEST_ASSERT(appdata.playing == EINA_FALSE, "Playing should be false initially");
57-
TEST_ASSERT(appdata.filters_visible == EINA_TRUE, "Filters visible should be true");
58-
TEST_ASSERT(appdata.view_mode == VIEW_SEARCH, "View mode should be SEARCH");
59-
TEST_ASSERT(appdata.loading_requests == 5, "Loading requests should be 5");
60-
61-
return 1;
53+
TEST_ASSERT_EQUAL(EINA_FALSE, appdata.playing);
54+
TEST_ASSERT_EQUAL(EINA_TRUE, appdata.filters_visible);
55+
TEST_ASSERT_EQUAL(VIEW_SEARCH, appdata.view_mode);
56+
TEST_ASSERT_EQUAL(5, appdata.loading_requests);
6257
}
6358

64-
int test_station_string_fields() {
59+
void test_station_string_fields(void) {
6560
Station station = {0};
6661

6762
station.name = "Jazz FM";
@@ -73,38 +68,22 @@ int test_station_string_fields() {
7368
station.codec = "MP3";
7469
station.tags = "jazz,music";
7570

76-
TEST_ASSERT(strcmp(station.name, "Jazz FM") == 0, "Station name should be Jazz FM");
77-
TEST_ASSERT(strcmp(station.url, "http://jazz.fm/stream.mp3") == 0, "Station URL should match");
78-
TEST_ASSERT(strcmp(station.country, "USA") == 0, "Station country should be USA");
79-
TEST_ASSERT(strcmp(station.language, "English") == 0, "Station language should be English");
80-
TEST_ASSERT(strcmp(station.codec, "MP3") == 0, "Station codec should be MP3");
81-
TEST_ASSERT(strcmp(station.tags, "jazz,music") == 0, "Station tags should match");
82-
83-
return 1;
71+
TEST_ASSERT_EQUAL_STRING("Jazz FM", station.name);
72+
TEST_ASSERT_EQUAL_STRING("http://jazz.fm/stream.mp3", station.url);
73+
TEST_ASSERT_EQUAL_STRING("USA", station.country);
74+
TEST_ASSERT_EQUAL_STRING("English", station.language);
75+
TEST_ASSERT_EQUAL_STRING("MP3", station.codec);
76+
TEST_ASSERT_EQUAL_STRING("jazz,music", station.tags);
8477
}
8578

8679
// Main test runner
87-
int main() {
88-
printf("Running eradio basic tests...\n");
89-
printf("================================\n");
90-
91-
int passed = 0;
92-
int total = 0;
93-
94-
// Run tests
95-
total++; passed += test_station_creation();
96-
total++; passed += test_view_mode_enum();
97-
total++; passed += test_appdata_structure();
98-
total++; passed += test_station_string_fields();
99-
100-
printf("================================\n");
101-
printf("Test Results: %d/%d tests passed\n", passed, total);
102-
103-
if (passed == total) {
104-
printf("All tests PASSED!\n");
105-
return EXIT_SUCCESS;
106-
} else {
107-
printf("Some tests FAILED!\n");
108-
return EXIT_FAILURE;
109-
}
80+
int main(void) {
81+
UNITY_BEGIN();
82+
83+
RUN_TEST(test_station_creation);
84+
RUN_TEST(test_view_mode_enum);
85+
RUN_TEST(test_appdata_structure);
86+
RUN_TEST(test_station_string_fields);
87+
88+
return UNITY_END();
11089
}

vendor/unity

Submodule unity added at 36e9b19

0 commit comments

Comments
 (0)