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}
0 commit comments