al_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package al
  2. import "testing"
  3. import "runtime"
  4. // import "fmt"
  5. // some parameters
  6. const expected_version = 83887873
  7. func TestGetAllegroVersion(t *testing.T) {
  8. version := GetAllegroVersion()
  9. if version != expected_version {
  10. t.Errorf("unexpected version of Allegro: %d in stead of %d!",
  11. version, expected_version)
  12. }
  13. }
  14. // Test system installation and deinstallation
  15. func TestSystemInstall(t *testing.T) {
  16. if IsSystemInstalled() {
  17. t.Errorf("System should not be installed before install\n")
  18. return
  19. }
  20. InstallSystem()
  21. if !IsSystemInstalled() {
  22. t.Errorf("System should be installed after install\n")
  23. return
  24. }
  25. UninstallSystem()
  26. if IsSystemInstalled() {
  27. t.Errorf("System should not be installed after uninstall\n")
  28. return
  29. }
  30. }
  31. // Test USTR
  32. func TestUSTR(t *testing.T) {
  33. s1 := "Hello no unicode!"
  34. s2 := "Hello µ unicode!"
  35. u1 := USTRV(s1)
  36. u2 := USTRV(s2)
  37. r1 := u1.String()
  38. r2 := u2.String()
  39. if s1 != r1 {
  40. t.Errorf("USTR roundtrip failed: %s->%s", s1, r1)
  41. }
  42. if s2 != r2 {
  43. t.Errorf("USTR roundtrip failed: %s->%s", s2, r2)
  44. }
  45. u1.Free()
  46. u1.Free()
  47. u1.Free()
  48. if u1.String() != "<destroyed>" {
  49. t.Error("USTR.String() should return <destroyed> after Free()")
  50. }
  51. }
  52. // Test timer functions
  53. func TestGetTimeRest(t *testing.T) {
  54. InstallSystem()
  55. defer UninstallSystem()
  56. rest := 0.123
  57. t1 := GetTime()
  58. Rest(rest)
  59. t2 := GetTime()
  60. del := t2 - t1 - rest
  61. if (del > 0.001) || (del < -0.001) {
  62. t.Errorf("Rest/GetTime for %f not precise %f %f %f", rest, t1, t2, del)
  63. }
  64. }
  65. // Test path functions
  66. func TestPath(t *testing.T) {
  67. InstallSystem()
  68. defer UninstallSystem()
  69. path := GetStandardPath(TEMP_PATH)
  70. str := path.String()
  71. tmp := "/tmp/"
  72. // special case for windows...
  73. if runtime.GOOS == "windows" {
  74. tmp = `C:\TMP\`
  75. }
  76. if str != tmp {
  77. t.Errorf("GetStandardPath(TEMP_PATH) is not %s but %s", tmp, str)
  78. }
  79. }
  80. // Test screen saver inhibition.
  81. func TestInhibitScreensaver(t *testing.T) {
  82. InstallSystem()
  83. defer UninstallSystem()
  84. ok := InhibitScreensaver(true)
  85. if !ok {
  86. t.Errorf("InhibitScreensaver failed: %v", ok)
  87. }
  88. }