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

Information
Class: inventory_handler_c
Assembly: src.backend.api.handlers
File(s): ./src/backend/api/handlers/inventory_handler.c
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 33
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
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% (22/22) Branch coverage: 100% (2/2) Total lines: 33 2/18/2026 - 10:50:55 PM Line coverage: 100% (22/22) Branch coverage: 100% (2/2) Total lines: 33

File(s)

./src/backend/api/handlers/inventory_handler.c

#LineLine coverage
 1#include "inventory_handler.h"
 2#include "../../database/api_handlers.h"
 3#include "../../database/cJSON.h"
 4#include <string.h>
 5#include <stdlib.h>
 6#include <stdio.h>
 7
 18char *serialize_inventory_to_json(void) {
 19  cJSON *root = cJSON_CreateObject();
 110  cJSON *item_array = cJSON_CreateArray();
 111  cJSON *item1 = cJSON_CreateObject();
 112  cJSON_AddNumberToObject(item1, "id", 1);
 113  cJSON_AddStringToObject(item1, "name", "Motor Oil");
 114  cJSON_AddNumberToObject(item1, "quantity", 25);
 115  cJSON_AddItemToArray(item_array, item1);
 116  cJSON_AddItemToObject(root, "inventory", item_array);
 117  char *json = cJSON_Print(root);
 118  cJSON_Delete(root);
 119  return json;
 20}
 21
 222void handle_inventory_request(HttpRequest *req, HttpResponse *res) {
 223  if (strcmp(req->method, "GET") == 0) {
 124    char *json = serialize_inventory_to_json();
 125    res->status_code = 200;
 126    strcpy(res->content_type, "application/json");
 127    strncpy(res->body, json, 8191);
 128    free(json);
 29  } else {
 130    res->status_code = 405; // Method Not Allowed
 131    strcpy(res->body, "{\"error\": \"Method not supported for inventory\"}");
 32  }
 233}

Methods/Properties