zipalign_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package tests
  2. import (
  3. "bytes"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "notabug.org/Umnik/GoAndroidSDK/v2/components/sdk/buildTools/zipalign"
  8. )
  9. func newZipalign(t *testing.T) *zipalign.Zipalign {
  10. t.Helper()
  11. za, err := zipalign.NewZipalignLastVersion(*newSdk(t, t.Name()))
  12. if !testErr(t, t.Name(), err) {
  13. return nil
  14. }
  15. return za
  16. }
  17. func TestCheckAligment(t *testing.T) {
  18. t.Parallel()
  19. za := newZipalign(t)
  20. out, err := za.CheckAlign(goodApkFile, "4", true, true)
  21. if !testErr(t, t.Name(), err) {
  22. return
  23. }
  24. for _, line := range bytes.Split(out, []byte("/n")) {
  25. if bytes.Contains(line, []byte("Verifying alignment of")) ||
  26. bytes.Contains(line, []byte("(OK")) ||
  27. bytes.Contains(line, []byte("Verification succesful")) {
  28. t.Logf("%s", line)
  29. } else {
  30. t.Errorf("Zipalign failed: %s", line)
  31. }
  32. }
  33. }
  34. func TestDoAligment(t *testing.T) {
  35. t.Parallel()
  36. za := newZipalign(t)
  37. gfTmp, err := os.CreateTemp("", "zipalign-*") // чтобы не повредить тестовый файл
  38. if !testErr(t, t.Name(), err) {
  39. return
  40. }
  41. defer removeOsFile(t, t.Name(), gfTmp.Name())
  42. if !makeCopy(t, t.Name(), gfTmp, goodApkFile) {
  43. return
  44. }
  45. outFile := filepath.Join(os.TempDir(), "out.apk")
  46. defer removeOsFile(t, t.Name(), outFile)
  47. out, err := za.DoAlign(gfTmp.Name(), outFile, "4", false, true, true)
  48. if !testErr(t, t.Name(), err) {
  49. return
  50. }
  51. if !bytes.Contains(out, []byte("Verification succesful")) {
  52. t.Errorf("Aligment fails with: %s", out)
  53. }
  54. }