Skip to content

Commit

Permalink
add tests for get and set domain lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
poetinger committed Nov 20, 2023
1 parent cf880f0 commit 39b82b1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/core/ddsc/tests/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,47 @@ CU_Test(ddsc_domain_create, raw_config)
ddsrt_free (arg_raw.buf);
}

CU_Test(ddsc_domain_lifecycle, basic_transition)
{
dds_domain_lifecycle_t lifecycle_state = -1;
dds_return_t retval = dds_get_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, &lifecycle_state);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_OK);
CU_ASSERT_EQUAL(lifecycle_state, DDS_DOMAIN_LIFECYCLE_INITIALISATION);

retval = dds_set_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, DDS_DOMAIN_LIFECYCLE_OPERATIONAL);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_OK);
retval = dds_get_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, &lifecycle_state);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_OK);
CU_ASSERT_EQUAL(lifecycle_state, DDS_DOMAIN_LIFECYCLE_OPERATIONAL);
}

CU_Test(ddsc_domain_lifecycle, invalid_transitions)
{
dds_domain_lifecycle_t lifecycle_state = -1;

// Null check, get
dds_return_t retval = dds_get_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, NULL);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_PRECONDITION_NOT_MET);

// Invalid handle, get
retval = dds_get_domain_lifecycle(0, &lifecycle_state);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_BAD_PARAMETER);

// Invalid init->init transition
retval = dds_set_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, DDS_DOMAIN_LIFECYCLE_INITIALISATION);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_PRECONDITION_NOT_MET);

// Invalid handle, set
retval = dds_set_domain_lifecycle(0, DDS_DOMAIN_LIFECYCLE_OPERATIONAL);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_ILLEGAL_OPERATION);

// Invalid operatational->init transition
retval = dds_set_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, DDS_DOMAIN_LIFECYCLE_OPERATIONAL);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_OK);
retval = dds_set_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, DDS_DOMAIN_LIFECYCLE_INITIALISATION);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_PRECONDITION_NOT_MET);

// Nonexistent state
retval = dds_set_domain_lifecycle(DDS_CYCLONEDDS_HANDLE, 3);
CU_ASSERT_EQUAL(retval, DDS_RETCODE_PRECONDITION_NOT_MET);
}

0 comments on commit 39b82b1

Please sign in to comment.