Skip to content

Commit

Permalink
ad qr code test
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 15, 2024
1 parent 49c2026 commit 4561785
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom/benchmark/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ component {
, "member-cfml"
];
application.testSuite = [
"fileReadBinary"
"fileReadBinary",
"qrcode"
];
}

Expand Down
4 changes: 4 additions & 0 deletions custom/benchmark/tests/qrcode.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<cfscript>
generator = new res.qrcodes.QrCodeGenerator();
generator.generateQrCode( "hello world" );
</cfscript>
58 changes: 58 additions & 0 deletions custom/benchmark/tests/res/qrcodes/QrCodeGenerator.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Simple wrapper to Java library for generating QR Codes
*
* @autodoc
* @singleton
*
*/
component {

public any function init() {
_setupLibPath( );

return this;
}

// PUBLIC API
public binary function generateQrCode( required string input, numeric size=125, string imageType="gif" ) {
var qrCode = CreateObject( "java", "net.glxn.qrgen.javase.QRCode", _getLibPath() );
var binary = qrCode.from( arguments.input )
.to( _getImageTypeConstant( arguments.imageType ) )
.withSize( arguments.size, arguments.size )
.stream()
.toByteArray();
return binary;
}



// PRIVATE HELPERS
private void function _setupLibPath() {
var dir = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "/lib";
var jarFiles = DirectoryList( dir, true, "path" );

_setLibPath( jarFiles );
}

private string function _getImageTypeConstant( required string imageType ) {
var imageTypes = CreateObject( "java", "net.glxn.qrgen.core.image.ImageType", _getLibPath() );

switch( arguments.imageType ) {
case "jpg":
return imageTypes.JPG;
case "png":
return imageTypes.PNG;
default:
return imageTypes.GIF;
}
}

// ACCESSORS
private array function _getLibPath() {
return _libPath;
}
private void function _setLibPath( required array libPath ) {
_libPath = arguments.libPath;
}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4561785

Please sign in to comment.