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

Information
Class: test_inventory_service_c
Assembly: src.backend.tests.unit.database
File(s): ./src/backend/tests/unit/database/test_inventory_service.c
Line coverage
100%
Covered lines: 56
Uncovered lines: 0
Coverable lines: 56
Total lines: 73
Line coverage: 100%
Branch coverage
50%
Covered branches: 12
Total branches: 24
Branch coverage: 50%
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% (56/56) Branch coverage: 50% (12/24) Total lines: 73 2/18/2026 - 10:50:55 PM Line coverage: 100% (56/56) Branch coverage: 50% (12/24) Total lines: 73

File(s)

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

#LineLine coverage
 1#include "../../../database/inventory_service.h"
 2#include <stdio.h>
 3#include <assert.h>
 4#include <string.h>
 5
 16void test_inventory_struct_size() {
 7  InventoryItem item;
 8  assert(sizeof(item.part_name) == 100);
 9  assert(sizeof(item.sku) == 50);
 10  assert(sizeof(item.last_restocked_at) == 32);
 111  printf("[PASS] InventoryItem struct: correct field sizes\n");
 112}
 13
 114void test_inventory_initialization() {
 115  InventoryItem item = {0};
 116  item.id = 1;
 117  strcpy(item.part_name, "Bearing 608");
 118  strcpy(item.sku, "BRG-608-2RS");
 119  item.quantity = 50;
 120  item.min_stock_level = 10;
 121  item.unit_cost = 2.50;
 122  assert(item.id == 1);
 123  assert(strcmp(item.part_name, "Bearing 608") == 0);
 124  assert(strcmp(item.sku, "BRG-608-2RS") == 0);
 125  assert(item.quantity == 50);
 126  assert(item.min_stock_level == 10);
 127  assert(item.unit_cost == 2.50);
 128  printf("[PASS] InventoryItem initialization: all fields correct\n");
 129}
 30
 131void test_inventory_low_stock_detection() {
 132  InventoryItem item1 = {.quantity = 5, .min_stock_level = 10};
 133  InventoryItem item2 = {.quantity = 15, .min_stock_level = 10};
 134  assert(item1.quantity < item1.min_stock_level);
 135  assert(item2.quantity >= item2.min_stock_level);
 136  printf("[PASS] Inventory: low stock detection logic\n");
 137}
 38
 139void test_inventory_cost_calculation() {
 140  InventoryItem item = {.quantity = 100, .unit_cost = 5.75};
 141  double total_value = item.quantity *item.unit_cost;
 142  assert(total_value == 575.0);
 143  printf("[PASS] Inventory: cost calculation\n");
 144}
 45
 146void test_inventory_sku_format() {
 147  InventoryItem item = {0};
 148  strcpy(item.sku, "PART-2024-001");
 149  assert(strlen(item.sku) > 0);
 150  assert(strstr(item.sku, "PART") != NULL);
 151  printf("[PASS] Inventory: SKU format validation\n");
 152}
 53
 154void test_inventory_negative_quantity_guard() {
 155  InventoryItem item = {.quantity = 10};
 156  int change = -15;
 57  // Simulating update logic
 158  int new_quantity = item.quantity + change;
 159  assert(new_quantity < 0); // Should be caught by service layer
 160  printf("[PASS] Inventory: negative quantity detection\n");
 161}
 62
 163int main() {
 164  printf("=== Inventory Service Unit Tests ===\n");
 165  test_inventory_struct_size();
 166  test_inventory_initialization();
 167  test_inventory_low_stock_detection();
 168  test_inventory_cost_calculation();
 169  test_inventory_sku_format();
 170  test_inventory_negative_quantity_guard();
 171  printf("\n✅ All Inventory Service unit tests passed!\n");
 172  return 0;
 73}

Methods/Properties