File: attribute_store.test.cpp

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (103 lines) | stat: -rw-r--r-- 2,944 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <algorithm>
#include "external/minunit.h"
#include "attribute_store.h"

MU_TEST(test_attribute_store) {
	AttributeStore store;
	store.reset();

	mu_check(store.size() == 0);

	AttributeSet s1;
	store.addAttribute(s1, "str1", std::string("someval"), 0);
	store.addAttribute(s1, "str2", std::string("a very long string"), 0);
	store.addAttribute(s1, "bool1", false, 0);
	store.addAttribute(s1, "bool2", true, 0);
	store.addAttribute(s1, "float1", (float)42.0, 0);

	const auto s1Index = store.add(s1);

	mu_check(store.size() == 1);

	const auto s1Pairs = store.getUnsafe(s1Index);
	mu_check(s1Pairs.size() == 5);
	const auto str1 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
			return ap->keyIndex == store.keyStore.key2index("str1");
	});
	mu_check(str1 != s1Pairs.end());
	mu_check((*str1)->hasStringValue());
	mu_check((*str1)->stringValue() == "someval");

	const auto str2 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
			return ap->keyIndex == store.keyStore.key2index("str2");
	});
	mu_check(str2 != s1Pairs.end());
	mu_check((*str2)->hasStringValue());
	mu_check((*str2)->stringValue() == "a very long string");

	const auto bool1 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
			return ap->keyIndex == store.keyStore.key2index("bool1");
	});
	mu_check(bool1 != s1Pairs.end());
	mu_check((*bool1)->hasBoolValue());
	mu_check((*bool1)->boolValue() == false);

	const auto bool2 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
			return ap->keyIndex == store.keyStore.key2index("bool2");
	});
	mu_check(bool2 != s1Pairs.end());
	mu_check((*bool2)->hasBoolValue());
	mu_check((*bool2)->boolValue() == true);

	const auto float1 = std::find_if(s1Pairs.begin(), s1Pairs.end(), [&store](auto ap) {
			return ap->keyIndex == store.keyStore.key2index("float1");
	});
	mu_check(float1 != s1Pairs.end());
	mu_check((*float1)->hasFloatValue());
	mu_check((*float1)->floatValue() == 42);
}

MU_TEST(test_attribute_store_reuses) {
	AttributeStore store;
	store.reset();

	mu_check(store.size() == 0);

	{
		AttributeSet s1a;
		store.addAttribute(s1a, "str1", std::string("someval"), 0);
		const auto s1aIndex = store.add(s1a);

		AttributeSet s1b;
		store.addAttribute(s1b, "str1", std::string("someval"), 0);
		const auto s1bIndex = store.add(s1b);

		mu_check(s1aIndex == s1bIndex);
	}

	{
		AttributeSet s1a;
		store.addAttribute(s1a, "str1", std::string("this is a very long string"), 0);
		const auto s1aIndex = store.add(s1a);

		AttributeSet s1b;
		store.addAttribute(s1b, "str1", std::string("this is a very long string"), 0);
		const auto s1bIndex = store.add(s1b);

		mu_check(s1aIndex == s1bIndex);
	}


}

MU_TEST_SUITE(test_suite_attribute_store) {
	MU_RUN_TEST(test_attribute_store);
	MU_RUN_TEST(test_attribute_store_reuses);
}

int main() {
	MU_RUN_SUITE(test_suite_attribute_store);
	MU_REPORT();
	return MU_EXIT_CODE;
}