()
| 39 | } |
| 40 | |
| 41 | AssetsTest() { |
| 42 | if (!OSPRuntime.isJS) { |
| 43 | System.out.println("Assets are JavaScript only now."); |
| 44 | System.exit(0); |
| 45 | } |
| 46 | // test that an image that is NOT in the zip file can be loaded directly. |
| 47 | String imageName = "org/opensourcephysics/resources/cover.gif"; |
| 48 | URL url = Assets.getURLFromPath(imageName, true); |
| 49 | if (url == null) { |
| 50 | OSPLog.debug(imageName + " was not found in an asset ZIP file"); |
| 51 | url = Assets.getURLFromPath(imageName, false); |
| 52 | } |
| 53 | System.out.println("url=" + url); |
| 54 | if (url != null) { |
| 55 | ImageIcon icon = new ImageIcon(url); |
| 56 | JFrame frame = new JFrame("Asset Loader Example"); |
| 57 | IconPanel imagePanel = new IconPanel(icon); |
| 58 | imagePanel.setLayout(new BorderLayout()); |
| 59 | frame.add(imagePanel); |
| 60 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 61 | frame.setSize(400, 400); |
| 62 | frame.setVisible(true); |
| 63 | } |
| 64 | |
| 65 | // Test that we can get the ZipEntry list. |
| 66 | getFileList("osp-assets.zip"); |
| 67 | |
| 68 | // Test that we can get the bytes for cover.gif, which is not in the zip file |
| 69 | byte[] bytes = Assets.getURLContents(url); |
| 70 | |
| 71 | String magic = new String(new byte[] { bytes[0], bytes[1], bytes[2], bytes[3] }); |
| 72 | OSPLog.debug("\n\n" + magic + " " + bytes.length); |
| 73 | |
| 74 | // Test that we can get the bytes for a file that is NOT in the zip file |
| 75 | bytes = Assets.getAssetBytes(imageName); |
| 76 | assert(bytes.length == 30189); |
| 77 | |
| 78 | // Test that we can get the bytes for a file that is in the zip file |
| 79 | bytes = Assets.getAssetBytes("org/opensourcephysics/resources/display/drawing_tools.xml"); |
| 80 | assert(bytes.length == 964); |
| 81 | |
| 82 | // test with file name space |
| 83 | url = Assets.getURLFromPath("test/spacetest.zip!/Car in a loop with friction.trk"); |
| 84 | bytes = Assets.getURLContents(url); |
| 85 | assert(bytes.length == 50356); |
| 86 | |
| 87 | // // test remote access - NO CORS at St. Olaf. |
| 88 | // url = Assets.getURLFromPath("https://chemapps.stolaf.edu/swingjs/test/spacetest.zip");//!/Car in a loop with friction.trk"); |
| 89 | // bytes = Assets.getURLContents(url); |
| 90 | // assert(bytes.length == 655915); |
| 91 | // |
| 92 | // // test remote access- DOES NOT WORK WITH QUERY in Java. |
| 93 | // url = Assets.getURLFromPath("https://www.compadre.org/osp/document/ServeFile.cfm?ID=15022&DocID=5059&Attachment=1!/Car in a loop with friction.trk"); |
| 94 | // bytes = Assets.getURLContents(url); |
| 95 | // assert(bytes.length == 50356); |
| 96 | |
| 97 | System.out.println("AssetsTest OK"); |
| 98 | } |
nothing calls this directly
no test coverage detected