< Summary - Backend C Tests - Coverage Report (WSL)

Information
Class: test_maintenance_service_c
Assembly: src.backend.tests.unit.database
File(s): ./src/backend/tests/unit/database/test_maintenance_service.c
Line coverage
100%
Covered lines: 62
Uncovered lines: 0
Coverable lines: 62
Total lines: 87
Line coverage: 100%
Branch coverage
57%
Covered branches: 16
Total branches: 28
Branch coverage: 57.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 2/18/2026 - 10:50:55 PM Line coverage: 100% (62/62) Branch coverage: 57.1% (16/28) Total lines: 87 2/18/2026 - 10:50:55 PM Line coverage: 100% (62/62) Branch coverage: 57.1% (16/28) Total lines: 87

File(s)

./src/backend/tests/unit/database/test_maintenance_service.c

#LineLine coverage
 1#include "../../../database/maintenance_service.h"
 2#include <stdio.h>
 3#include <assert.h>
 4#include <string.h>
 5
 16void 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);
 111  printf("[PASS] MaintenanceLog struct: correct sizes\n");
 112}
 13
 114void test_maintenance_log_initialization() {
 115  MaintenanceLog log = {0};
 116  log.id = 1;
 117  log.machine_id = 5;
 118  strcpy(log.technician_name, "Ahmet Yilmaz");
 119  strcpy(log.log_date, "2026-02-09");
 120  strcpy(log.description, "Preventive maintenance completed");
 121  log.cost = 150.50;
 122  assert(log.id == 1);
 123  assert(log.machine_id == 5);
 124  assert(strcmp(log.technician_name, "Ahmet Yilmaz") == 0);
 125  assert(log.cost == 150.50);
 126  printf("[PASS] MaintenanceLog: initialization\n");
 127}
 28
 129void test_maintenance_cost_validation() {
 130  MaintenanceLog log1 = {.cost = 0.0};
 131  MaintenanceLog log2 = {.cost = -10.0};
 132  MaintenanceLog log3 = {.cost = 1000.0};
 133  assert(log1.cost >= 0);
 134  assert(log2.cost < 0); // Should be rejected by service
 135  assert(log3.cost > 0);
 136  printf("[PASS] Maintenance: cost validation\n");
 137}
 38
 139void test_maintenance_description_length() {
 140  MaintenanceLog log = {0};
 41  char long_desc[600];
 142  memset(long_desc, 'X', 599);
 143  long_desc[599] = '\0';
 144  strncpy(log.description, long_desc, 511);
 145  log.description[511] = '\0';
 146  assert(strlen(log.description) == 511);
 147  printf("[PASS] Maintenance: description boundary\n");
 148}
 49
 150void test_maintenance_date_format() {
 151  MaintenanceLog log = {0};
 152  strcpy(log.log_date, "2026-02-09");
 153  assert(strlen(log.log_date) == 10);
 154  assert(log.log_date[4] == '-');
 155  assert(log.log_date[7] == '-');
 156  printf("[PASS] Maintenance: date format\n");
 157}
 58
 159void test_maintenance_technician_assignment() {
 160  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  };
 165  int tech_a_count = 0;
 66
 467  for (int i = 0; i < 3; i++) {
 368    if (strcmp(logs[i].technician_name, "Tech A") == 0) {
 269      tech_a_count++;
 70    }
 71  }
 72
 173  assert(tech_a_count == 2);
 174  printf("[PASS] Maintenance: technician assignment tracking\n");
 175}
 76
 177int main() {
 178  printf("=== Maintenance Service Unit Tests ===\n");
 179  test_maintenance_log_struct();
 180  test_maintenance_log_initialization();
 181  test_maintenance_cost_validation();
 182  test_maintenance_description_length();
 183  test_maintenance_date_format();
 184  test_maintenance_technician_assignment();
 185  printf("\n✅ All Maintenance Service unit tests passed!\n");
 186  return 0;
 87}

Methods/Properties