summaryrefslogtreecommitdiff
path: root/modules/codec/tests/forst.cpp
blob: 1d9c0c316cf6a9b67eaeef943c57d727d9be382e (plain)
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
#include <forstio/test/suite.hpp>
#include "../c++/data.hpp"
#include "../c++/forst.hpp"
#include "../c++/schema_meta.hpp"

#include <iostream>

namespace {
namespace sch {
using namespace saw::schema;

using TestStruct = Struct<
	Member<String, "string">,
	Member<UInt64, "number">,
	Member<Int8, "signed">
>;

using TestArray = Array<
	TestStruct
>;

SAW_TEST("Codec Forst Layer Info"){
	using namespace saw;

	{
		uint64_t depth = impl::forst_codec_info<schema::UInt64>::layers;
		SAW_EXPECT(depth == 0, "Layer info is wrong");
	}
	{
		uint64_t depth = impl::forst_codec_info<schema::String>::layers;
		SAW_EXPECT(depth == 1, "Layer info is wrong");
	}
	{
		uint64_t depth = impl::forst_codec_info<TestStruct>::layers;
		SAW_EXPECT(depth == 1, "Layer info is wrong");
	}
	{
		uint64_t depth = impl::forst_codec_info<TestArray>::layers;
		SAW_EXPECT(depth == 2, "Layer info is wrong");
	}
}

SAW_TEST("Codec Forst Static Size Info"){
	using namespace saw;

	{
		uint64_t depth = impl::forst_codec_info<schema::String>::static_size;
		SAW_EXPECT(depth == 8u, "Static size is wrong");
	}
	{
		uint64_t size = impl::forst_codec_info<schema::UInt8>::static_size;
		SAW_EXPECT(size == 1u, "Static size is wrong");
	}
	{
		uint64_t size = impl::forst_codec_info<schema::UInt16>::static_size;
		SAW_EXPECT(size == 2u, "Static size is wrong");
	}
	{
		uint64_t size = impl::forst_codec_info<schema::UInt32>::static_size;
		SAW_EXPECT(size == 4u, "Static size is wrong");
	}
	{
		uint64_t size = impl::forst_codec_info<schema::UInt64>::static_size;
		SAW_EXPECT(size == 8u, "Static size is wrong");
	}
	{
		uint64_t size = impl::forst_codec_info<TestStruct>::static_size;
		SAW_EXPECT(size == 17u, std::string{"Static size is wrong: "} + std::to_string(size));
	}
}

SAW_TEST("Codec Forst Primitive"){
	using namespace saw;

	data<UInt64, encode::KelForst> forst_dat;

	uint64_t foo = 4213u;

	forst_dat.set(foo);

	uint64_t val = forst_dat.get();

	SAW_EXPECT(val == foo, "Unexpected value");
}
}
}