Tests.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "IncludeAllTests.h"
  11. #include "RakString.h"
  12. #include "DS_List.h"
  13. #include "Gets.h"
  14. using namespace RakNet;
  15. /*
  16. The TestInterface used in this was made to be able to be flexible
  17. when adding new test cases. While I do not use the paramslist, it is available.
  18. */
  19. int main(int argc, char *argv[])
  20. {
  21. int returnVal;
  22. char str[512];
  23. int numTests=0;
  24. int testListSize=0;
  25. int passedTests=0;
  26. DataStructures::List <TestInterface*> testList;//Pointer list
  27. DataStructures::List <int> testResultList;//A list of pass and/or fail and the error codes
  28. DataStructures::List <RakString> testsToRun;//A list of tests to run
  29. DataStructures::List <int> testsToRunIndexes;//A list of tests to run by index
  30. //Add all the tests to the test list
  31. testList.Push(new EightPeerTest(),_FILE_AND_LINE_);
  32. testList.Push(new MaximumConnectTest(),_FILE_AND_LINE_);
  33. testList.Push(new PeerConnectDisconnectWithCancelPendingTest(),_FILE_AND_LINE_);
  34. testList.Push(new PeerConnectDisconnectTest(),_FILE_AND_LINE_);
  35. testList.Push(new ManyClientsOneServerBlockingTest(),_FILE_AND_LINE_);
  36. testList.Push(new ManyClientsOneServerNonBlockingTest(),_FILE_AND_LINE_);
  37. testList.Push(new ManyClientsOneServerDeallocateBlockingTest(),_FILE_AND_LINE_);
  38. testList.Push(new ReliableOrderedConvertedTest(),_FILE_AND_LINE_);
  39. testList.Push(new DroppedConnectionConvertTest(),_FILE_AND_LINE_);
  40. testList.Push(new ComprehensiveConvertTest(),_FILE_AND_LINE_);
  41. testList.Push(new CrossConnectionConvertTest(),_FILE_AND_LINE_);
  42. testList.Push(new PingTestsTest(),_FILE_AND_LINE_);
  43. testList.Push(new OfflineMessagesConvertTest(),_FILE_AND_LINE_);
  44. testList.Push(new LocalIsConnectedTest(),_FILE_AND_LINE_);
  45. testList.Push(new SecurityFunctionsTest(),_FILE_AND_LINE_);
  46. testList.Push(new ConnectWithSocketTest(),_FILE_AND_LINE_);
  47. testList.Push(new SystemAddressAndGuidTest(),_FILE_AND_LINE_);
  48. testList.Push(new PacketAndLowLevelTestsTest(),_FILE_AND_LINE_);
  49. testList.Push(new MiscellaneousTestsTest(),_FILE_AND_LINE_);
  50. testListSize=testList.Size();
  51. bool isVerbose=true;
  52. bool disallowTestToPause=false;
  53. DataStructures::List<RakString> testcases;
  54. if (argc>1)//we have command line arguments
  55. {
  56. for (int p=1;p<argc;p++)
  57. {
  58. testsToRun.Push(argv[p],_FILE_AND_LINE_);
  59. }
  60. }
  61. DataStructures::List<RakString> noParamsList;
  62. if (testsToRun.Size()==0&&testsToRunIndexes.Size()==0)
  63. {
  64. numTests=testListSize;
  65. for(int i=0;i<testListSize;i++)
  66. {
  67. printf("\n\nRunning test %s.\n\n",testList[i]->GetTestName().C_String());
  68. returnVal=testList[i]->RunTest(noParamsList,isVerbose,disallowTestToPause);
  69. testList[i]->DestroyPeers();
  70. if (returnVal==0)
  71. {passedTests++;}
  72. else
  73. {
  74. printf("Test %s returned with error %s",testList[i]->GetTestName().C_String(),testList[i]->ErrorCodeToString(returnVal).C_String());
  75. }
  76. }
  77. }
  78. if (testsToRun.Size()!=0)//If string arguments convert to indexes.Suggestion: if speed becoms an issue keep a sorted list and binary search it
  79. {
  80. int TestsToRunSize= testsToRun.Size();
  81. RakString testName;
  82. for(int i=0;i<TestsToRunSize;i++)
  83. {
  84. testName=testsToRun[i];
  85. for(int j=0;j<testListSize;j++)
  86. {
  87. if (testList[j]->GetTestName().StrICmp(testName)==0)
  88. {
  89. testsToRunIndexes.Push(j,_FILE_AND_LINE_);
  90. }
  91. }
  92. }
  93. }
  94. if (testsToRunIndexes.Size()!=0)//Run selected indexes
  95. {
  96. numTests=testsToRunIndexes.Size();
  97. for(int i=0;i<numTests;i++)
  98. {
  99. if (testsToRunIndexes[i]<testListSize)
  100. {
  101. printf("\n\nRunning test %s.\n\n",testList[testsToRunIndexes[i]]->GetTestName().C_String());
  102. returnVal=testList[testsToRunIndexes[i]]->RunTest(noParamsList,isVerbose,disallowTestToPause);
  103. testList[i]->DestroyPeers();
  104. if (returnVal==0)
  105. {passedTests++;}
  106. else
  107. {
  108. printf("Test %s returned with error %s",testList[testsToRunIndexes[i]]->GetTestName().C_String(),testList[testsToRunIndexes[i]]->ErrorCodeToString(returnVal).C_String());
  109. }
  110. }
  111. }
  112. }
  113. if (numTests>0)
  114. {
  115. printf("\nPassed %i out of %i tests.\n",passedTests,numTests);
  116. }
  117. printf("Press enter to continue \n");
  118. Gets(str, sizeof(str));
  119. //Cleanup
  120. int len=testList.Size();
  121. for (int i=0;i<len;i++)
  122. {
  123. delete testList[i];
  124. }
  125. testList.Clear(false,_FILE_AND_LINE_);
  126. return 0;
  127. }
粤ICP备19079148号