tool.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package tests
  2. import (
  3. "archive/zip"
  4. "io"
  5. "os"
  6. "testing"
  7. "notabug.org/Umnik/GoAndroidSDK/v2/components/sdk"
  8. )
  9. func newSdk(t *testing.T, fnName string) *sdk.SDK {
  10. s, err := sdk.NewSDK()
  11. if !testErr(t, fnName, err) {
  12. return nil
  13. }
  14. return s
  15. }
  16. func closeOsFile(t *testing.T, fnName string, closer *os.File) {
  17. t.Helper()
  18. testErr(t, fnName, closer.Close())
  19. }
  20. func closeZipFile(t *testing.T, fnName string, closer *zip.ReadCloser) {
  21. t.Helper()
  22. testErr(t, fnName, closer.Close())
  23. }
  24. func removeOsFile(t *testing.T, fnName string, fileName string) {
  25. testErr(t, fnName, os.Remove(fileName))
  26. }
  27. func makeCopy(t *testing.T, fnName string, dest io.Writer, source string) bool {
  28. t.Helper()
  29. src, err := os.Open(source)
  30. if !testErr(t, fnName, err) {
  31. return false
  32. }
  33. defer closeOsFile(t, fnName, src)
  34. _, err = io.Copy(dest, src)
  35. return testErr(t, fnName, err)
  36. }
  37. func testErr(t *testing.T, funcName string, err error) bool {
  38. if err != nil {
  39. t.Errorf("%v failed with: %q", funcName, err)
  40. return false
  41. }
  42. return true
  43. }
  44. func goodApkFile() string {
  45. return "saveto.apk"
  46. }