tool.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }
  47. func split_base() string {
  48. return "base_split.apk"
  49. }