15a60e47497f21f64e6d79420dc4c56c1907df22akschulzpackage com.android.bluetooth.tests;
25a60e47497f21f64e6d79420dc4c56c1907df22akschulz
35a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport java.io.IOException;
45a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport java.util.ArrayList;
55a60e47497f21f64e6d79420dc4c56c1907df22akschulz
65a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport javax.obex.HeaderSet;
75a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport javax.obex.ObexPacket;
85a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport javax.obex.Operation;
95a60e47497f21f64e6d79420dc4c56c1907df22akschulz
105a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport junit.framework.Assert;
115a60e47497f21f64e6d79420dc4c56c1907df22akschulz
125a60e47497f21f64e6d79420dc4c56c1907df22akschulzimport com.android.bluetooth.tests.TestSequencer.OPTYPE;
135a60e47497f21f64e6d79420dc4c56c1907df22akschulz
145a60e47497f21f64e6d79420dc4c56c1907df22akschulzpublic class SeqStep {
155a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /**
165a60e47497f21f64e6d79420dc4c56c1907df22akschulz     * Test step class to define the operations to be tested.
175a60e47497f21f64e6d79420dc4c56c1907df22akschulz     * Some of the data in these test steps will be modified during
185a60e47497f21f64e6d79420dc4c56c1907df22akschulz     * test - e.g. the HeaderSets will be modified to enable SRM
195a60e47497f21f64e6d79420dc4c56c1907df22akschulz     * and/or carry test information
205a60e47497f21f64e6d79420dc4c56c1907df22akschulz     */
215a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* Operation type - Connect, Get, Put etc. */
225a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public OPTYPE mType;
235a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The headers to send in the request - and validate on server side */
245a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public HeaderSet mReqHeaders = null;
255a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The headers to send in the response - and validate on client side */
265a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public HeaderSet mResHeaders = null;
275a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* Use SRM */
285a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public boolean mUseSrm = false;
295a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The amount of data to include in the body */
305a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ObexTestParams mParams = null;
315a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The offset into the data where the un-pause signal is to be sent */
325a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public int mUnPauseOffset = -1;
335a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The offset into the data where the Abort request is to be sent */
345a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public int mAbortOffset = -1;
355a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The side to perform Abort */
365a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public boolean mServerSideAbout = false;
375a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* The ID of the test step */
385a60e47497f21f64e6d79420dc4c56c1907df22akschulz    private int mId;
395a60e47497f21f64e6d79420dc4c56c1907df22akschulz
405a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public boolean mSetPathBackup = false; /* bit 0 in flags */
415a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public boolean mSetPathCreate = false; /* Inverse of bit 1 in flags */
425a60e47497f21f64e6d79420dc4c56c1907df22akschulz
435a60e47497f21f64e6d79420dc4c56c1907df22akschulz
445a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ISeqStepValidator mValidator = null;
455a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ISeqStepAction mServerPreAction = null;
465a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ISeqStepAction mClientPostAction = null;
475a60e47497f21f64e6d79420dc4c56c1907df22akschulz
485a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* Arrays to hold expected sequence of request/response packets. */
495a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ArrayList<ObexPacket> mRequestPackets = null;
505a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public ArrayList<ObexPacket> mResponsePackets = null;
515a60e47497f21f64e6d79420dc4c56c1907df22akschulz
525a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public int index = 0; /* requests with same index are executed in parallel
535a60e47497f21f64e6d79420dc4c56c1907df22akschulz                             (without waiting for a response) */
545a60e47497f21f64e6d79420dc4c56c1907df22akschulz
555a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public SeqStep(OPTYPE type) {
565a60e47497f21f64e6d79420dc4c56c1907df22akschulz        mRequestPackets = new ArrayList<ObexPacket>();
575a60e47497f21f64e6d79420dc4c56c1907df22akschulz        mResponsePackets = new ArrayList<ObexPacket>();
585a60e47497f21f64e6d79420dc4c56c1907df22akschulz        mType = type;
595a60e47497f21f64e6d79420dc4c56c1907df22akschulz    }
605a60e47497f21f64e6d79420dc4c56c1907df22akschulz
615a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public boolean validate(HeaderSet response, Operation op) throws IOException {
625a60e47497f21f64e6d79420dc4c56c1907df22akschulz        Assert.assertNotNull(mValidator);
635a60e47497f21f64e6d79420dc4c56c1907df22akschulz        return mValidator.validate(this, response, op);
645a60e47497f21f64e6d79420dc4c56c1907df22akschulz    }
655a60e47497f21f64e6d79420dc4c56c1907df22akschulz
665a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public void serverPreAction(HeaderSet request, Operation op) throws IOException {
675a60e47497f21f64e6d79420dc4c56c1907df22akschulz        if(mServerPreAction != null) {
685a60e47497f21f64e6d79420dc4c56c1907df22akschulz            mServerPreAction.execute(this, request, op);
695a60e47497f21f64e6d79420dc4c56c1907df22akschulz        }
705a60e47497f21f64e6d79420dc4c56c1907df22akschulz    }
715a60e47497f21f64e6d79420dc4c56c1907df22akschulz
725a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public void clientPostAction(HeaderSet response, Operation op) throws IOException {
735a60e47497f21f64e6d79420dc4c56c1907df22akschulz        if(mClientPostAction != null) {
745a60e47497f21f64e6d79420dc4c56c1907df22akschulz            mClientPostAction.execute(this, response, op);
755a60e47497f21f64e6d79420dc4c56c1907df22akschulz        }
765a60e47497f21f64e6d79420dc4c56c1907df22akschulz    }
775a60e47497f21f64e6d79420dc4c56c1907df22akschulz
785a60e47497f21f64e6d79420dc4c56c1907df22akschulz
795a60e47497f21f64e6d79420dc4c56c1907df22akschulz    /* TODO: Consider to build these automatically based on the operations
805a60e47497f21f64e6d79420dc4c56c1907df22akschulz     *       to be performed. Validate using utility functions - not strict
815a60e47497f21f64e6d79420dc4c56c1907df22akschulz     *       binary compare.
825a60e47497f21f64e6d79420dc4c56c1907df22akschulz     *
835a60e47497f21f64e6d79420dc4c56c1907df22akschulz     *       OR simply remove!*/
845a60e47497f21f64e6d79420dc4c56c1907df22akschulz    public void addObexPacketSet(ObexPacket request, ObexPacket response) {
855a60e47497f21f64e6d79420dc4c56c1907df22akschulz        mRequestPackets.add(request);
865a60e47497f21f64e6d79420dc4c56c1907df22akschulz        mResponsePackets.add(response);
875a60e47497f21f64e6d79420dc4c56c1907df22akschulz    }
885a60e47497f21f64e6d79420dc4c56c1907df22akschulz}
89