This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository eradio.
View the commit online.
commit 4bd5c1b5711b4795a67537940ce028beb208e066
Author: politebot <[email protected]>
AuthorDate: Tue Oct 21 18:21:41 2025 -0500
Use unity for tests
---
.github/workflows/build.yml | 9 +++--
.gitmodules | 3 ++
src/Makefile.am | 10 +++--
src/tests/test_basic.c | 99 ++++++++++++++++++---------------------------
vendor/unity | 1 +
5 files changed, 55 insertions(+), 67 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index cc51091..5fd1d5f 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,4 +1,3 @@
-
name: Build
on:
@@ -10,11 +9,13 @@ on:
jobs:
build:
runs-on: ubuntu-latest
-
+
steps:
- name: Checkout code
uses: actions/checkout@v4
-
+ with:
+ submodules: recursive
+
- name: Configure dpkg to skip docs
run: |
sudo mkdir -p /etc/dpkg/dpkg.cfg.d
@@ -47,4 +48,4 @@ jobs:
run: |
cd src
make test_basic
- ./test_basic
+ ./test_basic
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..31f22c8
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "vendor/unity"]
+ path = vendor/unity
+ url = ""
diff --git a/src/Makefile.am b/src/Makefile.am
index 6276766..dd66cad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,9 +6,13 @@ eradio_SOURCES = main.c ui.c radio_player.c station_list.c http.c favorites.c \
eradio_CFLAGS = $(EFL_CFLAGS) $(LIBXML_CFLAGS)
eradio_LDADD = $(EFL_LIBS) $(LIBXML_LIBS)
-# Test program
+# Test program with Unity framework
noinst_PROGRAMS = test_basic
-test_basic_SOURCES = tests/test_basic.c appdata.h
-test_basic_CFLAGS = $(EFL_CFLAGS)
+# Unity framework sources
+UNITY_SRC = $(top_srcdir)/vendor/unity/src/unity.c
+UNITY_HDR = $(top_srcdir)/vendor/unity/src/unity.h
+
+test_basic_SOURCES = tests/test_basic.c appdata.h $(UNITY_SRC)
+test_basic_CFLAGS = $(EFL_CFLAGS) -I$(top_srcdir)/vendor/unity/src
test_basic_LDADD = $(EFL_LIBS_NO_CON)
\ No newline at end of file
diff --git a/src/tests/test_basic.c b/src/tests/test_basic.c
index aa7fd53..1e4bf4f 100644
--- a/src/tests/test_basic.c
+++ b/src/tests/test_basic.c
@@ -2,22 +2,23 @@
#include <stdlib.h>
#include <string.h>
+// Include Unity testing framework
+#include "unity.h"
+
// Include the core data structures we want to test
#include "../appdata.h"
-// Simple test framework macros
-#define TEST_ASSERT(condition, message) \
- do { \
- if (!(condition)) { \
- printf("FAIL: %s\n", message); \
- return 0; \
- } else { \
- printf("PASS: %s\n", message); \
- } \
- } while(0)
+// setUp and tearDown functions (optional)
+void setUp(void) {
+ // This runs before each test
+}
+
+void tearDown(void) {
+ // This runs after each test
+}
// Test functions
-int test_station_creation() {
+void test_station_creation(void) {
Station station = {0};
station.name = "Test Radio Station";
@@ -25,26 +26,22 @@ int test_station_creation() {
station.bitrate = 128;
station.favorite = EINA_TRUE;
- TEST_ASSERT(station.name != NULL, "Station name should be set");
- TEST_ASSERT(strcmp(station.name, "Test Radio Station") == 0, "Station name should match");
- TEST_ASSERT(station.bitrate == 128, "Station bitrate should be 128");
- TEST_ASSERT(station.favorite == EINA_TRUE, "Station favorite should be true");
-
- return 1;
+ TEST_ASSERT_NOT_NULL(station.name);
+ TEST_ASSERT_EQUAL_STRING("Test Radio Station", station.name);
+ TEST_ASSERT_EQUAL(128, station.bitrate);
+ TEST_ASSERT_EQUAL(EINA_TRUE, station.favorite);
}
-int test_view_mode_enum() {
+void test_view_mode_enum(void) {
ViewMode search_mode = VIEW_SEARCH;
ViewMode favorites_mode = VIEW_FAVORITES;
- TEST_ASSERT(search_mode == 0, "VIEW_SEARCH should be 0");
- TEST_ASSERT(favorites_mode == 1, "VIEW_FAVORITES should be 1");
- TEST_ASSERT(search_mode != favorites_mode, "View modes should be different");
-
- return 1;
+ TEST_ASSERT_EQUAL(0, search_mode);
+ TEST_ASSERT_EQUAL(1, favorites_mode);
+ TEST_ASSERT_NOT_EQUAL(search_mode, favorites_mode);
}
-int test_appdata_structure() {
+void test_appdata_structure(void) {
AppData appdata = {0};
// Initialize some basic fields
@@ -53,15 +50,13 @@ int test_appdata_structure() {
appdata.view_mode = VIEW_SEARCH;
appdata.loading_requests = 5;
- TEST_ASSERT(appdata.playing == EINA_FALSE, "Playing should be false initially");
- TEST_ASSERT(appdata.filters_visible == EINA_TRUE, "Filters visible should be true");
- TEST_ASSERT(appdata.view_mode == VIEW_SEARCH, "View mode should be SEARCH");
- TEST_ASSERT(appdata.loading_requests == 5, "Loading requests should be 5");
-
- return 1;
+ TEST_ASSERT_EQUAL(EINA_FALSE, appdata.playing);
+ TEST_ASSERT_EQUAL(EINA_TRUE, appdata.filters_visible);
+ TEST_ASSERT_EQUAL(VIEW_SEARCH, appdata.view_mode);
+ TEST_ASSERT_EQUAL(5, appdata.loading_requests);
}
-int test_station_string_fields() {
+void test_station_string_fields(void) {
Station station = {0};
station.name = "Jazz FM";
@@ -73,38 +68,22 @@ int test_station_string_fields() {
station.codec = "MP3";
station.tags = "jazz,music";
- TEST_ASSERT(strcmp(station.name, "Jazz FM") == 0, "Station name should be Jazz FM");
- TEST_ASSERT(strcmp(station.url, "http://jazz.fm/stream.mp3") == 0, "Station URL should match");
- TEST_ASSERT(strcmp(station.country, "USA") == 0, "Station country should be USA");
- TEST_ASSERT(strcmp(station.language, "English") == 0, "Station language should be English");
- TEST_ASSERT(strcmp(station.codec, "MP3") == 0, "Station codec should be MP3");
- TEST_ASSERT(strcmp(station.tags, "jazz,music") == 0, "Station tags should match");
-
- return 1;
+ TEST_ASSERT_EQUAL_STRING("Jazz FM", station.name);
+ TEST_ASSERT_EQUAL_STRING("http://jazz.fm/stream.mp3", station.url);
+ TEST_ASSERT_EQUAL_STRING("USA", station.country);
+ TEST_ASSERT_EQUAL_STRING("English", station.language);
+ TEST_ASSERT_EQUAL_STRING("MP3", station.codec);
+ TEST_ASSERT_EQUAL_STRING("jazz,music", station.tags);
}
// Main test runner
-int main() {
- printf("Running eradio basic tests...\n");
- printf("================================\n");
+int main(void) {
+ UNITY_BEGIN();
- int passed = 0;
- int total = 0;
+ RUN_TEST(test_station_creation);
+ RUN_TEST(test_view_mode_enum);
+ RUN_TEST(test_appdata_structure);
+ RUN_TEST(test_station_string_fields);
- // Run tests
- total++; passed += test_station_creation();
- total++; passed += test_view_mode_enum();
- total++; passed += test_appdata_structure();
- total++; passed += test_station_string_fields();
-
- printf("================================\n");
- printf("Test Results: %d/%d tests passed\n", passed, total);
-
- if (passed == total) {
- printf("All tests PASSED!\n");
- return EXIT_SUCCESS;
- } else {
- printf("Some tests FAILED!\n");
- return EXIT_FAILURE;
- }
+ return UNITY_END();
}
\ No newline at end of file
diff --git a/vendor/unity b/vendor/unity
new file mode 160000
index 0000000..36e9b19
--- /dev/null
+++ b/vendor/unity
@@ -0,0 +1 @@
+Subproject commit 36e9b197ec3c36951ec6abf1f57252116e04acc3
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.