test-exif.js 962 B

1234567891011121314151617181920212223242526
  1. var testCase = require('nodeunit').testCase;
  2. var exif = require('../lib/exif.js');
  3. var BufferStream = require('../lib/bufferstream.js');
  4. var buf = require('fs').readFileSync(__dirname + '/starfish.jpg');
  5. module.exports = testCase({
  6. "test parseTags": function(test) {
  7. var expectedTags = require('./expected-exif-tags.json');
  8. var index = 0;
  9. exif.parseTags(new BufferStream(buf, 24, 23960), function(ifdSection, tagType, value, format) {
  10. var t = expectedTags[index];
  11. test.strictEqual(t.ifdSection, ifdSection);
  12. test.strictEqual(t.tagType, tagType);
  13. test.strictEqual(t.format, format);
  14. if(typeof t.value === 'string' && t.value.indexOf('b:') === 0) {
  15. test.ok(Buffer.isBuffer(value));
  16. test.strictEqual(parseInt(t.value.substr(2), 10), value.length);
  17. } else {
  18. test.deepEqual(t.value, value);
  19. }
  20. ++index;
  21. });
  22. test.strictEqual(index, expectedTags.length, 'all tags should be passed to the iterator');
  23. test.done();
  24. }
  25. });