void LLTemplateMessageBuilderTestObject::test<44>()
		// read variable block past end of message -> 0 repeats
	{
		// build message with single block
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
		U32 outValue, outValue2, inValue = 0xbbbbbbbb;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inValue);
		const U32 bufferSize = 1024;
		U8 buffer[bufferSize];
		memset(buffer, 0xaa, bufferSize);
		memset(buffer, 0, LL_PACKET_ID_SIZE);
		U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
		delete builder;

		// add variable block to reader template
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4));

		// read message value and check block repeat count
		numberMap[1] = &messageTemplate;
		LLTemplateMessageReader* reader = 
			new LLTemplateMessageReader(numberMap);
		reader->validateMessage(buffer, builtSize, LLHost());
		reader->readMessage(buffer, LLHost());
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
		outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1);
		ensure_equals("Ensure present value ", outValue, inValue);
		ensure_equals("Ensure 0 repeats ", outValue2, 0);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<43>()
		// read past end of message -> default values (forward compatibility)
	{
		// build message with single block
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
		U32 outValue, outValue2, inValue = 0xbbbbbbbb;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inValue);
		const U32 bufferSize = 1024;
		U8 buffer[bufferSize];
		memset(buffer, 0xaa, bufferSize);
		memset(buffer, 0, LL_PACKET_ID_SIZE);
		U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
		delete builder;

		// add block to reader template
		messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE));

		// read message value and default value
		numberMap[1] = &messageTemplate;
		LLTemplateMessageReader* reader = 
			new LLTemplateMessageReader(numberMap);
		reader->validateMessage(buffer, builtSize, LLHost());
		reader->readMessage(buffer, LLHost());
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
		reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outValue2);
		ensure_equals("Ensure present value ", outValue, inValue);
		ensure_equals("Ensure default value ", outValue2, 0);
		delete reader;
	}
		static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = const_cast<char*>(_PREHASH_Test0))
		{
			nameMap[_PREHASH_TestMessage] = &messageTemplate;
			LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(nameMap);
			builder->newMessage(_PREHASH_TestMessage);
			builder->nextBlock(name);
			return builder;
		}
	void LLTemplateMessageBuilderTestObject::test<20>()
		// block build order !-> binary order
	{
		U8 buffer1[MAX_BUFFER_SIZE];
		memset(buffer1, 0, MAX_BUFFER_SIZE);
		U8 buffer2[MAX_BUFFER_SIZE];
		memset(buffer2, 0, MAX_BUFFER_SIZE);
		U32 bufferSize1, bufferSize2;

		// build template: Test0 before Test1
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));

		// build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_PREHASH_Test0));
		builder->addU32(_PREHASH_Test0, 0xaaaa);
		builder->nextBlock(_PREHASH_Test1);
		builder->addU32(_PREHASH_Test0, 0xbbbb);
		bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0);
		delete builder;

		// build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb
		builder = defaultBuilder(messageTemplate, const_cast<char*>(_PREHASH_Test1));
		builder->addU32(_PREHASH_Test0, 0xbbbb);
		builder->nextBlock(_PREHASH_Test0);
		builder->addU32(_PREHASH_Test0, 0xaaaa);
		bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0);
		delete builder;

		ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2);
		ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0);
	}
	void LLTemplateMessageBuilderTestObject::test<13>()
		 // Vector3d
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24));
		LLVector3d outValue, inValue = LLVector3d(1,2,3);
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addVector3d(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure LLVector3d", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<10>()
		 // F64
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_F64, 8));
		F64 outValue, inValue = 3232143.33;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addF64(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure F64", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<14>()
		 // Quaternion
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12));
		LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0);
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addQuat(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure LLQuaternion", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<5>()
		 // U16
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U16, 2));
		U16 outValue, inValue = 3;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU16(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure U16", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<8>()
		 // U32
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U32, 4));
		U32 outValue, inValue = 88;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure U32", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<2>()
		 // BOOL
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1));
		BOOL outValue, inValue = TRUE;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addBOOL(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure BOOL", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<17>()
		 // IPPort
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2));
		U16 outValue, inValue = 80;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addIPPort(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure IPPort", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<16>()
		 // IPAddr
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4));
		U32 outValue, inValue = 12344556;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addIPAddr(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure IPAddr", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<36>()
		 // non-zero offset with Vector4
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16));
		LLVector4 outValue, inValue = LLVector4(1,2,3,4);
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addVector4(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(
			messageTemplate, builder, 64);
		reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure LLVector4", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<33>()
		 // non-zero offset with U64
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U64, 8));
		U64 outValue, inValue = 121;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU64(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(
			messageTemplate, builder, 32);
		reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure U64", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<31>()
		 // non-zero offset with F32
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_F32, 4));
		F32 outValue, inValue = 121.44f;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addF32(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(
			messageTemplate, builder, 16);
		reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure F32", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<28>()
		 // non-zero offset with S16
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_S16, 2));
		S16 outValue, inValue = 90;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addS16(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(
			messageTemplate, builder, 2);
		reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure S16", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<27>()
		 // non-zero offset with U8
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U8, 1));
		U8 outValue, inValue = 2;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU8(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(
			messageTemplate, builder, 255);
		reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure U8", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<15>()
		 // UUID
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16));
		LLUUID outValue, inValue;
		inValue.generate();
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addUUID(_PREHASH_Test0, inValue);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue);
		ensure_equals("Ensure UUID", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<18>()
		// String
	{
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1));
		std::string outValue, inValue = "testing";
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addString(_PREHASH_Test0, inValue.c_str());
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		char buffer[MAX_STRING];
		reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer);
		outValue = buffer;
		ensure_equals("Ensure String", inValue, outValue);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<23>()
		// variable repeated block name never accessed
	{
		U32 inTest = 1, outTest;
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(
			createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4));

		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inTest);

		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest);
		S32 blockCount = reader->getNumberOfBlocks(const_cast<char*>(_PREHASH_Test1));
		ensure_equals("Ensure block count", blockCount, 0);
		ensure_equals("Ensure Test0", inTest, outTest);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<24>()
		// forwarding message
	{
		// build template
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4));

		// build message
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, 42);

		// read message
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);

		// forward message
		builder = defaultBuilder(messageTemplate);
		builder->newMessage(_PREHASH_TestMessage);
		reader->copyToBuilder(*builder);
		U8 buffer[MAX_BUFFER_SIZE];
		builder->buildMessage(buffer, MAX_BUFFER_SIZE, 0);

		delete builder;
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<45>()
		// read variable length data past end of message -> 0 length
	{
		// build message with single block
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE));
		U32 outValue, outValue2, inValue = 0xbbbbbbbb;
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inValue);
		const U32 bufferSize = 1024;
		U8 buffer[bufferSize];
		memset(buffer, 0xaa, bufferSize);
		memset(buffer, 0, LL_PACKET_ID_SIZE);
		U32 builtSize = builder->buildMessage(buffer, bufferSize, 0);
		delete builder;

		// add variable block to reader template
		messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_VARIABLE, 4, 
											 MBT_SINGLE));

		// read message value and default string
		numberMap[1] = &messageTemplate;
		LLTemplateMessageReader* reader = 
			new LLTemplateMessageReader(numberMap);
		reader->validateMessage(buffer, builtSize, LLHost());
		reader->readMessage(buffer, LLHost());
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue);
		char outBuffer[bufferSize];
		memset(buffer, 0xcc, bufferSize);
		reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize, 
						  outBuffer);
		outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1);
		ensure_equals("Ensure present value ", outValue, inValue);
		ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0);
		delete reader;
	}
	void LLTemplateMessageBuilderTestObject::test<21>()
		// block appended in declaration -> data appended in binary
	{
		U8 buffer1[MAX_BUFFER_SIZE];
		memset(buffer1, 0, MAX_BUFFER_SIZE);
		U8 buffer2[MAX_BUFFER_SIZE];
		memset(buffer2, 0, MAX_BUFFER_SIZE);
		U32 bufferSize1, bufferSize2;

		// Build template: Test0 only
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));

		// Build message
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, const_cast<char*>(_PREHASH_Test0));
		builder->addU32(_PREHASH_Test0, 0xaaaa);
		bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0);
		delete builder;

		// Build template: Test0 before Test1
		messageTemplate = defaultTemplate();
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4, MBT_SINGLE));
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4, MBT_SINGLE));

		// Build message
		builder = defaultBuilder(messageTemplate, const_cast<char*>(_PREHASH_Test0));
		builder->addU32(_PREHASH_Test0, 0xaaaa);
		builder->nextBlock(_PREHASH_Test1);
		builder->addU32(_PREHASH_Test0, 0xbbbb);
		bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0);
		delete builder;

		ensure_not_equals("Ensure Buffer Sizes Not Equal", bufferSize1, bufferSize2);
		ensure_equals("Ensure Buffer Prefix Equal", memcmp(buffer1, buffer2, bufferSize1), 0);
		ensure_not_equals("Ensure Buffer Contents Not Equal", memcmp(buffer1, buffer2, bufferSize2), 0);
	}
	void LLTemplateMessageBuilderTestObject::test<22>()
		// repeated penultimate block (crashes when data in LLDynamicArrayIndexed)
	{
		U32 inTest00 = 0, inTest01 = 1, inTest1 = 2;
		U32 outTest00, outTest01, outTest1;
		LLMessageTemplate messageTemplate = defaultTemplate();
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test0), MVT_U32, 4));
		messageTemplate.addBlock(createBlock(const_cast<char*>(_PREHASH_Test1), MVT_U32, 4));
		LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate);
		builder->addU32(_PREHASH_Test0, inTest00);
		builder->nextBlock(_PREHASH_Test0);
		builder->addU32(_PREHASH_Test0, inTest01);
		builder->nextBlock(_PREHASH_Test1);
		builder->addU32(_PREHASH_Test0, inTest1);
		LLTemplateMessageReader* reader = setReader(messageTemplate, builder);
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest00, 0);
		reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest01, 1);
		reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outTest1);
		ensure_equals("Ensure Test0[0]", inTest00, outTest00);
		ensure_equals("Ensure Test0[1]", inTest01, outTest01);
		ensure_equals("Ensure Test1", inTest1, outTest1);
		delete reader;
	}