diff options
author | Rick Pasetto <rick@lindenlab.com> | 2009-11-24 14:26:00 -0800 |
---|---|---|
committer | Rick Pasetto <rick@lindenlab.com> | 2009-11-24 14:26:00 -0800 |
commit | f276b73d974a4b47d50e71922846efe9ee0b1409 (patch) | |
tree | d0a003ae4a87f9e04df97863e69d41db4a330ee6 /indra/newview/tests | |
parent | 6d5aff5aecc5c537ea6d24a2f79afa1afa5f47a8 (diff) |
DEV-41998 - refactor mediadataclient to use a std::list, and re-sort every time an item is pulled off the queue
Review #43
This change refactors mediadataclient to no longer use a PriorityQueue (which sorts only on insertion), but rather just use a std::list which is re-sorted on insert, and also when "popped" (at the time the queue timer goes off).
Also implemented a unit test to make sure re-sorting occurs on timer tick.
Diffstat (limited to 'indra/newview/tests')
-rw-r--r-- | indra/newview/tests/llmediadataclient_test.cpp | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/indra/newview/tests/llmediadataclient_test.cpp b/indra/newview/tests/llmediadataclient_test.cpp index 217889c390..6ff2c9446e 100644 --- a/indra/newview/tests/llmediadataclient_test.cpp +++ b/indra/newview/tests/llmediadataclient_test.cpp @@ -191,6 +191,12 @@ public: virtual bool isDead() const { return mDead; } + void setDistanceFromAvatar(F64 val) + { mRep["distance"] = val; } + + void setTotalMediaInterest(F64 val) + { mRep["interest"] = val; } + int getNumBounceBacks() const { return mNumBounceBacks; } @@ -593,6 +599,91 @@ namespace tut ensure("queue empty", mdc->isEmpty()); } - + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); + } + + ////////////////////////////////////////////////////////////////////////////////////////// + + template<> template<> + void mediadataclient_object_t::test<9>() + { + // + // Test queue re-ordering + // + LOG_TEST(9); + + LLMediaDataClientObject::ptr_t o1 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_1,"10.0","1.0")); + LLMediaDataClientObject::ptr_t o2 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_2,"20.0","1.0")); + LLMediaDataClientObject::ptr_t o3 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_3,"30.0","1.0")); + LLMediaDataClientObject::ptr_t o4 = new LLMediaDataClientObjectTest(_DATA(VALID_OBJECT_ID_4,"40.0","1.0")); + { + LLPointer<LLObjectMediaDataClient> mdc = new LLObjectMediaDataClient(NO_PERIOD,NO_PERIOD); + + // queue up all 4 objects. They should now be in the queue in + // order 1 through 4, with 4 being at the front of the queue + mdc->fetchMedia(o1); + mdc->fetchMedia(o2); + mdc->fetchMedia(o3); + mdc->fetchMedia(o4); + + int test_num = 0; + + ensure(STR(test_num) + ". is in queue 1", mdc->isInQueue(o1)); + ensure(STR(test_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(test_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(test_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(test_num) + ". post records", gPostRecords->size(), 0); + + ::pump_timers(); + ++test_num; + + // The first tick should remove the first one + ensure(STR(test_num) + ". is not in queue 1", !mdc->isInQueue(o1)); + ensure(STR(test_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(test_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(test_num) + ". is in queue 4", mdc->isInQueue(o4)); + ensure(STR(test_num) + ". post records", gPostRecords->size(), 1); + + // Now, pretend that object 4 moved relative to the avatar such + // that it is now closest + static_cast<LLMediaDataClientObjectTest*>( + static_cast<LLMediaDataClientObject*>(o4))->setDistanceFromAvatar(5.0); + + ::pump_timers(); + ++test_num; + + // The second tick should still pick off item 2, but then re-sort + // have picked off object 4 + ensure(STR(test_num) + ". is in queue 2", mdc->isInQueue(o2)); + ensure(STR(test_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(test_num) + ". is not in queue 4", !mdc->isInQueue(o4)); + ensure(STR(test_num) + ". post records", gPostRecords->size(), 2); + + ::pump_timers(); + ++test_num; + + // The third tick should pick off object 2 + ensure(STR(test_num) + ". is not in queue 2", !mdc->isInQueue(o2)); + ensure(STR(test_num) + ". is in queue 3", mdc->isInQueue(o3)); + ensure(STR(test_num) + ". post records", gPostRecords->size(), 3); + + // The fourth tick should pick off object 3 + ::pump_timers(); + ++test_num; + + ensure(STR(test_num) + ". is not in queue 3", !mdc->isInQueue(o3)); + ensure(STR(test_num) + ". post records", gPostRecords->size(), 4); + + ensure("queue empty", mdc->isEmpty()); + } + ensure("refcount of o1", o1->getNumRefs(), 1); + ensure("refcount of o2", o2->getNumRefs(), 1); + ensure("refcount of o3", o3->getNumRefs(), 1); + ensure("refcount of o4", o4->getNumRefs(), 1); + } + } |