TestResource.hx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package unit;
  2. class TestResource extends Test {
  3. static var STR = "Héllo World !";
  4. function testResources() {
  5. var names = haxe.Resource.listNames();
  6. eq( names.length, 2 );
  7. if( names[0] == "res1.txt" )
  8. eq( names[1], "res2.bin" );
  9. else {
  10. eq( names[0], "res2.bin" );
  11. eq( names[1], "res1.txt" );
  12. }
  13. eq( haxe.Resource.getString("res1.txt"), STR );
  14. #if (neko || php)
  15. // allow binary strings
  16. eq( haxe.Resource.getBytes("res2.bin").sub(0,9).toString(), "MZ\x90\x00\x03\x00\x00\x00\x04" );
  17. #else
  18. // cut until first \0
  19. eq( haxe.Resource.getString("res2.bin").substr(0,2), "MZ" );
  20. #end
  21. eq( haxe.Resource.getBytes("res1.txt").compare(haxe.io.Bytes.ofString(STR)), 0 );
  22. var b = haxe.Resource.getBytes("res2.bin");
  23. var firsts = [0x4D,0x5A,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xB8];
  24. var lasts = [0xD6,0x52,0x03,0x1A,0x2C,0x4E,0x45,0x4B,0x4F,0x00,0x1C,0x00,0x00];
  25. for( i in 0...firsts.length )
  26. eq( b.get(i), firsts[i]);
  27. for( i in 0...lasts.length )
  28. eq( b.get(b.length - lasts.length + i), lasts[i] );
  29. }
  30. #if neko
  31. static function main() {
  32. var ch = sys.io.File.write("res1.txt",true);
  33. ch.writeString(STR);
  34. ch.close();
  35. var ch = sys.io.File.write("res2.bin",true);
  36. ch.writeString("Héllo");
  37. ch.writeByte(0);
  38. ch.writeString("World");
  39. ch.writeInt32(0);
  40. ch.writeString("!");
  41. ch.close();
  42. }
  43. #end
  44. }