[Utils] Add a template vertion of executeOnGLibEventLoop for improving safety.

We move the structure outside of the test function, because the
C++ cannot use the local type as a template parameter.
(C++11 can do that though...)