#include "Utilities/commondefs.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable : 4244 ) #endif // text archive #include #include #include "Input\AllRawEvents.hpp" #include "Input\RawEventFactory.hpp" using namespace Input; void init_data(RawEvent *re) { BOOST_LOG_TRIVIAL(debug) << "Initializing RawEvent data"; re->evtype = "abort"; re->source = "test"; re->valid = true; re->timeSource = "Dr Who"; re->eventTime = chron::high_resolution_clock::now(); } void init_data(RawUIEvent *re) { BOOST_LOG_TRIVIAL(debug) << "Initializing RawUIEvent data"; init_data(static_cast(re)); re->detail = 1098765; } void init_data(RawCSAMEvent *re) { BOOST_LOG_TRIVIAL(debug) << "Initializing RawCSAMEvent data"; init_data(static_cast(re)); re->ctrlKey = true; re->altKey = true; re->shiftKey = true; re->metaKey = true; } void init_data(RawMouseEvent *re) { BOOST_LOG_TRIVIAL(debug) << "Initializing RawMouseEvent data"; init_data(static_cast(re)); re->screenX = 1256; re->screenY = 985; re->button = 0xA5; re->buttons = 0x5A; } void init_data(RawPointerEvent *re) { BOOST_LOG_TRIVIAL(debug) << "Initializing RawPointerEvent data"; init_data(static_cast(re)); re->width = 34; re->height = 22; re->pressure = 64; re->tiltX = 13; re->tiltY = 75; re->ptrType = RawPointerEvent::eye; re->isPrimary = true; } template void repeated_serialize_thru_ptr_test() { BOOST_LOG_TRIVIAL(debug) << "...Starting " << typeid(T).name() << " serializing via ptr type " << typeid(ptrClazz).name() << " serialization test"; T obj; // creates and initializes an instance ptrClazz * aobj1; // creates and initializes an instance init_data(&obj); // sets fields to specific values, overwriting default values const ptrClazz *dobj= &obj; // create and open a character archive for output BOOST_LOG_TRIVIAL(debug) << "...Starting serializing via ptr of " << typeid(ptrClazz).name() << " for serialization test"; // create a scope for the timer - output dumped out when it goes out of scope for (int i = 0; i < loopcnt; i++) { event_ostream iostr; { boost::archive::text_oarchive oa(iostr); oa << dobj; } event_istream in_stream(iostr.str()); { boost::archive::text_iarchive ia(in_stream); ia >> aobj1; // creates an instance referred to by this pointer } iostr.clear(); // clear the buffer for the next time around in_stream.clear(); if (i < loopcnt -1) // delete all but the last one delete aobj1; } // just compare the last one assert(*dobj == *aobj1); // delete final one delete aobj1; BOOST_LOG_TRIVIAL(debug) << "...Done with " << typeid(T).name() << " ptr serialization test"; } #define repeat_count 1 void serial_repeat_test() { repeated_serialize_thru_ptr_test(); repeated_serialize_thru_ptr_test(); repeated_serialize_thru_ptr_test(); repeated_serialize_thru_ptr_test(); repeated_serialize_thru_ptr_test(); } int main( int argc, char* argv[] ) { Input::RawEventFactory::registerForSerialization(); // insure registration done serial_repeat_test(); BOOST_LOG_TRIVIAL(debug) << "Exiting input test main "; }