#include "include/CommandDecoderTest.h" #include "CommandDecoder.h" QList CommandDecoderTest::create2CommandSample() { //-node 3 -g -f 11 -o filetext.txt QList blist; CommandsType b1; CommandsType b2; CommandsType b3; CommandsType b4; b1.command = "-node"; b1.value = "3"; blist.append(b1); b2.command = "-g"; b2.value = Q_NULLPTR; blist.append(b2); b3.command = "-f"; b3.value = "11"; blist.append(b3); b4.command = "-o"; b4.value = "filetext.txt"; blist.append(b4); return blist; } //**************************************************************** QList CommandDecoderTest::createCorrectOrderOfCommand() { //-node 3 -f 7 QList blist; CommandsType b1; CommandsType b2; b1.command = "-node"; b1.value = "3"; blist.append(b1); b2.command = "-f"; b2.value = "7"; blist.append(b2); return blist; } //**************************************************************** CommandDecoderTest::CommandDecoderTest() { } //**************************************************************** CommandDecoderTest::~CommandDecoderTest() { } //**************************************************************** void CommandDecoderTest::normalOrderTestCase() { CommandDecoder temp; char* ptr_array[4]; char array[4][20] = {{0}}; strcpy(array[0], "-node"); strcpy(array[1], "3"); strcpy(array[2], "-f"); strcpy(array[3], "7"); for(int i = 0; i < 4; i++) { ptr_array[i] = array[i]; } QList c1 = temp.decoderString(4, ptr_array); auto c2 = createCorrectOrderOfCommand(); QCOMPARE(c1, c2); } //**************************************************************** void CommandDecoderTest::twoCommandOrderTestCase() { //-node 3 -g -f 11 -o filetext.txt CommandDecoder temp; char* ptr_array[7]; char array[7][20] = {{0}}; strcpy(array[0], "-node"); strcpy(array[1], "3"); strcpy(array[2], "-g"); strcpy(array[3], "-f"); strcpy(array[4], "11"); strcpy(array[5], "-o"); strcpy(array[6], "filetext.txt"); for(int i = 0; i < 7; i++) { ptr_array[i] = array[i]; } QList c1 = temp.decoderString(7, ptr_array); auto c2 = create2CommandSample(); QCOMPARE(c1, c2); } //**************************************************************** void CommandDecoderTest::morethanOneValueTestCase() { //-node 3 -g 15 16 -h 22 CommandDecoder temp; char* ptr_array[7]; char array[7][20] = {{0}}; strcpy(array[0], "-node"); strcpy(array[1], "3"); strcpy(array[2], "-g"); strcpy(array[3], "15"); strcpy(array[4], "11"); strcpy(array[5], "-h"); strcpy(array[6], "22"); for(int i = 0; i < 7; i++) { ptr_array[i] = array[i]; } try { QList c1 = temp.decoderString(7, ptr_array); QVERIFY(false); } catch(...) { QVERIFY(true); } }