コード例 #1
0
ファイル: main.cpp プロジェクト: developerjoe/cpp-examples
int main(int argc, char **argv) {

    socketTest();

    return 0;
}
コード例 #2
0
int main(int argc, char *argv[]) {
	bool error = false;
	uint8_t buffer[256];
	uint16_t bufferSize = 256;
	StreamParser p(streamReader, buffer, bufferSize, handlers, 1, NULL);
	
	while(p.parse() >= 0);
	
	int16_t theInt = 400;
	float theFloat = 213423.23466432;
	uint16_t functionID = 1;
	
	char *stri = (char *)"hello world";
	
	uint8_t indexTable[] = { Object::T_UINT16, Object::T_INT16, Object::T_STRING, Object::T_FLOAT, Object::T_INT32, Object::T_INT64, (uint8_t)(strlen(stri) + 1) };
	Object o(indexTable, 6);
	
	uint8_t dataBuffer[o.getDataSize()];
	o.setDataBuffer(dataBuffer);
	
	o.uint16At(0, functionID); //function id
	o.int16At(1, theInt); //payload argument
	o.strAt(2, stri, strlen(stri) + 1);
	if(!o.floatAt(3, theFloat)) {
		printf("Failed to set float value\n");
	}
	o.int32At(4, 345589619);
	o.int64At(5, 9384760934765065ll);
	
	if(o.int64At(5) != 9384760934765065ll) {
		printf("Retrieved int64 does not equal actual A:%lld, R:%lld\n", (long long int)9384760934765065ll, (long long int)o.int64At(5));
	}
	
	if(o.int32At(4) != 345589619) {
		printf("Retrieved int32 does not equal actual\n");
	}
	
	if(o.floatAt(3) != theFloat) {
		printf("Retrieved float does not equal actual A:%f, R:%f\n", theFloat, o.floatAt(3));
	}
	
	if(o.int16At(1) != theInt) {
		printf("Retrieved int does not equal actual A:%d R:%d\n", theInt, o.int16At(1));
	}
	
	StreamParser::PacketHeader ph = StreamParser::makePacket(16, o.getSize());
	
	printf("generated packet: ");
	printHex(&ph, sizeof(ph));
	o.writeTo(writer, NULL);
	printf("\n");
	
	
	testBuffer = ((uint8_t *)(&ph));
	testBufferSize = sizeof(StreamParser::PacketHeader);
	testBufferIndex = 0;
	
	printf("rpc call: ");
	if(rpc.call(10, "cCds", -10, 10, 320, "hello world") <= 0) {
		printf("error doing rpc call");
	}
	printf("\n");
	
	if(error) {
		printf("FAIELD: Object & RPC buffer tests\n");
	} else {
		printf("PASSED: Object & RPC buffer tests\n");
	}

	printf("Calling socket tests\n");
	socketTest();
	printf("PASSED: Socket Tests\n");

}