| | | 1 | | #include "../../../database/maintenance_service.h" |
| | | 2 | | #include <stdio.h> |
| | | 3 | | #include <assert.h> |
| | | 4 | | #include <string.h> |
| | | 5 | | |
| | 1 | 6 | | void test_maintenance_log_struct() { |
| | | 7 | | MaintenanceLog log; |
| | | 8 | | assert(sizeof(log.technician_name) == 100); |
| | | 9 | | assert(sizeof(log.log_date) == 32); |
| | | 10 | | assert(sizeof(log.description) == 512); |
| | 1 | 11 | | printf("[PASS] MaintenanceLog struct: correct sizes\n"); |
| | 1 | 12 | | } |
| | | 13 | | |
| | 1 | 14 | | void test_maintenance_log_initialization() { |
| | 1 | 15 | | MaintenanceLog log = {0}; |
| | 1 | 16 | | log.id = 1; |
| | 1 | 17 | | log.machine_id = 5; |
| | 1 | 18 | | strcpy(log.technician_name, "Ahmet Yilmaz"); |
| | 1 | 19 | | strcpy(log.log_date, "2026-02-09"); |
| | 1 | 20 | | strcpy(log.description, "Preventive maintenance completed"); |
| | 1 | 21 | | log.cost = 150.50; |
| | 1 | 22 | | assert(log.id == 1); |
| | 1 | 23 | | assert(log.machine_id == 5); |
| | 1 | 24 | | assert(strcmp(log.technician_name, "Ahmet Yilmaz") == 0); |
| | 1 | 25 | | assert(log.cost == 150.50); |
| | 1 | 26 | | printf("[PASS] MaintenanceLog: initialization\n"); |
| | 1 | 27 | | } |
| | | 28 | | |
| | 1 | 29 | | void test_maintenance_cost_validation() { |
| | 1 | 30 | | MaintenanceLog log1 = {.cost = 0.0}; |
| | 1 | 31 | | MaintenanceLog log2 = {.cost = -10.0}; |
| | 1 | 32 | | MaintenanceLog log3 = {.cost = 1000.0}; |
| | 1 | 33 | | assert(log1.cost >= 0); |
| | 1 | 34 | | assert(log2.cost < 0); // Should be rejected by service |
| | 1 | 35 | | assert(log3.cost > 0); |
| | 1 | 36 | | printf("[PASS] Maintenance: cost validation\n"); |
| | 1 | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | void test_maintenance_description_length() { |
| | 1 | 40 | | MaintenanceLog log = {0}; |
| | | 41 | | char long_desc[600]; |
| | 1 | 42 | | memset(long_desc, 'X', 599); |
| | 1 | 43 | | long_desc[599] = '\0'; |
| | 1 | 44 | | strncpy(log.description, long_desc, 511); |
| | 1 | 45 | | log.description[511] = '\0'; |
| | 1 | 46 | | assert(strlen(log.description) == 511); |
| | 1 | 47 | | printf("[PASS] Maintenance: description boundary\n"); |
| | 1 | 48 | | } |
| | | 49 | | |
| | 1 | 50 | | void test_maintenance_date_format() { |
| | 1 | 51 | | MaintenanceLog log = {0}; |
| | 1 | 52 | | strcpy(log.log_date, "2026-02-09"); |
| | 1 | 53 | | assert(strlen(log.log_date) == 10); |
| | 1 | 54 | | assert(log.log_date[4] == '-'); |
| | 1 | 55 | | assert(log.log_date[7] == '-'); |
| | 1 | 56 | | printf("[PASS] Maintenance: date format\n"); |
| | 1 | 57 | | } |
| | | 58 | | |
| | 1 | 59 | | void test_maintenance_technician_assignment() { |
| | 1 | 60 | | MaintenanceLog logs[3] = { |
| | | 61 | | {.id = 1, .technician_name = "Tech A"}, |
| | | 62 | | {.id = 2, .technician_name = "Tech B"}, |
| | | 63 | | {.id = 3, .technician_name = "Tech A"} |
| | | 64 | | }; |
| | 1 | 65 | | int tech_a_count = 0; |
| | | 66 | | |
| | 4 | 67 | | for (int i = 0; i < 3; i++) { |
| | 3 | 68 | | if (strcmp(logs[i].technician_name, "Tech A") == 0) { |
| | 2 | 69 | | tech_a_count++; |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | |
| | 1 | 73 | | assert(tech_a_count == 2); |
| | 1 | 74 | | printf("[PASS] Maintenance: technician assignment tracking\n"); |
| | 1 | 75 | | } |
| | | 76 | | |
| | 1 | 77 | | int main() { |
| | 1 | 78 | | printf("=== Maintenance Service Unit Tests ===\n"); |
| | 1 | 79 | | test_maintenance_log_struct(); |
| | 1 | 80 | | test_maintenance_log_initialization(); |
| | 1 | 81 | | test_maintenance_cost_validation(); |
| | 1 | 82 | | test_maintenance_description_length(); |
| | 1 | 83 | | test_maintenance_date_format(); |
| | 1 | 84 | | test_maintenance_technician_assignment(); |
| | 1 | 85 | | printf("\n✅ All Maintenance Service unit tests passed!\n"); |
| | 1 | 86 | | return 0; |
| | | 87 | | } |