|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/* |
| 8 | + * Stub for nrf_cloud_coap.h. |
| 9 | + * |
| 10 | + * Compilation requirement: full type definitions are pulled in through the |
| 11 | + * normal include chain (lte_lc.h, wifi_location_common.h, nrf_cloud_location.h) |
| 12 | + * exactly as in production code. |
| 13 | + * |
| 14 | + * CMock requirement: CMock's Ruby parser runs with WORKING_DIRECTORY set to |
| 15 | + * the project source root and therefore cannot resolve the relative include |
| 16 | + * paths. The parser skips includes it cannot find and parses only the |
| 17 | + * function declarations that appear directly in this file — which is |
| 18 | + * sufficient to generate correct mock stubs. |
| 19 | + */ |
| 20 | + |
| 21 | +#ifndef NRF_CLOUD_COAP_TEST_STUB_H_ |
| 22 | +#define NRF_CLOUD_COAP_TEST_STUB_H_ |
| 23 | + |
| 24 | +#include <stddef.h> |
| 25 | +#include <stdint.h> |
| 26 | +#include <stdbool.h> |
| 27 | +#include <limits.h> |
| 28 | + |
| 29 | +/* |
| 30 | + * Pull in the full type definitions that sm_at_nrfcloud.c needs when it |
| 31 | + * accesses struct members (wifi_scan_info, lte_lc_cells_info, etc.). |
| 32 | + * CMock's Ruby parser will skip these includes if it cannot find them; the |
| 33 | + * function signatures below are enough for mock generation. |
| 34 | + */ |
| 35 | +#include <modem/lte_lc.h> |
| 36 | +#include "net/wifi_location_common.h" |
| 37 | +#include "net/nrf_cloud_location.h" |
| 38 | + |
| 39 | +/* ------------------------------------------------------------------------- |
| 40 | + * CoAP content-format constant. |
| 41 | + * In production code this comes from <zephyr/net/coap.h> when |
| 42 | + * CONFIG_NRF_CLOUD_COAP is set. Without that Kconfig the real header |
| 43 | + * defines a stub enum without the actual values, so we define it here. |
| 44 | + * ---------------------------------------------------------------------- */ |
| 45 | +#ifndef COAP_CONTENT_FORMAT_APP_JSON |
| 46 | +#define COAP_CONTENT_FORMAT_APP_JSON 50 |
| 47 | +#endif |
| 48 | + |
| 49 | +/* ------------------------------------------------------------------------- |
| 50 | + * CoAP response callback – matches the real coap_client_response_cb_t. |
| 51 | + * ---------------------------------------------------------------------- */ |
| 52 | +#ifndef COAP_CLIENT_RESPONSE_CB_T_DEFINED |
| 53 | +#define COAP_CLIENT_RESPONSE_CB_T_DEFINED |
| 54 | +typedef void (*coap_client_response_cb_t)(int16_t result_code, size_t offset, |
| 55 | + const uint8_t *payload, size_t len, |
| 56 | + bool last_block, void *user_data); |
| 57 | +#endif |
| 58 | + |
| 59 | +/* ------------------------------------------------------------------------- |
| 60 | + * Wi-Fi and location constants (also defined in the sub-stubs; guards |
| 61 | + * prevent redefinition when this header is included first). |
| 62 | + * ---------------------------------------------------------------------- */ |
| 63 | +#ifndef NRF_CLOUD_LOCATION_WIFI_AP_CNT_MIN |
| 64 | +#define NRF_CLOUD_LOCATION_WIFI_AP_CNT_MIN 2 |
| 65 | +#endif |
| 66 | +#ifndef NRF_CLOUD_LOCATION_WIFI_OMIT_RSSI |
| 67 | +#define NRF_CLOUD_LOCATION_WIFI_OMIT_RSSI (INT8_MAX) |
| 68 | +#endif |
| 69 | + |
| 70 | +/* ------------------------------------------------------------------------- |
| 71 | + * nRF Cloud CoAP location request – matches struct nrf_cloud_coap_location_request |
| 72 | + * in the real nrf_cloud_coap.h. |
| 73 | + * ---------------------------------------------------------------------- */ |
| 74 | +#ifndef NRF_CLOUD_COAP_LOCATION_REQUEST_DEFINED |
| 75 | +#define NRF_CLOUD_COAP_LOCATION_REQUEST_DEFINED |
| 76 | +/* Forward declaration; the test always passes config = NULL. */ |
| 77 | +struct nrf_cloud_location_config; |
| 78 | + |
| 79 | +struct nrf_cloud_coap_location_request { |
| 80 | + struct lte_lc_cells_info *cell_info; |
| 81 | + struct wifi_scan_info *wifi_info; |
| 82 | + const struct nrf_cloud_location_config *config; |
| 83 | +}; |
| 84 | +#endif /* NRF_CLOUD_COAP_LOCATION_REQUEST_DEFINED */ |
| 85 | + |
| 86 | +/* ------------------------------------------------------------------------- |
| 87 | + * nRF Cloud CoAP API – mocked by CMock |
| 88 | + * ---------------------------------------------------------------------- */ |
| 89 | +int nrf_cloud_coap_init(void); |
| 90 | +int nrf_cloud_coap_connect(const char *const app_ver); |
| 91 | +int nrf_cloud_coap_disconnect(void); |
| 92 | +int nrf_cloud_coap_location_get(struct nrf_cloud_coap_location_request const *const request, |
| 93 | + struct nrf_cloud_location_result *const result); |
| 94 | +int nrf_cloud_coap_post(const char *resource, const char *query, |
| 95 | + const uint8_t *buf, size_t len, |
| 96 | + int fmt, bool reliable, |
| 97 | + coap_client_response_cb_t cb, void *user); |
| 98 | + |
| 99 | +#endif /* NRF_CLOUD_COAP_TEST_STUB_H_ */ |
0 commit comments