@@ -56,6 +56,32 @@ suite('Validation of input params', function () {
56
56
) ;
57
57
} ) ;
58
58
59
+ test ( 'mode' , function ( ) {
60
+ assert . throws (
61
+ function ( ) {
62
+ qrc . encode ( 'TEST' , { mode : qrc . MODE_NUM - 1 } ) ;
63
+ } ,
64
+ / M o d e o u t o f r a n g e /
65
+ ) ;
66
+ assert . throws (
67
+ function ( ) {
68
+ qrc . encode ( 'TEST' , { mode : qrc . MODE_KANJI + 1 } ) ;
69
+ } ,
70
+ / M o d e o u t o f r a n g e /
71
+ ) ;
72
+ assert . throws (
73
+ function ( ) {
74
+ qrc . encode ( 'TEST' , { mode : qrc . MODE_NUM + 0.5 } ) ;
75
+ } ,
76
+ / W r o n g t y p e f o r m o d e /
77
+ ) ;
78
+ assert . doesNotThrow (
79
+ function ( ) {
80
+ qrc . encode ( 'TEST' , { mode : qrc . MODE_AN } ) ;
81
+ }
82
+ ) ;
83
+ } ) ;
84
+
59
85
test ( 'dot size' , function ( ) {
60
86
assert . throws (
61
87
function ( ) {
@@ -219,6 +245,35 @@ suite('Encode to buffer', function () {
219
245
'dc645b387c5c8189bde0606ef5c6d85880d67fbc' ) ;
220
246
} ) ;
221
247
248
+ test ( 'explicitly set mode(NUM)' , function ( ) {
249
+ var act = qrc . encode ( '1234' , { mode : qrc . MODE_NUM } ) ;
250
+ var hash = crypto . createHash ( 'sha1' ) ;
251
+ assert . strictEqual ( act . version , 1 ) ;
252
+ assert . strictEqual ( act . width , 21 ) ;
253
+ hash . update ( act . data ) ;
254
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
255
+ '3bbb8a9bfa4ba87aa5ed47d95ec4e36b53180498' ) ;
256
+ } ) ;
257
+
258
+ test ( 'explicitly set mode(AN)' , function ( ) {
259
+ var act = qrc . encode ( 'FOO1234' , { mode : qrc . MODE_AN } ) ;
260
+ var hash = crypto . createHash ( 'sha1' ) ;
261
+ assert . strictEqual ( act . version , 1 ) ;
262
+ assert . strictEqual ( act . width , 21 ) ;
263
+ hash . update ( act . data ) ;
264
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
265
+ 'cc92bdbf848fa1a98bf9e22100495ab06f809387' ) ;
266
+ } ) ;
267
+
268
+ test ( 'explicitly set mode(8)' , function ( ) {
269
+ var act = qrc . encode ( 'FOO1234' , { mode : qrc . MODE_8 } ) ;
270
+ var hash = crypto . createHash ( 'sha1' ) ;
271
+ assert . strictEqual ( act . version , 1 ) ;
272
+ assert . strictEqual ( act . width , 21 ) ;
273
+ hash . update ( act . data ) ;
274
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
275
+ '04ad4388c4dbc311d667d41200f4c4fae441c30f' ) ;
276
+ } ) ;
222
277
} ) ;
223
278
224
279
suite ( 'Encode to PNG buffer' , function ( ) {
@@ -282,6 +337,36 @@ suite('Encode to PNG buffer', function () {
282
337
'907541542df208453ad40e357fa7d9ed98d208ae' ) ;
283
338
} ) ;
284
339
340
+ test ( 'explicitly set mode(NUM)' , function ( ) {
341
+ var act = qrc . encodePng ( '1234' , { mode : qrc . MODE_NUM } ) ;
342
+ var hash = crypto . createHash ( 'sha1' ) ;
343
+ assert . strictEqual ( act . version , 1 ) ;
344
+ assert . strictEqual ( act . width , 21 ) ;
345
+ hash . update ( act . data ) ;
346
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
347
+ '5e2862515472cf8a98b1432d5a2da9ae82ce6d9c' ) ;
348
+ } ) ;
349
+
350
+ test ( 'explicitly set mode(AN)' , function ( ) {
351
+ var act = qrc . encodePng ( 'FOO1234' , { mode : qrc . MODE_AN } ) ;
352
+ var hash = crypto . createHash ( 'sha1' ) ;
353
+ assert . strictEqual ( act . version , 1 ) ;
354
+ assert . strictEqual ( act . width , 21 ) ;
355
+ hash . update ( act . data ) ;
356
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
357
+ '07f6ebca2afc5b5c63b08bbc4f23cf2763465dac' ) ;
358
+ } ) ;
359
+
360
+ test ( 'explicitly set mode(8)' , function ( ) {
361
+ var act = qrc . encodePng ( 'FOO1234' , { mode : qrc . MODE_8 } ) ;
362
+ var hash = crypto . createHash ( 'sha1' ) ;
363
+ assert . strictEqual ( act . version , 1 ) ;
364
+ assert . strictEqual ( act . width , 21 ) ;
365
+ hash . update ( act . data ) ;
366
+ assert . strictEqual ( hash . digest ( 'hex' ) ,
367
+ '964df950b5b50d7d7fef91bed7f9f5fa7c9d5906' ) ;
368
+ } ) ;
369
+
285
370
test ( 'explicitly set dot size' , function ( ) {
286
371
var act = qrc . encodePng ( 'TEST' , { dotSize : 10 } ) ;
287
372
var hash = crypto . createHash ( 'sha1' ) ;
0 commit comments