test_proj.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import os
  2. import infra.basetest
  3. class TestProj(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_PROJ=y
  7. BR2_PACKAGE_PROJ_APPS=y
  8. BR2_TARGET_ROOTFS_CPIO=y
  9. # BR2_TARGET_ROOTFS_TAR is not set
  10. """
  11. def test_run(self):
  12. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  13. self.emulator.boot(arch="armv5",
  14. kernel="builtin",
  15. options=["-initrd", cpio_file])
  16. self.emulator.login()
  17. # We check the program can run. The "proj" command does not
  18. # have a "--version" option. It will just show its version
  19. # when invoked without any argument.
  20. self.assertRunOk("proj")
  21. # The commands in this tests are taken from the Proj
  22. # documentation quickstart page, at:
  23. # https://proj.org/en/9.5/usage/quickstart.html
  24. proj_str = "+proj=merc +lat_ts=56.5 +ellps=GRS80"
  25. cmd = "echo 55.2 12.2"
  26. cmd += f" | proj {proj_str}"
  27. out, ret = self.emulator.run(cmd)
  28. self.assertEqual(ret, 0)
  29. expected_values = [3399483.80, 752085.60]
  30. values = list(map(lambda x: float(x), out[0].split()))
  31. for i in range(len(expected_values)):
  32. self.assertAlmostEqual(values[i], expected_values[i])
  33. proj_str = "+proj=merc +lat_ts=56.5 +ellps=GRS80 +to +proj=utm +zone=32"
  34. cmd = "echo 3399483.80 752085.60"
  35. cmd += f" | cs2cs {proj_str}"
  36. out, ret = self.emulator.run(cmd)
  37. self.assertEqual(ret, 0)
  38. expected_values = [6103992.36, 1924052.47, 0.00]
  39. values = list(map(lambda x: float(x), out[0].split()))
  40. for i in range(len(expected_values)):
  41. self.assertAlmostEqual(values[i], expected_values[i])
  42. proj_str = "+init=epsg:4326 +to +init=epsg:25832"
  43. cmd = "echo 56 12"
  44. cmd += f" | cs2cs {proj_str}"
  45. out, ret = self.emulator.run(cmd)
  46. self.assertEqual(ret, 0)
  47. expected_values = [6231950.54, 1920310.71, 0.00]
  48. values = list(map(lambda x: float(x), out[0].split()))
  49. for i in range(len(expected_values)):
  50. self.assertAlmostEqual(values[i], expected_values[i])