• Welcome to Valhalla Legends Archive.
 

Testing Framework

Started by iago, January 16, 2005, 02:22 AM

Previous topic - Next topic

iago

I figured I'd post this here to see if others have tried it (and to brag cuz I'm special :)).

Anyway, my bot is plugin oriented, but sometimes it's useful to stress-test a plugin with a series of calls rather than put it on Battle.net and let it get its ass kicked, or let it ban all your friends.  So I wrote a testing framework which will load a plugin and send events to it, outputting what it is attempting to do rather than actually doing it. 

Here's an example, since my ping class is fairly simple.  The code is:
Quotepublic class PingTester
{
    public static void main(String []args) throws Exception
    {
        System.out.println(">> Loading and Activating Ping Plugin");
        HelperStuff helper = new HelperStuff(new File("/home/iago/workspace/Plugins/Ping.jar"));

        System.out.println();
        System.out.println(">> Sending SID_PING packet to the plugin. The plugin should");
        System.out.println("   turn off TCPNoDelay, send a SID_PING packet, then turn TCPNoDelay");
        System.out.println("   back on.");
        helper.fakePacket(PacketConstants.SID_PING, new byte [] { 0x11, 0x22, 0x33, 0x44 });
       
        System.out.println();
        System.out.println(">> Sending SID_AUTH_CHECK packet with passed authorization.");
        System.out.println("   This should send back a SID_UDPPINGRESPONSE.");
        helper.fakePacket(PacketConstants.SID_AUTH_CHECK, new byte [] { 0x00, 0x00, 0x00, 0x00 });
       
        System.out.println();
        System.out.println(">> Sending SID_AUTH_CHECK packet with failed authorization.");
        System.out.println("   This should get no response.");
        helper.fakePacket(PacketConstants.SID_AUTH_CHECK, new byte [] { 0x00, 0x00, 0x00, 0x01 });
       
        System.out.println();
        System.out.println(">> Sending fake SID_NULL packet.  This should get no reaction.");
        helper.fakePacket(PacketConstants.SID_NULL, new byte [] { });
       
        System.out.println();
        System.out.println(">> Tests complete!");
    }
}

And here's the output:
Quote>> Loading and Activating Ping Plugin
   Plugin is registering itself to handle incoming packet: SID_NULL
   Plugin is registering itself to handle incoming packet: SID_PING
   Plugin is registering itself to handle incoming packet: SID_AUTH_CHECK

>> Sending SID_PING packet to the plugin. The plugin should
   turn off TCPNoDelay, send a SID_PING packet, then turn TCPNoDelay
   back on.
   Plugin is tryin to turn on TCPNoDelay.
   --> Plugin is attempting to send a packet: SID_PING
   Plugin is tryin to turn off TCPNoDelay.

>> Sending SID_AUTH_CHECK packet with passed authorization.
   This should send back a SID_UDPPINGRESPONSE.
   --> Plugin is attempting to send a packet: SID_UDPPINGRESPONSE

>> Sending SID_AUTH_CHECK packet with failed authorization.
   This should get no response.

>> Sending fake SID_NULL packet.  This should get no reaction.

>> Tests complete!

I've written one for nearly every plugin.  Whenever I add a feature, I add a test to it to ensure that it hasn't broken anything.  If I rewrite part of a plugin to function differently, again I can run the tests and feel confident in my work. 

Any questions/comments/opinions? I can post logs from other tests I have, if anybody wants to see them.  They are quite a bit longer, though.

This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna

What's wrong with good old fashioned unit tests?

iago

"Old fashioned"? 

I hated unit tests when I did them, and now I don't remember how to do them properly.  This gives me a more generic interface with my plugins.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*