代码拉取完成,页面将自动刷新
// Test code for vrpn_LamportClock
#ifdef VRPN_USE_OLD_STREAMS
#include <iostream.h>
#else
#include <iostream>
using namespace std;
#endif
#include <assert.h>
#include <vrpn_LamportClock.h>
vrpn_LamportClock * clockA;
vrpn_LamportClock * clockB;
void setUp (void) {
clockA = new vrpn_LamportClock (2, 0);
clockB = new vrpn_LamportClock (2, 1);
}
void tearDown (void) {
if (clockA) delete clockA;
if (clockB) delete clockB;
}
void test_one_getTimestampAndAdvance (void) {
vrpn_LamportTimestamp * t1 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp tc (*t1);
assert(t1);
assert(t1->size() == 2);
assert((*t1)[0] == 1);
assert((*t1)[1] == 0);
assert(!(*t1 < *t1));
assert(!(tc < *t1));
assert(!(*t1 < tc));
vrpn_LamportTimestamp * t2 = clockA->getTimestampAndAdvance();
assert(t2);
assert((*t1)[0] == 1);
assert((*t1)[1] == 0);
assert(t2->size() == 2);
assert((*t2)[0] == 2);
assert((*t2)[1] == 0);
assert(*t1 < *t2);
assert(!(*t2 < *t1));
vrpn_LamportTimestamp * t3 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * t4 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * t5 = clockA->getTimestampAndAdvance();
assert(t5->size() == 2);
assert((*t5)[0] == 5);
assert((*t5)[1] == 0);
delete t1;
delete t2;
delete t3;
delete t4;
delete t5;
}
void test_two (void) {
vrpn_LamportTimestamp * ta1 = clockA->getTimestampAndAdvance();
vrpn_LamportTimestamp * tb1 = clockB->getTimestampAndAdvance();
clockA->receive(*tb1);
vrpn_LamportTimestamp * ta2 = clockA->getTimestampAndAdvance();
assert((*ta2)[0] == 2);
assert((*ta2)[1] == 1);
assert(*ta1 < *ta2);
assert(*tb1 < *ta2);
assert(!(*tb1 < *ta1));
assert(!(*ta1 < *tb1));
delete ta1;
delete tb1;
delete ta2;
}
int main (int, char **) {
setUp();
test_one_getTimestampAndAdvance();
tearDown();
setUp();
test_two();
tearDown();
cout << "OK" << endl;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。