| | | 1 | | #include "../../../database/machine_service.h" |
| | | 2 | | #include "../../../database/db_connection.h" |
| | | 3 | | #include <stdio.h> |
| | | 4 | | #include <assert.h> |
| | | 5 | | #include <string.h> |
| | | 6 | | |
| | | 7 | | // Mock test - requires actual DB connection for integration tests |
| | 1 | 8 | | void test_machine_struct_size() { |
| | | 9 | | Machine m; |
| | | 10 | | assert(sizeof(m.name) == 100); |
| | | 11 | | assert(sizeof(m.model) == 50); |
| | | 12 | | assert(sizeof(m.location) == 100); |
| | | 13 | | assert(sizeof(m.status) == 20); |
| | 1 | 14 | | printf("[PASS] Machine struct: correct field sizes\n"); |
| | 1 | 15 | | } |
| | | 16 | | |
| | 1 | 17 | | void test_machine_initialization() { |
| | 1 | 18 | | Machine m = {0}; |
| | 1 | 19 | | m.id = 1; |
| | 1 | 20 | | strcpy(m.name, "Test Machine"); |
| | 1 | 21 | | strcpy(m.status, "operational"); |
| | 1 | 22 | | assert(m.id == 1); |
| | 1 | 23 | | assert(strcmp(m.name, "Test Machine") == 0); |
| | 1 | 24 | | assert(strcmp(m.status, "operational") == 0); |
| | 1 | 25 | | printf("[PASS] Machine initialization: fields set correctly\n"); |
| | 1 | 26 | | } |
| | | 27 | | |
| | 1 | 28 | | void test_machine_name_boundary() { |
| | 1 | 29 | | Machine m = {0}; |
| | | 30 | | char long_name[150]; |
| | 1 | 31 | | memset(long_name, 'A', 149); |
| | 1 | 32 | | long_name[149] = '\0'; |
| | 1 | 33 | | strncpy(m.name, long_name, 99); |
| | 1 | 34 | | m.name[99] = '\0'; |
| | 1 | 35 | | assert(strlen(m.name) == 99); |
| | 1 | 36 | | printf("[PASS] Machine name: boundary check passed\n"); |
| | 1 | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | void test_machine_status_values() { |
| | 1 | 40 | | Machine m1 = {.id = 1}; |
| | 1 | 41 | | strcpy(m1.status, "operational"); |
| | 1 | 42 | | Machine m2 = {.id = 2}; |
| | 1 | 43 | | strcpy(m2.status, "maintenance"); |
| | 1 | 44 | | Machine m3 = {.id = 3}; |
| | 1 | 45 | | strcpy(m3.status, "fault"); |
| | 1 | 46 | | assert(strcmp(m1.status, "operational") == 0); |
| | 1 | 47 | | assert(strcmp(m2.status, "maintenance") == 0); |
| | 1 | 48 | | assert(strcmp(m3.status, "fault") == 0); |
| | 1 | 49 | | printf("[PASS] Machine status: all valid states\n"); |
| | 1 | 50 | | } |
| | | 51 | | |
| | 1 | 52 | | int main() { |
| | 1 | 53 | | printf("=== Machine Service Unit Tests ===\n"); |
| | 1 | 54 | | printf("Note: These are structure tests. Integration tests require DB connection.\n\n"); |
| | 1 | 55 | | test_machine_struct_size(); |
| | 1 | 56 | | test_machine_initialization(); |
| | 1 | 57 | | test_machine_name_boundary(); |
| | 1 | 58 | | test_machine_status_values(); |
| | 1 | 59 | | printf("\n✅ All Machine Service unit tests passed!\n"); |
| | 1 | 60 | | printf("⚠️ Run integration tests with active PostgreSQL connection for full coverage.\n"); |
| | 1 | 61 | | return 0; |
| | | 62 | | } |