
#include "cSchedMsgTest.h"
#include "Test.h"
#include <sstream>

#define DHT_APPTYPE "vdr"

void test() {

	cSchedMsgRC msg_r(3,3);
	testFalse(msg_r.isSerialized(), "isSerialized");

	cSchedMsgSuppress msg_s(4);

	testEquals(msg_s.getSuppress(), 4.0, "suppress");
	testEquals(msg_r.getR(), 3.0, "request");

	time_t now = time(NULL);
	msg_r.setChannel("RTL");
	msg_r.setStartTime(now);

	//serialization
	ostringstream os;
	os << "RC " << 3.0 << " " << 3.0 << " " << now << " RTL" ;
	testEquals(msg_r.serialize(),  os.str(), "serialize"); 
	//cout << msg_r.serialize() << " " << os.str() << endl;

	cSchedMsgRC msg_n;
	msg_n.createFromRaw(msg_r.serialize());
	testTrue(msg_n.getR() == msg_r.getR(), "getR()");
//	TRACEBOOL(msg_n.getR(), msg_r.getR())

	// message sending
	int sd = dht_socket();
	if (sd < 0) {
		cerr << "error dht_socket" << endl;
		return;
	}
	struct dht_apptype dat;
	dat.apptype =  DHT_APPTYPE;
	dat.len = strlen(DHT_APPTYPE);
	dat.mustbehashed = true;

	if (dht_bind(sd, &dat) < 0) {
		cerr << "error dht_bind: " << dht_strerror(sd) << endl;
		return;
	}
	msg_n.sendto(sd);

}

	

int main() {
	test();
}
