testlogger.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. .pragma library
  5. var testResults = null;
  6. function log_init_results()
  7. {
  8. if (!testResults) {
  9. testResults = {
  10. runningTest: -1,
  11. nextId: 0,
  12. testCases: []
  13. }
  14. }
  15. }
  16. function log_register_test(name)
  17. {
  18. log_init_results()
  19. var testId = testResults.nextId++
  20. testResults.testCases.push(testId)
  21. return testId
  22. }
  23. function log_optional_test(testId)
  24. {
  25. log_init_results()
  26. var index = testResults.testCases.indexOf(testId)
  27. if (index >= 0)
  28. testResults.testCases.splice(index, 1)
  29. }
  30. function log_mandatory_test(testId)
  31. {
  32. log_init_results()
  33. var index = testResults.testCases.indexOf(testId)
  34. if (index === -1)
  35. testResults.testCases.push(testId)
  36. }
  37. function log_can_start_test(testId)
  38. {
  39. return !testResults || testResults.runningTest === -1 || testResults.runningTest === testId;
  40. }
  41. function log_start_test(testId)
  42. {
  43. log_init_results()
  44. if (testResults.runningTest === testId)
  45. return false
  46. testResults.runningTest = testId
  47. return true
  48. }
  49. function log_complete_test(testId)
  50. {
  51. var index = testResults.testCases.indexOf(testId)
  52. if (index >= 0)
  53. testResults.testCases.splice(index, 1)
  54. testResults.runningTest = -1
  55. return testResults.testCases.length > 0
  56. }