Exemplo n.º 1
0
TEST_RESULT TestAllocateNotificationMessage()
{
	std::cout << "create noti with no cid" << std::endl;
	{
		std::stringstream messageToBeSent;
		Message * noti  = new AllocateNotification("gutentag");

		noti->Write(messageToBeSent);
		std::cout << messageToBeSent.str() << std::endl;
	}

	std::cout << "create noti with cid" << std::endl;
	{
		std::stringstream messageToBeSent;
		Message * noti = new AllocateNotification("gutentag", 15);

		noti->Write(messageToBeSent);
		std::cout << messageToBeSent.str() << std::endl;
	}

	std::cout << "create noti with error" << std::endl;
	{
		std::stringstream messageToBeSent;
		Notification * noti = new AllocateNotification("gutentag", 15);
		noti->SetError(ERRORCODE_WRONG_CHANNELID, "crab happened");
		noti->Write(messageToBeSent);
		std::cout << messageToBeSent.str() << std::endl;
	}

	std::cout << "create Allocate noti with error and cid" << std::endl;
	{
		std::stringstream messageToBeSent;
		AllocateNotification * noti = new AllocateNotification("gutentag", 15);
		noti->SetError(ERRORCODE_WRONG_CHANNELID, "crab happened 2");
		noti->Write(messageToBeSent);
		std::cout << messageToBeSent.str() << std::endl;

		pugi::xml_document* doc = new pugi::xml_document();
		ParseResponse(doc, ( char*)(messageToBeSent.str().c_str()));
		AllocateNotification * res = new AllocateNotification(doc);

		std::cout << "channel id" << res->GetChannelId() << std::endl;
		ErrorCode errc;
		const char * errstr;
		res->GetError(errc, errstr);
		std::string messageName = res->GetMessageName();

		std::cout << "message name" << messageName << std::endl;
		std::cout << "err code" << errc << std::endl;
		std::cout << "err str" << errstr << std::endl;


	}

	std::cout << "test static functionality" << std::endl;
		{
			std::stringstream messageToBeSent;
			AllocateNotification * noti = new AllocateNotification("gutentag", 25);
			noti->SetError(ERRORCODE_WRONG_CHANNELID, "crab happened 3");
			noti->Write(messageToBeSent);
			std::cout << messageToBeSent.str() << std::endl;

			pugi::xml_document* doc = new pugi::xml_document();
			ParseResponse(doc, ( char*)(messageToBeSent.str().c_str()));

			if (Notification::NOTIFICATIONTTYPE_ALLOCATE == Notification::GetNotificationType(doc))
				std::cout << "type obtained properly" << std::endl;

			std::cout << "tag" << Notification::GetNotificationTag(doc) << std::endl;

		}


	return PASSED;

}