Skip to content

Commit

Permalink
Changed count to be the max number of results instead of the number i…
Browse files Browse the repository at this point in the history
…nvestigated.
  • Loading branch information
Will Sobel committed Mar 25, 2014
1 parent ebf04c1 commit 42853db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
16 changes: 8 additions & 8 deletions agent/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,9 @@ string Agent::fetchSampleData(std::set<string> &aFilter,

// START SHOULD BE BETWEEN 0 AND SEQUENCE NUMBER
start = (start <= firstSeq) ? firstSeq : start;
end = start + count;
if (end >= mSequence) {
end = mSequence;
endOfBuffer = true;
} else {
endOfBuffer = false;
}

for (uint64_t i = start; i < end; i++)
uint64_t i;
for (i = start; results.size() < count && i < mSequence; i++)
{
// Filter out according to if it exists in the list
const string &dataId = (*mSlidingBuffer)[i]->getDataItem()->getId();
Expand All @@ -1276,6 +1270,12 @@ string Agent::fetchSampleData(std::set<string> &aFilter,
}
}

end = i;
if (i >= mSequence)
endOfBuffer = true;
else
endOfBuffer = false;

if (aObserver != NULL) aObserver->reset();
}

Expand Down
40 changes: 40 additions & 0 deletions test/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,46 @@ void AgentTest::testSequenceNumberRollover()
#endif
}

void AgentTest::testSampleCount()
{
key_value_map kvm;

adapter = a->addAdapter("LinuxCNC", "server", 7878, false);
CPPUNIT_ASSERT(adapter);

int64_t seq = a->getSequence();

// Get the current position
char line[80];

// Add many events
for (int i = 0; i < 128; i++)
{
sprintf(line, "TIME|line|%d|Xact|%d", i, i);
adapter->processData(line);
}

{
path = "/sample";
kvm["path"] = "//DataItem[@name='Xact']";
kvm["from"] = int64ToString(seq);
kvm["count"] = "10";

PARSE_XML_RESPONSE_QUERY(kvm);
CPPUNITTEST_ASSERT_XML_PATH_EQUAL(doc, "//m:Header@nextSequence",
int64ToString(seq + 20).c_str());

CPPUNITTEST_ASSERT_XML_PATH_COUNT(doc, "//m:DeviceStream//m:Position", 10);

// Make sure we got 10 lines
for (int j = 0; j < 10; j++)
{
sprintf(line, "//m:DeviceStream//m:Position[%d]@sequence", j + 1);
CPPUNITTEST_ASSERT_XML_PATH_EQUAL(doc, line, int64ToString(seq + j * 2 + 1).c_str());
}
}

}

void AgentTest::testAdapterCommands()
{
Expand Down
2 changes: 2 additions & 0 deletions test/agent_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class AgentTest : public CppUnit::TestFixture
CPPUNIT_TEST(testAssetStorageWithoutType);
CPPUNIT_TEST(testStreamData);
CPPUNIT_TEST(testSequenceNumberRollover);
CPPUNIT_TEST(testSampleCount);
CPPUNIT_TEST(testStreamDataObserver);
CPPUNIT_TEST(testFailWithDuplicateDeviceUUID);
CPPUNIT_TEST(testMultipleDisconnect);
Expand Down Expand Up @@ -199,6 +200,7 @@ class AgentTest : public CppUnit::TestFixture

// Sequence number tests
void testSequenceNumberRollover();
void testSampleCount();

// Test failure when adding a duplicate device uuid.
void testFailWithDuplicateDeviceUUID();
Expand Down

0 comments on commit 42853db

Please sign in to comment.