| 921 | } |
| 922 | |
| 923 | void |
| 924 | PubDriver::allocator_test () |
| 925 | { |
| 926 | size_t n_chunks = TheServiceParticipant->n_chunks (); |
| 927 | |
| 928 | ::DDS::ReturnCode_t ret = ::DDS::RETCODE_OK; |
| 929 | |
| 930 | ::Xyz::Foo foo1; |
| 931 | foo1.a_long_value = 101010; |
| 932 | foo1.handle_value = -1; |
| 933 | foo1.sample_sequence = -1; |
| 934 | foo1.writer_id = -1; |
| 935 | |
| 936 | ::DDS::InstanceHandle_t handle |
| 937 | = foo_datawriter_->register_instance(foo1); |
| 938 | |
| 939 | ::Xyz::Foo foo2; |
| 940 | foo2.a_long_value = 101010; |
| 941 | foo2.handle_value = handle; |
| 942 | foo2.writer_id = 0; |
| 943 | |
| 944 | const SerializedSizeBound bound = MarshalTraits< ::Xyz::Foo>::serialized_size_bound(encoding); |
| 945 | |
| 946 | // Allocate serialized foo data from pre-allocated pool |
| 947 | for (size_t i = 1; i <= n_chunks; i ++) { |
| 948 | foo2.sample_sequence = static_cast<CORBA::Long>(i); |
| 949 | |
| 950 | ret = foo_datawriter_->write(foo2, handle); |
| 951 | |
| 952 | TEST_CHECK(ret == ::DDS::RETCODE_OK); |
| 953 | |
| 954 | if (bound) { |
| 955 | TEST_CHECK(foo_datawriter_servant_->data_allocator() != 0); |
| 956 | TEST_CHECK(foo_datawriter_servant_->data_allocator()->allocs_from_heap_ == 0); |
| 957 | TEST_CHECK(foo_datawriter_servant_->data_allocator()->allocs_from_pool_ == static_cast<unsigned long>(i)); |
| 958 | } else { |
| 959 | TEST_CHECK(foo_datawriter_servant_->data_allocator() == 0); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | // The pre-allocated pool is full, now the foo data is allocated from heap |
| 964 | for (size_t i = 1; i <= 2; i ++) { |
| 965 | foo2.sample_sequence = static_cast<CORBA::Long>(i + n_chunks); |
| 966 | |
| 967 | ret = foo_datawriter_->write(foo2, handle); |
| 968 | |
| 969 | TEST_CHECK(ret == ::DDS::RETCODE_OK); |
| 970 | |
| 971 | if (bound) { |
| 972 | TEST_CHECK(foo_datawriter_servant_->data_allocator() != 0); |
| 973 | TEST_CHECK(foo_datawriter_servant_->data_allocator()->allocs_from_heap_ == static_cast<unsigned long>(i)); |
| 974 | TEST_CHECK(foo_datawriter_servant_->data_allocator()->allocs_from_pool_ == static_cast<unsigned long>(n_chunks)); |
| 975 | } else { |
| 976 | TEST_CHECK(foo_datawriter_servant_->data_allocator() == 0); |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 |
nothing calls this directly
no test coverage detected