コード例 #1
0
TEST(JsonTest, CreateJson)
{
    ScopedDevice sd1(sample_complete);
    ASSERT_NE(sd1.device, nullptr);

    std::unique_ptr<char, void (*)(void *)> json(
            mb_device_to_json(sd1.device), free);
    ASSERT_TRUE(json.operator bool());

    ScopedDevice sd2(json.get());
    ASSERT_TRUE(mb_device_equals(sd1.device, sd2.device));
}
コード例 #2
0
TEST(JsonTest, LoadMultiple)
{
    ScopedDevices sd1(sample_multiple);
    ASSERT_NE(sd1.devices, nullptr);

    ScopedDevices sd2(sample_complete);
    ASSERT_EQ(sd2.devices, nullptr);
    ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE);
    ASSERT_STREQ(sd2.error.context, ".");
    ASSERT_STREQ(sd2.error.actual_type, "object");
    ASSERT_STREQ(sd2.error.expected_type, "array");
}
コード例 #3
0
TEST(JsonTest, LoadInvalidType)
{
    ScopedDevice sd1(sample_invalid_root);
    ASSERT_EQ(sd1.device, nullptr);
    ASSERT_EQ(sd1.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE);
    ASSERT_STREQ(sd1.error.context, ".");
    ASSERT_STREQ(sd1.error.actual_type, "array");
    ASSERT_STREQ(sd1.error.expected_type, "object");

    ScopedDevice sd2(sample_invalid_type);
    ASSERT_EQ(sd2.device, nullptr);
    ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_MISMATCHED_TYPE);
    ASSERT_STREQ(sd2.error.context, ".boot_ui");
    ASSERT_STREQ(sd2.error.actual_type, "string");
    ASSERT_STREQ(sd2.error.expected_type, "object");
}
コード例 #4
0
TEST(JsonTest, LoadInvalidValue)
{
    ScopedDevice sd1(sample_invalid_device_flags);
    ASSERT_EQ(sd1.device, nullptr);
    ASSERT_EQ(sd1.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE);
    ASSERT_STREQ(sd1.error.context, ".flags[0]");

    ScopedDevice sd2(sample_invalid_tw_flags);
    ASSERT_EQ(sd2.device, nullptr);
    ASSERT_EQ(sd2.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE);
    ASSERT_STREQ(sd2.error.context, ".boot_ui.flags[0]");

    ScopedDevice sd3(sample_invalid_tw_pixel_format);
    ASSERT_EQ(sd3.device, nullptr);
    ASSERT_EQ(sd3.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE);
    ASSERT_STREQ(sd3.error.context, ".boot_ui.pixel_format");

    ScopedDevice sd4(sample_invalid_tw_force_pixel_format);
    ASSERT_EQ(sd4.device, nullptr);
    ASSERT_EQ(sd4.error.type, MB_DEVICE_JSON_UNKNOWN_VALUE);
    ASSERT_STREQ(sd4.error.context, ".boot_ui.force_pixel_format");
}
コード例 #5
0
ファイル: ex7_11.cpp プロジェクト: KwangKa/CppPrimer5th
int main() {
    std::cout << "Default Constructor" << std::endl;
    Sales_data sd1;
    print(std::cout, sd1);
    std::cout << std::endl;
    
    std::cout << "Construct with bookNo" << std::endl;
    Sales_data sd2("978-7-121");
    print(std::cout, sd2);
    std::cout << std::endl;
    
    std::cout << "Construct with bookNo, units_sold, price" << std::endl;
    Sales_data sd3("978-7-121", 3, 25);
    print(std::cout, sd3);
    std::cout << std::endl;

    std::cout << "Construct with istream std::cin" << std::endl;
    Sales_data sd4(std::cin);
    print(std::cout, sd4);
    std::cout << std::endl;

    return 0;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: SuperMagicBadger/Zombiess
int main()
{
	RakNet::RakPeerInterface *rakPeer[2];
	rakPeer[0]=RakNet::RakPeerInterface::GetInstance();
	rakPeer[1]=RakNet::RakPeerInterface::GetInstance();
	RakNet::SocketDescriptor sd1(50000,0),sd2(50002,0);
	rakPeer[0]->Startup(1,&sd1, 1);
	rakPeer[1]->Startup(1,&sd2, 1);
	rakPeer[1]->SetMaximumIncomingConnections(1);
	RakNet::UDPForwarder udpForwarder;
	
	printf("Demonstrates the UDP Forwarder class\n");
	printf("It routes datagrams from system to another, at the UDP level.\n");
	printf("You probably won't use UDPForwarder directly.\n");
	printf("See UDPProxyClient, UDPProxyServer, UDPProxyCoordinator.\n");
	
	// Start the forwarder
	udpForwarder.Startup();

	// RakNet will send a message at least every 5 seconds. Add another second to account for thread latency
	const RakNet::TimeMS timeoutOnNoDataMS=6000;

	// Address is probably 192.168.0.1. Fix it to be 127.0.0.1.
	// Only necessary to do this when connecting through the loopback on the local system. In a real system we'd stick with the external IP
	RakNet::SystemAddress peer0Addr = rakPeer[0]->GetMyBoundAddress();
	RakAssert(peer0Addr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS);
	RakNet::SystemAddress peer1Addr = rakPeer[1]->GetMyBoundAddress();
	RakAssert(peer1Addr!=RakNet::UNASSIGNED_SYSTEM_ADDRESS);
// 	peer0Addr.FromString("127.0.0.1");
// 	peer1Addr.FromString("127.0.0.1");

	unsigned short fowardPort;
	if (!udpForwarder.StartForwarding(peer0Addr,peer1Addr, timeoutOnNoDataMS, 0, AF_INET, &fowardPort,0))
	{
		printf("Socket error\n");
		return 1;
	}

	// Send a connect message to the forwarder, on the port to forward to rakPeer[1]
	rakPeer[0]->Connect(peer1Addr.ToString(false), fowardPort, 0, 0);
	
	printf("'q'uit.\n");
	RakNet::Packet *p;
	while (1)
	{
		for (int i=0; i < 2 ; i++)
		{
			p=rakPeer[i]->Receive();
			while (p)
			{
				if (p->data[0]==ID_DISCONNECTION_NOTIFICATION)
					printf("%s disconnected\n", p->systemAddress.ToString(true));
				else if (p->data[0]==ID_CONNECTION_LOST)
					printf("Lost connection to %s (failure)\n", p->systemAddress.ToString(true));
				else if (p->data[0]==ID_NO_FREE_INCOMING_CONNECTIONS)
					printf("%s has no free incoming connections.\n", p->systemAddress.ToString(true));
				else if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
					printf("%s connected to us (success)\n", p->systemAddress.ToString(true));
				else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
					printf("Connection request accepted from %s (success)\n", p->systemAddress.ToString(true));
				else if (p->data[0]==ID_CONNECTION_ATTEMPT_FAILED)
					printf("Failed to connect to %s (failure)\n", p->systemAddress.ToString(true));
	
				rakPeer[i]->DeallocatePacket(p);
				p=rakPeer[i]->Receive();
			}
		}

		udpForwarder.Update();

		if (kbhit())
		{
			char ch = getch();
			if (ch=='q' || ch=='Q')
				break;
		}

		RakSleep(30);
	}

	rakPeer[0]->Shutdown(100,0);
	rakPeer[1]->Shutdown(100,0);
	RakNet::RakPeerInterface::DestroyInstance(rakPeer[0]);
	RakNet::RakPeerInterface::DestroyInstance(rakPeer[1]);
	return 0;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: CaiZhongda/ClashOfClans
int main()
{
	printf("This sample demonstrates incrementally sending a file with\n");
	printf("the FileListTransferPlugin. Incremental sends will read and send the.\n");
	printf("file only as needed, rather than putting the whole file in memory.\n");
	printf("This is to support sending large files to many users at the same time.\n");
	printf("Difficulty: Intermediate\n\n");

	TestCB testCB;
	RakNet::FileListTransfer flt1, flt2;
#ifdef USE_TCP
	RakNet::PacketizedTCP tcp1, tcp2;
	#if RAKNET_SUPPORT_IPV6==1
	const bool testInet6=true;
	#else
	const bool testInet6=false;
	#endif
	if (testInet6)
	{
		tcp1.Start(60000,1,-99999,AF_INET6);
		tcp2.Start(60001,1,-99999,AF_INET6);
		tcp2.Connect("::1",60000,false,AF_INET6);
	}
	else
	{
		tcp1.Start(60000,1,-99999,AF_INET);
		tcp2.Start(60001,1,-99999,AF_INET);
		tcp2.Connect("127.0.0.1",60000,false,AF_INET);
	}
	tcp1.AttachPlugin(&flt1);
	tcp2.AttachPlugin(&flt2);
#else
	RakNet::RakPeerInterface *peer1 = RakNet::RakPeerInterface::GetInstance();
	RakNet::RakPeerInterface *peer2 = RakNet::RakPeerInterface::GetInstance();
	RakNet::SocketDescriptor sd1(60000,0),sd2(60001,0);
	peer1->Startup(1,&sd1,1);
	peer2->Startup(1,&sd2,1);
	peer1->SetMaximumIncomingConnections(1);
	peer2->Connect("127.0.0.1",60000,0,0,0);
	peer1->AttachPlugin(&flt1);
	peer2->AttachPlugin(&flt2);
	peer1->SetSplitMessageProgressInterval(9);
	peer2->SetSplitMessageProgressInterval(9);
#endif
	// Print sending progress notifications
	flt1.AddCallback(&testFileListProgress);
	// Run incremental reads in a thread so the read does not block the main thread
	flt1.StartIncrementalReadThreads(1);
	RakNet::FileList fileList;
	RakNet::IncrementalReadInterface incrementalReadInterface;
	printf("Enter complete filename with path to test:\n");
	char str[256];
	Gets(str, sizeof(str));
	if (str[0]==0)
		strcpy(str, "D:\\RakNet\\Lib\\RakNetLibStaticDebug.lib");
	file=str;
	fileCopy=file+"_copy";
	// Reference this file, rather than add it in memory. Will send 1000 byte chunks. The reason to do this is so the whole file does not have to be in memory at once
	unsigned int fileLength = GetFileLength(file.C_String());
	if (fileLength==0)
	{
		printf("Test file %s not found.\n", file.C_String());

#ifdef USE_TCP
#else
		RakNet::RakPeerInterface::DestroyInstance(peer1);
		RakNet::RakPeerInterface::DestroyInstance(peer2);
#endif
		return 1;
	}
	fileList.AddFile(file.C_String(), file.C_String(), 0, fileLength, fileLength, FileListNodeContext(0,0), true);
	// Wait for the connection
	printf("File added.\n");
	RakSleep(100);
	RakNet::Packet *packet1, *packet2;
	while (1)
	{
#ifdef USE_TCP
		RakNet::SystemAddress sa;
		sa=tcp2.HasCompletedConnectionAttempt();
		if (sa!=RakNet::UNASSIGNED_SYSTEM_ADDRESS)
		{
			flt2.SetupReceive(&testCB, false, sa);
			break;
		}
#else
		// Wait for the connection request to be accepted
		packet2=peer2->Receive();
		if (packet2 && packet2->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
		{
			flt2.SetupReceive(&testCB, false, packet2->systemAddress);
			peer2->DeallocatePacket(packet2);
			break;
		}
		peer2->DeallocatePacket(packet2);
#endif
		RakSleep(30);
	}

	// When connected, send the file. Since the file is a reference, it will be sent incrementally
	while (1)
	{
#ifdef USE_TCP
		packet1=tcp1.Receive();
		packet2=tcp2.Receive();
		RakNet::SystemAddress sa;
		sa = tcp1.HasNewIncomingConnection();
		if (sa!=RakNet::UNASSIGNED_SYSTEM_ADDRESS)
			flt1.Send(&fileList,0,sa,0,HIGH_PRIORITY,0, &incrementalReadInterface, 2000 * 1024);
		tcp1.DeallocatePacket(packet1);
		tcp2.DeallocatePacket(packet2);
#else
		packet1=peer1->Receive();
		packet2=peer2->Receive();
		if (packet1 && packet1->data[0]==ID_NEW_INCOMING_CONNECTION)
			flt1.Send(&fileList,peer1,packet1->systemAddress,0,HIGH_PRIORITY,0, &incrementalReadInterface, 2000000);
		
		peer1->DeallocatePacket(packet1);
		peer2->DeallocatePacket(packet2);

#endif
		RakSleep(0);
	}
	
#ifdef USE_TCP
#else
	RakNet::RakPeerInterface::DestroyInstance(peer1);
	RakNet::RakPeerInterface::DestroyInstance(peer1);
#endif


	return 0;
}