summaryrefslogtreecommitdiff
path: root/modules/codec/tests/data.cpp
blob: 57c56d34d4d005b30f1d7d64a6603bf10b7da90d (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
#include <forstio/test/suite.hpp>
#include "../c++/data.hpp"

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

using Int32Array = Array<
	Int32
>;
}

SAW_TEST("Data Native/Bool"){
	using namespace saw;

	data<sch::Bool> t{true};
	data<sch::Bool> f;

	SAW_EXPECT(t.get(), "Should hold true");
	SAW_EXPECT(!f.get(), "Should default to false");

	SAW_EXPECT((t != f), "Should not be equal");
	SAW_EXPECT(((t && f).get() == false), "Wrong conjunction");
	SAW_EXPECT(((t || f).get() == true), "Wrong disjunction");
	SAW_EXPECT(((!f).get() == true), "Wrong negation");

	f.set(true);
	SAW_EXPECT((t == f), "Should be equal");

	constexpr data<sch::Bool> ct{true};
	static_assert(ct.get(), "Should be usable at compile time");
}

SAW_TEST("Data Native/Array Access with Data Native"){
	using namespace saw;

	data<sch::Int32Array,encode::Native> prim{2u};
	prim.at(1u).set(0);

	data<schema::UInt64, encode::Native> i{1u};

	auto& a = prim.at({i});

	a.set(5);

	auto b = prim.at({i});
	b.set(10);
	// Check if it's a reference being manipulated
	SAW_EXPECT(a.get() == 5, "'a' has unexpected value.");
	SAW_EXPECT(b.get() == 10, "'b' has unexpected value.");
}

SAW_TEST("Data Native/Indexing"){
	using namespace saw;

	data<sch::Int32Array, encode::Native> foo{10u};

	auto& b = foo.at(5u);

	b.set(10);

	auto foo_meta = foo.dims();
	auto foo_mi = foo_meta.at(0u);

	for(uint64_t i{0u}; i < foo_mi.get(); ++i){
		auto& a = foo.at(i);
		a.set(5 * i);
	}
	for(uint64_t i{0u}; i < foo_mi.get(); ++i){
		auto& a = foo.at(i);
		SAW_EXPECT(a.get() == static_cast<typename saw::native_data_type<sch::Int32>::type>(5*i), std::string{"5*i, but is "} + std::to_string(i));
	}
}

SAW_TEST("Data CT/Fixed Array"){
	using namespace saw;
	constexpr data<sch::FixedArray<sch::Int32,2u>> foo{{10,5}};
}



}