3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp File Reference

Native unit tests for load_map.h and remote_loads_core.h. More...

#include <unity.h>
#include "load_map.h"
#include "remote_loads_core.h"
#include "utils_override.h"
Include dependency graph for test_main.cpp:

Go to the source code of this file.

Classes

struct  RecordingRadio
 Stands in for RFM69::send(): records who would have been sent what. More...
 

Functions

template<const auto & Map, uint8_t NumUnits, uint8_t NumLoads>
static void cycle (RemoteLoadCore< NumUnits > &core, const LoadStates(&states)[NumLoads])
 Run one mains cycle: feed the states to the core, for the given map.
 
template<uint8_t NumUnits>
static int drain (RemoteLoadCore< NumUnits > &core, uint8_t unitIdx)
 Claim a unit's payload if a transmission is due, else return -1.
 
int main (int, char **)
 
template<uint8_t NumLoads>
static void setStates (LoadStates(&states)[NumLoads], uint8_t pattern)
 Build a LoadStates array from a bit pattern, bit i = load i.
 
void setUp (void)
 
void tearDown (void)
 
void test_a_change_on_one_unit_does_not_flag_the_other (void)
 
void test_a_change_restarts_the_refresh_counter (void)
 
void test_a_unit_beyond_the_core_is_ignored (void)
 
void test_all_off_still_refreshes (void)
 
void test_bitOf_counts_within_the_same_unit (void)
 
void test_census_is_constexpr (void)
 
void test_census_of_an_all_local_map (void)
 
void test_change_flags_a_transmission (void)
 
void test_draining_clears_the_flag (void)
 
void test_eight_loads_on_one_unit (void)
 
void test_first_load_of_a_unit_is_bit_zero (void)
 
void test_index_alignment_with_a_leading_local_load (void)
 
void test_interleaved_map (void)
 
void test_isValidMap_accepts_a_mixed_map (void)
 
void test_isValidMap_checks_a_remote_status_led (void)
 
void test_isValidMap_rejects_the_unused_pin_sentinel (void)
 
void test_isValidMap_rejects_unusable_local_pins (void)
 
void test_load_masks_of_a_mixed_map (void)
 
void test_load_masks_of_an_all_local_map (void)
 
void test_local_keeps_unit_zero (void)
 
void test_local_loads_are_ignored (void)
 
void test_masks_feed_the_override_config (void)
 
void test_no_unit_configured_is_a_no_op (void)
 
void test_node_ids_accepts_distinct_ids (void)
 
void test_node_ids_rejects_a_duplicate (void)
 
void test_node_ids_rejects_a_short_table (void)
 
void test_node_ids_rejects_out_of_range (void)
 
void test_node_ids_rejects_the_router_id (void)
 
void test_out_of_range_accessors_are_safe (void)
 
void test_overrideMasks_give_no_bit_to_an_out_of_range_entry (void)
 
void test_overrideMasks_match_the_shift_they_replace (void)
 
void test_overridePinOf_local_is_the_physical_pin (void)
 
void test_overridePinOf_remote_is_a_virtual_pin (void)
 
void test_payload_tracks_the_latest_state_even_if_unsent (void)
 
void test_refresh_counter_restarts_after_a_refresh (void)
 
void test_refresh_fires_on_the_fifth_unchanged_cycle (void)
 
void test_remote_encodes_the_unit_number (void)
 
void test_remote_led_pin_round_trips (void)
 
void test_remote_unit_out_of_range_is_flagged (void)
 
void test_remote_without_led_has_pin_zero (void)
 
void test_remoteOrdinal_counts_remote_entries_only (void)
 
void test_reset_clears_every_unit (void)
 
void test_sendPending_addresses_each_unit_by_its_node_id (void)
 
void test_sendPending_drains_what_it_sends (void)
 
void test_sendPending_only_addresses_the_unit_that_changed (void)
 
void test_sendPending_refreshes_every_unit (void)
 
void test_sendPending_without_units_never_sends (void)
 
void test_single_unit_payload (void)
 
void test_three_units_one_load_each (void)
 
void test_two_units_are_independent (void)
 
void test_unchanged_state_does_not_flag (void)
 

Variables

