Beispiel #1
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);
}
Beispiel #2
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);
}
Beispiel #3
0
KAI_TESTS_BEGIN

void TestBinaryStream::TestBuiltins()
{
	BinaryStream S;

	S << 42;
	KAI_TEST_TRUE(S.Size() == sizeof(int));
	KAI_TEST_TRUE(S.CanRead(sizeof(int)));
	int N;
	S >> N;
	KAI_TEST_EQUIV(N, 42);
	KAI_TEST_FALSE(S.CanRead(1));

	S.Clear();
	KAI_TEST_TRUE(S.Size() == 0);
	KAI_TEST_FALSE(S.CanRead(1));

	S << String("Hello, world");
	String T;
	S >> T;
	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(T, "Hello, world");
}