|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Embeint Inc |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +#include <zephyr/zbus/zbus.h> |
| 7 | +#include <zephyr/ztest.h> |
| 8 | +#include <zephyr/ztest_assert.h> |
| 9 | + |
| 10 | +struct msg { |
| 11 | + int x; |
| 12 | +}; |
| 13 | + |
| 14 | +ZBUS_CHAN_DEFINE(chan_a, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 15 | +ZBUS_CHAN_DEFINE(chan_b, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 16 | +ZBUS_CHAN_DEFINE(chan_c, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 17 | +ZBUS_CHAN_DEFINE(chan_d, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 18 | +ZBUS_CHAN_DEFINE(chan_e, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 19 | +ZBUS_CHAN_DEFINE(chan_f, struct msg, NULL, NULL, ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0)); |
| 20 | + |
| 21 | +ZTEST(channel_name, test_channel_retrieval) |
| 22 | +{ |
| 23 | + /* Invalid/unknown channel names */ |
| 24 | + zassert_is_null(zbus_chan_from_name("unknown")); |
| 25 | + zassert_is_null(zbus_chan_from_name("")); |
| 26 | + |
| 27 | + /* Standard retrieval */ |
| 28 | + zassert_equal(&chan_a, zbus_chan_from_name("chan_a")); |
| 29 | + zassert_equal(&chan_b, zbus_chan_from_name("chan_b")); |
| 30 | + zassert_equal(&chan_c, zbus_chan_from_name("chan_c")); |
| 31 | + |
| 32 | + /* Ensure no cross-talk between names */ |
| 33 | + zassert_not_equal(&chan_d, zbus_chan_from_name("chan_e")); |
| 34 | + zassert_not_equal(&chan_e, zbus_chan_from_name("chan_f")); |
| 35 | + zassert_not_equal(&chan_f, zbus_chan_from_name("chan_d")); |
| 36 | +} |
| 37 | + |
| 38 | +ZTEST_SUITE(channel_name, NULL, NULL, NULL, NULL, NULL); |
0 commit comments