static constexpr uint8_t sendIds [] { 15, 16, 17 }
 
static constexpr uint8_t sendMap [] { Load::local(5), Load::remote(1), Load::remote(2), Load::remote(1) }
 

Detailed Description

Native unit tests for load_map.h and remote_loads_core.h.

Tests the packed load-map encoding, the per-unit bitmask builder, the override pins derived from the map, the config checks and the send loop. No config.h, no Arduino, no stubs - just the real headers.

Definition in file test_main.cpp.

Function Documentation

◆ cycle()

template<const auto & Map, uint8_t NumUnits, uint8_t NumLoads>
static void cycle ( RemoteLoadCore< NumUnits > & core,
const LoadStates(&) states[NumLoads] )
static

Run one mains cycle: feed the states to the core, for the given map.

Definition at line 26 of file test_main.cpp.

Here is the caller graph for this function:

◆ drain()

template<uint8_t NumUnits>
static int drain ( RemoteLoadCore< NumUnits > & core,
uint8_t unitIdx )
static

Claim a unit's payload if a transmission is due, else return -1.

Definition at line 33 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int ,
char **  )

Definition at line 775 of file test_main.cpp.

Here is the call graph for this function:

◆ setStates()

template<uint8_t NumLoads>
static void setStates ( LoadStates(&) states[NumLoads],
uint8_t pattern )
static

Build a LoadStates array from a bit pattern, bit i = load i.

Definition at line 41 of file test_main.cpp.

Here is the caller graph for this function:

◆ setUp()

void setUp ( void )

Definition at line 17 of file test_main.cpp.

◆ tearDown()

void tearDown ( void )

Definition at line 18 of file test_main.cpp.

◆ test_a_change_on_one_unit_does_not_flag_the_other()

void test_a_change_on_one_unit_does_not_flag_the_other ( void )

Definition at line 342 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_a_change_restarts_the_refresh_counter()

void test_a_change_restarts_the_refresh_counter ( void )

Definition at line 402 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_a_unit_beyond_the_core_is_ignored()

void test_a_unit_beyond_the_core_is_ignored ( void )

Definition at line 476 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_all_off_still_refreshes()

void test_all_off_still_refreshes ( void )

Definition at line 431 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_bitOf_counts_within_the_same_unit()

void test_bitOf_counts_within_the_same_unit ( void )

Definition at line 154 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_census_is_constexpr()

void test_census_is_constexpr ( void )

Definition at line 86 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_census_of_an_all_local_map()

void test_census_of_an_all_local_map ( void )

Definition at line 99 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_change_flags_a_transmission()

void test_change_flags_a_transmission ( void )

Definition at line 287 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_draining_clears_the_flag()

void test_draining_clears_the_flag ( void )

Definition at line 299 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_eight_loads_on_one_unit()

void test_eight_loads_on_one_unit ( void )

Definition at line 254 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_first_load_of_a_unit_is_bit_zero()

void test_first_load_of_a_unit_is_bit_zero ( void )

Definition at line 239 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_index_alignment_with_a_leading_local_load()

void test_index_alignment_with_a_leading_local_load ( void )

Definition at line 270 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_interleaved_map()

void test_interleaved_map ( void )

Definition at line 220 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_isValidMap_accepts_a_mixed_map()

void test_isValidMap_accepts_a_mixed_map ( void )

Definition at line 562 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_isValidMap_checks_a_remote_status_led()

void test_isValidMap_checks_a_remote_status_led ( void )

Definition at line 590 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_isValidMap_rejects_the_unused_pin_sentinel()

void test_isValidMap_rejects_the_unused_pin_sentinel ( void )

Definition at line 581 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_isValidMap_rejects_unusable_local_pins()

void test_isValidMap_rejects_unusable_local_pins ( void )

Definition at line 570 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_load_masks_of_a_mixed_map()

void test_load_masks_of_a_mixed_map ( void )

Definition at line 523 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_load_masks_of_an_all_local_map()

void test_load_masks_of_an_all_local_map ( void )

Definition at line 531 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_local_keeps_unit_zero()

void test_local_keeps_unit_zero ( void )

Definition at line 53 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_local_loads_are_ignored()

void test_local_loads_are_ignored ( void )

