Exemple #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);
}
Exemple #2
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");
}