|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/* |
| 8 | + * Minimal fakes required to link nrf_cloud_coap_codec.c in the test |
| 9 | + * environment. |
| 10 | + * |
| 11 | + * nrf_cloud_coap_codec.c references several symbols from |
| 12 | + * nrf_cloud_codec_internal.c and nrf_cloud_mem.c. Including those full |
| 13 | + * implementations would drag in the modem, FOTA, and REST |
| 14 | + * subsystems that are irrelevant for pure CBOR codec unit tests. |
| 15 | + * |
| 16 | + * Only three of those symbols are reachable in the CBOR path that is |
| 17 | + * exercised by these tests: |
| 18 | + * - nrf_cloud_agnss_type_array_get (called in coap_codec_agnss_encode) |
| 19 | + * - nrf_cloud_calloc / nrf_cloud_free / nrf_cloud_malloc (link-time deps) |
| 20 | + * |
| 21 | + * The remaining symbols (nrf_cloud_encode_message, nrf_cloud_error_msg_decode, |
| 22 | + * nrf_cloud_rest_fota_execution_decode) are only reachable via JSON paths that |
| 23 | + * the CBOR tests do not exercise; they are stubbed out with safe no-op or |
| 24 | + * error-returning implementations so that the linker is satisfied. |
| 25 | + * |
| 26 | + * NOTE: This file is intentionally a copy of (and closely mirrors) the fakes |
| 27 | + * in codec/json/src/fakes.c. A future refactor can hoist the shared fakes |
| 28 | + * into a common location; that is deferred until the full codec test suite |
| 29 | + * shape is known. |
| 30 | + */ |
| 31 | + |
| 32 | +#include <stdbool.h> |
| 33 | +#include <stdlib.h> |
| 34 | +#include <errno.h> |
| 35 | +#include <net/nrf_cloud.h> |
| 36 | +#include <nrf_modem_gnss.h> |
| 37 | +#include <nrf_cloud_codec_internal.h> |
| 38 | +#include <nrf_cloud_mem.h> |
| 39 | + |
| 40 | +/* ------------------------------------------------------------------------- |
| 41 | + * Memory wrappers (mirrors of nrf_cloud_mem.c) |
| 42 | + * ------------------------------------------------------------------------- |
| 43 | + */ |
| 44 | + |
| 45 | +void *nrf_cloud_calloc(size_t count, size_t size) |
| 46 | +{ |
| 47 | + return calloc(count, size); |
| 48 | +} |
| 49 | + |
| 50 | +void *nrf_cloud_malloc(size_t size) |
| 51 | +{ |
| 52 | + return malloc(size); |
| 53 | +} |
| 54 | + |
| 55 | +void nrf_cloud_free(void *ptr) |
| 56 | +{ |
| 57 | + free(ptr); |
| 58 | +} |
| 59 | + |
| 60 | +/* ------------------------------------------------------------------------- |
| 61 | + * JSON-path stubs — never called from the CBOR test path. |
| 62 | + * Returning an error code prevents silent mis-routing if they are ever |
| 63 | + * reached unexpectedly. |
| 64 | + * ------------------------------------------------------------------------- |
| 65 | + */ |
| 66 | + |
| 67 | +int nrf_cloud_encode_message(const char *app_id, double value, const char *str_val, |
| 68 | + const char *topic, int64_t ts, struct nrf_cloud_data *output) |
| 69 | +{ |
| 70 | + ARG_UNUSED(app_id); |
| 71 | + ARG_UNUSED(value); |
| 72 | + ARG_UNUSED(str_val); |
| 73 | + ARG_UNUSED(topic); |
| 74 | + ARG_UNUSED(ts); |
| 75 | + ARG_UNUSED(output); |
| 76 | + return -ENOTSUP; |
| 77 | +} |
| 78 | + |
| 79 | +int nrf_cloud_error_msg_decode(const char *const buf, const char *const app_id, |
| 80 | + const char *const msg_type, enum nrf_cloud_error *const err) |
| 81 | +{ |
| 82 | + ARG_UNUSED(buf); |
| 83 | + ARG_UNUSED(app_id); |
| 84 | + ARG_UNUSED(msg_type); |
| 85 | + ARG_UNUSED(err); |
| 86 | + /* Return non-zero: signals "no JSON error message found", which causes |
| 87 | + * the callers (ground_fix / agnss / pgps decode) to return -EPROTO. |
| 88 | + */ |
| 89 | + return -ENOENT; |
| 90 | +} |
| 91 | + |
| 92 | +int nrf_cloud_rest_fota_execution_decode(const char *const response, |
| 93 | + struct nrf_cloud_fota_job_info *const job) |
| 94 | +{ |
| 95 | + ARG_UNUSED(response); |
| 96 | + ARG_UNUSED(job); |
| 97 | + return -ENOTSUP; |
| 98 | +} |
| 99 | + |
| 100 | +/* ------------------------------------------------------------------------- |
| 101 | + * nrf_cloud_agnss_type_array_get — called in the CBOR path of |
| 102 | + * coap_codec_agnss_encode when type == NRF_CLOUD_REST_AGNSS_REQ_CUSTOM. |
| 103 | + * |
| 104 | + * The real implementation parses an nrf_modem_gnss_agnss_data_frame bitmask |
| 105 | + * and fills in an array of nrf_cloud_agnss_type values. For unit testing |
| 106 | + * purposes a fixed two-element response is sufficient; it keeps the test |
| 107 | + * hermetic and produces a deterministic, non-empty CBOR output. |
| 108 | + * ------------------------------------------------------------------------- |
| 109 | + */ |
| 110 | + |
| 111 | +int nrf_cloud_agnss_type_array_get(const struct nrf_modem_gnss_agnss_data_frame *const request, |
| 112 | + enum nrf_cloud_agnss_type *array, const size_t array_size) |
| 113 | +{ |
| 114 | + ARG_UNUSED(request); |
| 115 | + |
| 116 | + if (!array || array_size < 2) { |
| 117 | + return -EINVAL; |
| 118 | + } |
| 119 | + |
| 120 | + array[0] = NRF_CLOUD_AGNSS_GPS_UTC_PARAMETERS; |
| 121 | + array[1] = NRF_CLOUD_AGNSS_GPS_EPHEMERIDES; |
| 122 | + |
| 123 | + return 2; |
| 124 | +} |
0 commit comments