Definition at line 181 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_masks_feed_the_override_config()

void test_masks_feed_the_override_config ( void )

Definition at line 539 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_no_unit_configured_is_a_no_op()

void test_no_unit_configured_is_a_no_op ( void )

Definition at line 446 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_node_ids_accepts_distinct_ids()

void test_node_ids_accepts_distinct_ids ( void )

Definition at line 625 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_node_ids_rejects_a_duplicate()

void test_node_ids_rejects_a_duplicate ( void )

Definition at line 634 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_node_ids_rejects_a_short_table()

void test_node_ids_rejects_a_short_table ( void )

Definition at line 660 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_node_ids_rejects_out_of_range()

void test_node_ids_rejects_out_of_range ( void )

Definition at line 649 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_node_ids_rejects_the_router_id()

void test_node_ids_rejects_the_router_id ( void )

Definition at line 642 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_out_of_range_accessors_are_safe()

void test_out_of_range_accessors_are_safe ( void )

Definition at line 489 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_overrideMasks_give_no_bit_to_an_out_of_range_entry()

void test_overrideMasks_give_no_bit_to_an_out_of_range_entry ( void )

Definition at line 142 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_overrideMasks_match_the_shift_they_replace()

void test_overrideMasks_match_the_shift_they_replace ( void )

Definition at line 119 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_overridePinOf_local_is_the_physical_pin()

void test_overridePinOf_local_is_the_physical_pin ( void )

Definition at line 502 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_overridePinOf_remote_is_a_virtual_pin()

void test_overridePinOf_remote_is_a_virtual_pin ( void )

Definition at line 512 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_payload_tracks_the_latest_state_even_if_unsent()

void test_payload_tracks_the_latest_state_even_if_unsent ( void )

Definition at line 325 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_refresh_counter_restarts_after_a_refresh()

void test_refresh_counter_restarts_after_a_refresh ( void )

Definition at line 384 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_refresh_fires_on_the_fifth_unchanged_cycle()

void test_refresh_fires_on_the_fifth_unchanged_cycle ( void )

Definition at line 364 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_remote_encodes_the_unit_number()

void test_remote_encodes_the_unit_number ( void )

Definition at line 61 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_remote_led_pin_round_trips()

void test_remote_led_pin_round_trips ( void )

Definition at line 79 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_remote_unit_out_of_range_is_flagged()

void test_remote_unit_out_of_range_is_flagged ( void )

Definition at line 601 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_remote_without_led_has_pin_zero()

void test_remote_without_led_has_pin_zero ( void )

Definition at line 73 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_remoteOrdinal_counts_remote_entries_only()

void test_remoteOrdinal_counts_remote_entries_only ( void )

Definition at line 110 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_reset_clears_every_unit()

void test_reset_clears_every_unit ( void )

Definition at line 459 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sendPending_addresses_each_unit_by_its_node_id()

void test_sendPending_addresses_each_unit_by_its_node_id ( void )

Definition at line 692 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sendPending_drains_what_it_sends()

void test_sendPending_drains_what_it_sends ( void )

Definition at line 709 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sendPending_only_addresses_the_unit_that_changed()

void test_sendPending_only_addresses_the_unit_that_changed ( void )

Definition at line 723 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sendPending_refreshes_every_unit()

void test_sendPending_refreshes_every_unit ( void )

Definition at line 742 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_sendPending_without_units_never_sends()

void test_sendPending_without_units_never_sends ( void )

Definition at line 763 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_single_unit_payload()

void test_single_unit_payload ( void )

Definition at line 169 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_three_units_one_load_each()

void test_three_units_one_load_each ( void )

Definition at line 206 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_two_units_are_independent()

void test_two_units_are_independent ( void )

Definition at line 192 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_unchanged_state_does_not_flag()

void test_unchanged_state_does_not_flag ( void )

Definition at line 312 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ sendIds

uint8_t sendIds[] { 15, 16, 17 }
staticconstexpr

Definition at line 690 of file test_main.cpp.

◆ sendMap

uint8_t sendMap[] { Load::local(5), Load::remote(1), Load::remote(2), Load::remote(1) }
staticconstexpr

Definition at line 689 of file test_main.cpp.