File: test_render_queue.cc

package info (click to toggle)
logserver 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: cpp: 10,815; makefile: 3
file content (69 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "test.h"

#include "render_queue.h"

void add_some(RenderQueue* rq, size_t epoch, size_t num) {
	for (size_t i = 0; i < num; ++i) {
		stringstream ss;
		ss << i << "_" << epoch;
		rq->add(new FormatString(ss.str()), i, epoch);
	}
}

void nothing_for(RenderQueue* rq, size_t epoch) {
	FormatString* fs = nullptr;
	size_t pos = G::NO_POS;
	bool ret = rq->remove(epoch, &pos, &fs);
	CHECK(!ret);
	CHECK(fs == nullptr);
	CHECK(pos == G::NO_POS);
}

void something_for(RenderQueue* rq, size_t epoch, size_t num) {
	for (size_t i = 0; i < num; ++i) {
		FormatString* fs = nullptr;
		size_t pos = G::NO_POS;
		bool ret = rq->remove(epoch, &pos, &fs);
		CHECK(ret);
		string s = *fs;
		stringstream ss;
		ss << pos << "_" << epoch;
		CHECK(s == ss.str());
		delete fs;
	}
}

TEST_CASE("add and remove") {
	RenderQueue rq;
	add_some(&rq, 1, 5);
	nothing_for(&rq, 0);
	something_for(&rq, 1, 5);
	nothing_for(&rq, 1);
	CHECK(rq.empty());
	nothing_for(&rq, 2);
}

TEST_CASE("stale epoch") {
	RenderQueue rq;
	add_some(&rq, 0, 5);
	add_some(&rq, 1, 5);
	something_for(&rq, 1, 1);
	nothing_for(&rq, 0);
	something_for(&rq, 1, 1);
	CHECK(!rq.empty());
	nothing_for(&rq, 2);
	nothing_for(&rq, 1);
	CHECK(rq.empty());
	nothing_for(&rq, 2);
}

TEST_CASE("future epoch") {
	RenderQueue rq;
	add_some(&rq, 1, 5);
	something_for(&rq, 1, 2);
	add_some(&rq, 2, 5);
	something_for(&rq, 1, 2);
	something_for(&rq, 2, 1);
	nothing_for(&rq, 1);
}