/** * * \section COPYRIGHT * * Copyright 2013-2020 Software Radio Systems Limited * * By using this file, you agree to the terms and conditions set * forth in the LICENSE file which can be found at the top level of * the distribution. * */ #include "srslte/srslog/context.h" #include "testing_helpers.h" #include using namespace srslog; namespace { DECLARE_METRIC("SNR", snr_t, float, "dB"); DECLARE_METRIC("PWR", pwr_t, int, "dBm"); DECLARE_METRIC("CenterFreq", cfreq_t, unsigned, "MHz"); DECLARE_METRIC_SET("RF", myset1, snr_t, pwr_t, cfreq_t); DECLARE_METRIC("Throughput", thr_t, float, "MB/s"); DECLARE_METRIC("Address", ip_addr_t, std::string, ""); DECLARE_METRIC_SET("Network", myset2, thr_t, ip_addr_t); using ctx_t = srslog::build_context_type; } // namespace /// Builds a context for testing. static ctx_t build_context() { ctx_t ctx("Ctx"); return ctx; } static bool when_context_is_built_then_context_name_is_valid() { ctx_t ctx = build_context(); ASSERT_EQ(ctx.name(), "Ctx"); return true; } static bool when_context_is_built_then_metric_sets_names_are_valid() { ctx_t ctx = build_context(); ASSERT_EQ(ctx.get().name(), std::string("RF")); ASSERT_EQ(ctx.get().name(), std::string("Network")); return true; } static bool when_context_is_built_then_metric_names_are_valid() { ctx_t ctx = build_context(); ASSERT_EQ(ctx.get().get().name(), std::string("SNR")); ASSERT_EQ(ctx.get().get().name(), std::string("PWR")); return true; } static bool when_context_is_built_then_metric_units_are_valid() { ctx_t ctx = build_context(); ASSERT_EQ(ctx.get().get().units(), std::string("dB")); ASSERT_EQ(ctx.get().get().units(), std::string("dBm")); return true; } static bool when_metric_is_set_through_context_then_value_is_stored() { ctx_t ctx = build_context(); float value = 10; ctx.get().write(value); ASSERT_EQ(ctx.get().read(), value); return true; } namespace { DECLARE_METRIC("metric1", m1_t, float, ""); DECLARE_METRIC_SET("test_set_t", test_set_t, m1_t); DECLARE_METRIC_LIST("vector", vector_metrics, std::vector); using ctx2_t = srslog::build_context_type; } // namespace static bool when_context_with_list_is_set_value_is_retrieved_correctly() { ctx2_t ctx("test"); float val = 2; ctx.get().emplace_back(); ctx.at(0).write(val); ASSERT_EQ(ctx.at(0).read(), val); return true; } int main() { TEST_FUNCTION(when_context_is_built_then_context_name_is_valid); TEST_FUNCTION(when_context_is_built_then_metric_sets_names_are_valid); TEST_FUNCTION(when_context_is_built_then_metric_names_are_valid); TEST_FUNCTION(when_context_is_built_then_metric_units_are_valid); TEST_FUNCTION(when_metric_is_set_through_context_then_value_is_stored); TEST_FUNCTION(when_context_with_list_is_set_value_is_retrieved_correctly); return 0; }