enumerator-type.py 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Copyright (c) Contributors to the Open 3D Engine Project.
  5. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. SPDX-License-Identifier: Apache-2.0 OR MIT
  7. """
  8. import sys
  9. import os
  10. from clr import *
  11. sys.path.append("..")
  12. import testfuncs
  13. def CheckSymbol(table, sym, field, value):
  14. if not table[sym]['type']['core'][field] == value:
  15. print (fg.RED+ sym + " must be of type "+ value + style.RESET_ALL)
  16. return False
  17. return True
  18. def execTest(thefile, compilerPath, silent):
  19. '''return number of successes'''
  20. symbols, ok = testfuncs.buildAndGetSymbols(thefile, compilerPath, silent)
  21. if not ok:
  22. print (fg.RED+ "Couldn't get meaningful symbols table"+ style.RESET_ALL)
  23. return 0
  24. if not symbols["Symbol '/Monday'"]['type']['core']['name'] == '/Weekday':
  25. ok = False
  26. print (fg.RED+ "Symbol /Monday must be of type '/Weekday'"+ style.RESET_ALL)
  27. if not symbols["Symbol '/Monday'"]['type']['core']['underlying_scalar'] == '<NA>':
  28. ok = False
  29. print (fg.RED+ "Symbol /Monday must have underlying_scalar of type '<NA>'"+ style.RESET_ALL)
  30. ok = ok and CheckSymbol(symbols, "Symbol '/Monday'", 'name', '/Weekday')
  31. ok = ok and CheckSymbol(symbols, "Symbol '/Monday'", 'underlying_scalar', '<NA>')
  32. ok = ok and CheckSymbol(symbols, "Symbol '/Tuesday'", 'name', '/Weekday')
  33. ok = ok and CheckSymbol(symbols, "Symbol '/Tuesday'", 'underlying_scalar', '<NA>')
  34. ok = ok and CheckSymbol(symbols, "Symbol '/Wednesday'", 'name', '/Weekday')
  35. ok = ok and CheckSymbol(symbols, "Symbol '/Wednesday'", 'underlying_scalar', '<NA>')
  36. ok = ok and CheckSymbol(symbols, "Symbol '/Thursday'", 'name', '/Weekday')
  37. ok = ok and CheckSymbol(symbols, "Symbol '/Thursday'", 'underlying_scalar', '<NA>')
  38. ok = ok and CheckSymbol(symbols, "Symbol '/Friday'", 'name', '/Weekday')
  39. ok = ok and CheckSymbol(symbols, "Symbol '/Friday'", 'underlying_scalar', '<NA>')
  40. ok = ok and CheckSymbol(symbols, "Symbol '/Saturday'", 'name', '/Weekday')
  41. ok = ok and CheckSymbol(symbols, "Symbol '/Saturday'", 'underlying_scalar', '<NA>')
  42. ok = ok and CheckSymbol(symbols, "Symbol '/Sunday'", 'name', '/Weekday')
  43. ok = ok and CheckSymbol(symbols, "Symbol '/Sunday'", 'underlying_scalar', '<NA>')
  44. ok = ok and CheckSymbol(symbols, "Symbol '/FavouriteDay'", 'name', '/Weekday')
  45. ok = ok and CheckSymbol(symbols, "Symbol '/FavouriteDay'", 'underlying_scalar', '<NA>')
  46. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Spring'", 'name', '/Season')
  47. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Spring'", 'underlying_scalar', '<NA>')
  48. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Summer'", 'name', '/Season')
  49. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Summer'", 'underlying_scalar', '<NA>')
  50. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Autumn'", 'name', '/Season')
  51. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Autumn'", 'underlying_scalar', '<NA>')
  52. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Winter'", 'name', '/Season')
  53. ok = ok and CheckSymbol(symbols, "Symbol '/Season/Winter'", 'underlying_scalar', '<NA>')
  54. ok = ok and CheckSymbol(symbols, "Symbol '/IsComing'", 'name', '/Season')
  55. ok = ok and CheckSymbol(symbols, "Symbol '/IsComing'", 'underlying_scalar', '<NA>')
  56. return ok
  57. result = 0 # to define for sub-tests
  58. resultFailed = 0
  59. def doTests(compiler, silent, azdxcpath):
  60. global result
  61. global resultFailed
  62. # Working directory should have been set to this script's directory by the calling parent
  63. # You can get it once doTests() is called, but not during initialization of the module,
  64. # because at that time it will still be set to the working directory of the calling script
  65. workDir = os.getcwd()
  66. if execTest(os.path.join(workDir, "../Samples/Enumeration.azsl"), compiler, silent): result += 1
  67. else: resultFailed += 1
  68. if __name__ == "__main__":
  69. print ("please call from testapp.py")