PageRenderTime 23ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/lua/template_default_arg_runme.lua

#
Lua | 63 lines | 41 code | 15 blank | 7 comment | 19 complexity | 311acc30ec7610ec44e5d0101cd3c476 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. require("import") -- the import fn
  2. import("template_default_arg") -- import code
  3. --for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global
  4. helloInt = template_default_arg.Hello_int()
  5. helloInt:foo(template_default_arg.Hello_int_hi)
  6. x = template_default_arg.X_int()
  7. assert(x:meth(20.0, 200) == 200,"X_int test 1 failed")
  8. assert(x:meth(20) == 20,"X_int test 2 failed")
  9. assert(x:meth() == 0,"X_int test 3 failed")
  10. y = template_default_arg.Y_unsigned()
  11. assert(y:meth(20.0, 200) == 200,"Y_unsigned test 1 failed")
  12. assert(y:meth(20) == 20,"Y_unsigned test 2 failed")
  13. assert(y:meth() == 0,"Y_unsigned test 3 failed")
  14. x = template_default_arg.X_longlong()
  15. x = template_default_arg.X_longlong(20.0)
  16. x = template_default_arg.X_longlong(20.0, 200) -- note: long longs just treated as another number
  17. x = template_default_arg.X_int()
  18. x = template_default_arg.X_int(20.0)
  19. x = template_default_arg.X_int(20.0, 200)
  20. x = template_default_arg.X_hello_unsigned()
  21. x = template_default_arg.X_hello_unsigned(20.0)
  22. x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int())
  23. y = template_default_arg.Y_hello_unsigned()
  24. y:meth(20.0, template_default_arg.Hello_int())
  25. y:meth(template_default_arg.Hello_int())
  26. y:meth()
  27. fz = template_default_arg.Foo_Z_8()
  28. x = template_default_arg.X_Foo_Z_8()
  29. fzc = x:meth(fz)
  30. -- Templated functions
  31. -- plain function: int ott(Foo<int>)
  32. assert(template_default_arg.ott(template_default_arg.Foo_int()) == 30,"ott test 1 failed")
  33. -- %template(ott) ott<int, int>
  34. assert(template_default_arg.ott() == 10,"ott test 2 failed")
  35. assert(template_default_arg.ott(1) == 10,"ott test 3 failed")
  36. assert(template_default_arg.ott(1, 1) == 10,"ott test 4 failed")
  37. assert(template_default_arg.ott("hi") == 20,"ott test 5 failed")
  38. assert(template_default_arg.ott("hi", 1) == 20,"ott test 6 failed")
  39. assert(template_default_arg.ott("hi", 1, 1) == 20,"ott test 7 failed")
  40. -- %template(ott) ott<const char *>
  41. assert(template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") == 40,"ott test 8 failed")
  42. assert(template_default_arg.ottstring(template_default_arg.Hello_int()) == 40,"ott test 9 failed")
  43. -- %template(ott) ott<int>
  44. assert(template_default_arg.ottint(template_default_arg.Hello_int(), 1) == 50,"ott test 10 failed")
  45. assert(template_default_arg.ottint(template_default_arg.Hello_int()) == 50,"ott test 11 failed")
  46. -- %template(ott) ott<double>
  47. assert(template_default_arg.ott(template_default_arg.Hello_int(), 1.0) == 60,"ott test 12 failed")
  48. assert(template_default_arg.ott(template_default_arg.Hello_int()) == 60,"ott test 13 failed")