MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / run_sorting_test

Function run_sorting_test

tests/DCPS/QueryCondition/QueryConditionTest.cpp:576–686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574}
575
576bool run_sorting_test(const MessageTypeSupport_var& ts, const Publisher_var& pub,
577 const Subscriber_var& sub)
578{
579 DataWriter_var dw;
580 DataReader_var dr;
581 if (!test_setup(ts, pub, sub, "MyTopic", dw, dr)) {
582 cerr << "ERROR: run_sorting_test: setup failed" << endl;
583 return false;
584 }
585
586 ReturnCode_t ret = RETCODE_OK;
587 MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
588 Message sample;
589 sample.key = 0;
590 sample.iteration = 0;
591 sample.name = "data_X";
592 sample.nest.value = B;
593 for (int i(0); i < 20; ++i, ++sample.key) {
594 //replace the 'X' with a random letter
595 sample.name.inout()[5] = static_cast<char>((rand() % 26) + 'A');
596 ret = mdw->write(sample, HANDLE_NIL);
597 if (ret != RETCODE_OK) return false;
598 if (!(i % 4)) { //once in a while write more than 1 sample per instance
599 Message sample2(sample);
600 sample2.nest.value = A;
601 sample2.name.inout()[5] = static_cast<char>((rand() % 26) + 'A');
602 ret = mdw->write(sample2, HANDLE_NIL);
603 if (ret != RETCODE_OK) return false;
604 sample2.nest.value = C;
605 ret = mdw->write(sample2, HANDLE_NIL);
606 if (ret != RETCODE_OK) return false;
607 }
608 }
609
610 DDS::StringSeq empty_query_params;
611 ReadCondition_var dr_qc = dr->create_querycondition(ANY_SAMPLE_STATE,
612 ANY_VIEW_STATE, ALIVE_INSTANCE_STATE, "ORDER BY name, nest.value",
613 empty_query_params);
614 if (!dr_qc) {
615 cerr << "ERROR: failed to create QueryCondition" << endl;
616 return false;
617 }
618 WaitSet_var ws = new WaitSet;
619 ws->attach_condition(dr_qc);
620 Duration_t five_seconds = {5, 0};
621 bool passed = true, done = false;
622 if (sub->delete_datareader(dr) != DDS::RETCODE_PRECONDITION_NOT_MET) {
623 cerr << "ERROR: the deletion of a DataReader is not allowed if there are "
624 "any existing QueryCondition objects that are attached to the DataReader." << endl;
625 passed = false;
626 done = true;
627 }
628 Readers readers(dr);
629 while (!done) {
630 ConditionSeq active;
631 ret = ws->wait(active, five_seconds);
632 if (ret == RETCODE_TIMEOUT) {
633 cout << "timeout ";

Callers 1

run_testFunction · 0.85

Calls 12

test_setupFunction · 0.85
test_cleanupFunction · 0.85
attach_conditionMethod · 0.80
detach_conditionMethod · 0.80
inoutMethod · 0.45
writeMethod · 0.45
create_queryconditionMethod · 0.45
delete_datareaderMethod · 0.45
waitMethod · 0.45
takeMethod · 0.45
lengthMethod · 0.45
delete_readconditionMethod · 0.45

Tested by

no test coverage detected