al_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package al
  2. import "testing"
  3. // import "fmt"
  4. // some parameters
  5. const expected_version = 83887873
  6. func TestGetAllegroVersion(t *testing.T) {
  7. version := GetAllegroVersion()
  8. if version != expected_version {
  9. t.Errorf("unexpected version of Allegro: %d in stead of %d!",
  10. version, expected_version)
  11. }
  12. }
  13. // Test system installation and deinstallation
  14. func TestSystemInstall(t *testing.T) {
  15. if(IsSystemInstalled()) {
  16. t.Errorf("System should not be installed before install\n")
  17. return
  18. }
  19. InstallSystem()
  20. if(!IsSystemInstalled()) {
  21. t.Errorf("System should be installed after install\n")
  22. return
  23. }
  24. UninstallSystem();
  25. if(IsSystemInstalled()) {
  26. t.Errorf("System should not be installed after uninstall\n")
  27. return
  28. }
  29. }
  30. // Test USTR
  31. func TestUSTR(t *testing.T) {
  32. s1 := "Hello no unicode!"
  33. s2 := "Hello µ unicode!"
  34. u1 := USTRV(s1)
  35. u2 := USTRV(s2)
  36. r1 := u1.String()
  37. r2 := u2.String()
  38. if(s1 != r1) {
  39. t.Errorf("USTR roundtrip failed: %s->%s", s1, r1)
  40. }
  41. if(s2 != r2) {
  42. t.Errorf("USTR roundtrip failed: %s->%s", s2, r2)
  43. }
  44. u1.Free() ; u1.Free() ; u1.Free() ;
  45. if(u1.String() != "<destroyed>") {
  46. t.Error("USTR.String() should return <destroyed> after Free()")
  47. }
  48. }
  49. // Test timer functions
  50. func TestGetTimeRest(t *testing.T) {
  51. InstallSystem()
  52. defer UninstallSystem()
  53. rest := 0.123
  54. t1 := GetTime()
  55. Rest(rest);
  56. t2 := GetTime();
  57. del := t2 - t1 - rest
  58. if (del > 0.001) || (del < -0.001) {
  59. t.Errorf("Rest/GetTime for %f not precise %f %f %f", rest, t1, t2, del)
  60. }
  61. }