Example #1
0
void TestBinaryStream::TestArray()
{
	Registry R;
	R.AddClass<Array>("Array");
	R.AddClass<int>("int");

	Pointer<Array> A = R.New<Array>();
	A->Append(R.New(0));
	A->Append(R.New(1));
	A->Append(R.New(2));
	A->Append(R.New(3));

	BinaryStream S;
	S.SetRegistry(&R);

	S << A;
	Object Q;
	S >> Q;

	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(Q.GetTypeNumber(), Type::Traits<Array>::Number);
	const Array &B = ConstDeref<Array>(Q);
	KAI_TEST_EQUIV(B.Size(), 4);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(0)), 0);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(1)), 1);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(2)), 2);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(3)), 3);
}
Example #2
0
void TestBinaryStream::TestList()
{
	Registry R;
	List::Register(R);
	R.AddClass<void>("void");
	R.AddClass<int>("int");
	R.AddClass<String>("String");

	Pointer<List> list = R.New<List>();
	list->Append(R.New(123));
	list->Append(R.New(456));
	list->Append(R.New("Hello"));
	BinaryStream stream(R);
	stream << list;
	Object result;
	stream >> result;

	KAI_TRACE_1(list);
	KAI_TRACE_1(stream);
	KAI_TRACE_1(result);

	KAI_TEST_TRUE(result.Exists());
	KAI_TEST_TRUE(result.IsType<List>());
	KAI_TEST_EQUIV(ConstDeref<List>(result).Size(), 3);
	KAI_TEST_EQUIV(result, list);

	Pointer<List> result_list = result;
	KAI_TEST_EQUIV(ConstDeref<String>(result_list->Back()), "Hello");
	result_list->PopBack();
	KAI_TEST_EQUIV(ConstDeref<int>(result_list->Back()), 456);
	result_list->PopBack();
	KAI_TEST_EQUIV(ConstDeref<int>(result_list->Back()), 123);
	result_list->PopBack();
	KAI_TEST_EQUIV(ConstDeref<List>(result_list).Size(), 0);
}
Example #3
0
void TestBinaryStream::TestObject()
{
	Registry R;
	R.AddClass<int>("int");

	BinaryStream S;
	S.SetRegistry(&R);

	Pointer<int> N = R.New(42);
	S << N;
	Object Q;
	S >> Q;
	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(Q.GetTypeNumber(), Type::Traits<int>::Number);
	KAI_TEST_EQUIV(ConstDeref<int>(Q), 42);

	S.Clear();
	KAI_TEST_TRUE(S.Empty());

	N.Set("child0", R.New(123));
	S << N;
	Object M;
	S >> M;
	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(ConstDeref<int>(M), 42);
	KAI_TEST_TRUE(M.Has("child0"));
	KAI_TEST_EQUIV(ConstDeref<int>(M.Get("child0")), 123);
}
Example #4
0
TEST_F(TestProperties, TestBuilder)
{
	Registry R;
	R.AddClass<int>();
	R.AddClass<Vector>();

	ClassBuilder<PropTest>(R)
		.Methods
		.Properties
			("num", &PropTest::num)
			("p_num", &PropTest::p_num)
			("object", &PropTest::object)
		;
	Pointer<PropTest> prop_test = R.New<PropTest>();
	ASSERT_TRUE(prop_test);
	ClassBase const *klass = prop_test.GetClass();
	ASSERT_TRUE(klass->HasProperty("num"));
	ASSERT_TRUE(klass->HasProperty("p_num"));
	ASSERT_TRUE(prop_test.Has("num"));
	ASSERT_FALSE(prop_test.Has("p_num"));

	Pointer<int> N1 = R.New(123);
	Pointer<int> N2 = R.New(456);
	Pointer<int> N3 = R.New(789);

	ASSERT_FALSE(N1.HasParent());
	prop_test->p_num = N1;
	ASSERT_TRUE(N1.HasParent());
	ASSERT_TRUE(N1.GetParentHandle() == prop_test.GetHandle());
	
	prop_test.Set("num", N2);
	ASSERT_TRUE(prop_test->num == *N2);
	ASSERT_FALSE(N2.HasParent());
	prop_test.SetValue("num", 666);
	ASSERT_TRUE(prop_test->num == 666);
	ASSERT_FALSE(N2.HasParent());


	ASSERT_TRUE(N1.HasParent());
	ASSERT_FALSE(N3.HasParent());
	prop_test.Set("p_num", N3);
	ASSERT_FALSE(N1.HasParent());
	ASSERT_TRUE(N3.HasParent());
	ASSERT_TRUE(N3.GetParentHandle() == prop_test.GetHandle());

	prop_test.SetValue("p_num", 42);
	EXPECT_EQ(*N3, 42);

	prop_test.SetValue("num", 13);
	EXPECT_EQ(prop_test->num, 13);
}