MES手机端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

46 righe
1.8 KiB

  1. var testCase = require('nodeunit').testCase;
  2. var jpeg = require('../lib/jpeg.js');
  3. var BufferStream = require('../lib/bufferstream.js');
  4. var buf = require('fs').readFileSync(__dirname + '/test.jpg');
  5. module.exports = testCase({
  6. "test parseSections": function(test) {
  7. var expectedSections = [
  8. { type: 216, offset: 2, len: 0 },
  9. { type: 224, offset: 6, len: 14 },
  10. { type: 226, offset: 24, len: 3158 },
  11. { type: 225, offset: 3186, len: 200 },
  12. { type: 225, offset: 3390, len: 374 },
  13. { type: 219, offset: 3768, len: 65 },
  14. { type: 219, offset: 3837, len: 65 },
  15. { type: 192, offset: 3906, len: 15 },
  16. { type: 196, offset: 3925, len: 29 },
  17. { type: 196, offset: 3958, len: 179 },
  18. { type: 196, offset: 4141, len: 29 },
  19. { type: 196, offset: 4174, len: 179 },
  20. { type: 218, offset: 4355, len: 0 }
  21. ];
  22. var index = 0;
  23. var jpegStream = new BufferStream(buf), start = jpegStream.mark();
  24. jpeg.parseSections(jpegStream, function(type, sectionStream) {
  25. test.strictEqual(type, expectedSections[index].type);
  26. test.strictEqual(sectionStream.offsetFrom(start), expectedSections[index].offset);
  27. test.strictEqual(sectionStream.remainingLength(), expectedSections[index].len);
  28. ++index;
  29. });
  30. test.strictEqual(index, expectedSections.length, 'all sections should be passed to the iterator');
  31. test.done();
  32. },
  33. "test getSizeFromSOFSection": function(test) {
  34. var size = jpeg.getSizeFromSOFSection(new BufferStream(buf, 3906, 15, true));
  35. test.strictEqual(size.width, 2);
  36. test.strictEqual(size.height, 1);
  37. test.done();
  38. },
  39. "test getSectionName": function(test) {
  40. test.deepEqual({name: 'SOI'}, jpeg.getSectionName(0xD8));
  41. test.deepEqual({name: 'APP', index: 15}, jpeg.getSectionName(0xEF));
  42. test.deepEqual({name: 'DHT'}, jpeg.getSectionName(0xC4));
  43. test.done();
  44. }
  45. });