0 Star 0 Fork 1

ianaxe/vrpn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vrpn_LamportClock.t.C 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
// 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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ianaxe/vrpn.git
git@gitee.com:ianaxe/vrpn.git
ianaxe
vrpn
vrpn
master

搜索帮助

371d5123 14472233 46e8bd33 14472233