diff --git a/.gitignore b/.gitignore index 4a00489..6057b24 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __dummy.html *.o *.obj libexempi-d.a +__test__unittest__ diff --git a/dub.sdl b/dub.sdl index 6e932cc..49096da 100644 --- a/dub.sdl +++ b/dub.sdl @@ -3,3 +3,14 @@ description "D bindings for exempi" authors "Les De Ridder" license "BSD 3-clause" targetType "library" +libs "exempi" + +configuration "library" { + sourcePaths "source" + importPaths "source" +} + +configuration "unittest" { + sourcePaths "tests" + importPaths "source" "tests" +} diff --git a/tests/init.d b/tests/init.d new file mode 100644 index 0000000..b051097 --- /dev/null +++ b/tests/init.d @@ -0,0 +1,65 @@ +/* + * exempi-d - tests/init.d + * + * Bindings by Les De Ridder + * + * Copyright (C) 2007-2016 Hubert Figuiere + * Copyright 2002-2007 Adobe Systems Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1 Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2 Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * 3 Neither the name of the Authors, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software wit hout specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +unittest +{ + import exempi.xmp; + + import std.file; + auto file = read("tests/samples/test1.xmp"); + auto len = file.length; + auto buffer = cast(const char*)file.ptr; + + assert(xmp_init()); + assert(xmp_init()); + + XmpPtr xmp = xmp_new_empty(); + assert(xmp_parse(xmp, buffer, len)); + assert(xmp !is null); + assert(xmp_free(xmp)); + + xmp_terminate(); + + xmp = xmp_new_empty(); + assert(xmp_parse(xmp, buffer, len)); + assert(xmp !is null); + assert(xmp_free(xmp)); + + xmp_terminate(); +} diff --git a/tests/samples/BlueSquare.jpg b/tests/samples/BlueSquare.jpg new file mode 100644 index 0000000..81b8a22 Binary files /dev/null and b/tests/samples/BlueSquare.jpg differ diff --git a/tests/samples/test1.xmp b/tests/samples/test1.xmp new file mode 100644 index 0000000..281f936 --- /dev/null +++ b/tests/samples/test1.xmp @@ -0,0 +1,255 @@ + + + + Canon + Canon EOS 20D + 1 + 3504 + 2336 + + + 0221 + 15/1 + -3906891/1000000 + 8/1 + 6/1 + 1 + 2006-12-07T23:20:43-05:00 + 2006-12-07T23:20:43-05:00 + 0/2 + 3625/1000 + 5 + 32/1 + 0 + 1 + 0 + 0 + 3504000/885 + 2336000/590 + 2 + + + 100 + + + + False + 0 + 2 + False + False + + + + 2006-12-07T23:20:43-05:00 + 3 + + + + + unknown + + + + + 2006, Hubert Figuiere + + + + + night + ontario + ottawa + parliament of canada + + + + + 420103070 + 24/1 85/1 0/0 0/0 + 24.0-85.0 mm + 176 + -2/1 + unknown + 1.1.0 + + + False + As Shot + 0.00 + 5 + +50 + +25 + 0 + 25 + 0 + 25 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 25 + 50 + 75 + +1.0 + 25 + 0 + False + Medium Contrast + + + 0, 0 + 32, 22 + 64, 56 + 128, 128 + 192, 196 + 255, 255 + + + + + false + 0 + 25 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 50 + 75 + 25 + 25 + As Shot + 0 + 0 + 0 + 100 + 0 + 0 + 71 + 0 + 25 + 0 + 5 + 0 + 50 + 0 + 0 + 0 + 29 + false + false + false + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + false + 1 + 0 + 0 + 0 + 0 + 29 + 0 + 0 + 0 + 71 + 50 + 0 + false + 0 + 0 + true + 0 + 0 + 1 + 4350 + + + aGllcmFyY2hpY2FsS2V5d29yZHMgPSB7Cgl7CgkJZmxhdCA9IHsKCQkJIm5pZ2h0IiwKCQl9LAoJCXBhdGggPSB7CgkJCSJuaWdodCIsCgkJfSwKCQlwcmltYXJ5ID0gIm5pZ2h0IiwKCQl1dWlkID0gIkU1RDEwQTFELTU3QUYtMTFEQi04RTMzLTAwMEQ5MzVDODY5QSIsCgl9LAoJewoJCWZsYXQgPSB7CgkJCSJvbnRhcmlvIiwKCQkJIm90dGF3YSIsCgkJfSwKCQlwYXRoID0gewoJCQkib250YXJpbyIsCgkJCSJvdHRhd2EiLAoJCX0sCgkJcHJpbWFyeSA9ICJvdHRhd2EiLAoJCXV1aWQgPSAiQjgzMTc4RkItNTdBRi0xMURCLThFMzMtMDAwRDkzNUM4NjlBIiwKCX0sCgl7CgkJZmxhdCA9IHsKCQkJInBhcmxpYW1lbnQgb2YgY2FuYWRhIiwKCQkJIm9udGFyaW8iLAoJCQkib3R0YXdhIiwKCQl9LAoJCXBhdGggPSB7CgkJCSJvbnRhcmlvIiwKCQkJIm90dGF3YSIsCgkJCSJwYXJsaWFtZW50IG9mIGNhbmFkYSIsCgkJfSwKCQlwcmltYXJ5ID0gInBhcmxpYW1lbnQgb2YgY2FuYWRhIiwKCQl1dWlkID0gIkU1RDMzMEZDLTU3QUYtMTFEQi04RTMzLTAwMEQ5MzVDODY5QSIsCgl9LAp9Cg== + + + + + 4 + 3 + inches + + + + + Parliament Hill, Ottawa, Ontario, Canada + + + diff --git a/tests/xmpfiles.d b/tests/xmpfiles.d new file mode 100644 index 0000000..45f1859 --- /dev/null +++ b/tests/xmpfiles.d @@ -0,0 +1,115 @@ +/* + * exempi-d - tests/xmpfiles.d + * + * Bindings by Les De Ridder + * + * Copyright (C) 2007-2016 Hubert Figuiere + * Copyright 2002-2007 Adobe Systems Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1 Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2 Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * 3 Neither the name of the Authors, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software wit hout specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +unittest +{ + import exempi.xmp; + import exempi.xmpconsts; + + import std.string; + + enum sampleFile = "tests/samples/BlueSquare.jpg"; + + assert(xmp_init()); + + XmpFilePtr f = xmp_files_open_new(sampleFile.toStringz(), XmpOpenFileOptions.XMP_OPEN_READ); + + assert(f !is null); + + assert(xmp_files_check_file_format(sampleFile.toStringz()) == XmpFileType.XMP_FT_JPEG); + + XmpStringPtr file_path = xmp_string_new(); + XmpOpenFileOptions options; + XmpFileType file_format; + XmpFileFormatOptions handler_flags; + assert(xmp_files_get_file_info(f, file_path, &options, &file_format, + &handler_flags)); + assert(options == XmpOpenFileOptions.XMP_OPEN_READ); + assert(file_format == XmpFileType.XMP_FT_JPEG); + // the value check might break at each SDK update. You have been warned. + assert(handler_flags == 0x27f); + //assert(sampleFile.toStringz() == xmp_string_cstr(file_path)); + xmp_string_free(file_path); + + XmpPtr xmp = xmp_new_empty(); + + assert(xmp !is null); + + assert(xmp_files_get_xmp(f, xmp)); + + { + XmpStringPtr thestring = xmp_string_new(); + XmpPacketInfo packet_info; + assert(xmp_files_get_xmp_xmpstring(f, thestring, &packet_info)); + assert(packet_info.offset == 2189); + assert(packet_info.length == 4782); + assert(packet_info.padSize == 2049); + assert(packet_info.hasWrapper); + + const char *xmp_str = xmp_string_cstr(thestring); + assert(xmp_str); + xmp_string_free(thestring); + } + + XmpStringPtr the_prop = xmp_string_new(); + + assert( + xmp_get_property(xmp, NS_PHOTOSHOP.ptr, "ICCProfile", the_prop, null)); + assert("sRGB IEC61966-2.1" == fromStringz(xmp_string_cstr(the_prop))); + + xmp_string_free(the_prop); + assert(xmp_free(xmp)); + + assert(xmp_files_free(f)); + + XmpFileFormatOptions formatOptions; + + // the value check might break at each SDK update. You have been warned. + assert(xmp_files_get_format_info(XmpFileType.XMP_FT_JPEG, &formatOptions)); + assert(formatOptions == 0x27f); + assert(xmp_files_get_format_info(XmpFileType.XMP_FT_GIF, &formatOptions)); + assert(formatOptions == 0x46b); + assert(xmp_files_get_format_info(XmpFileType.XMP_FT_PNG, &formatOptions)); + assert(formatOptions == 0x46b); + // PDF doesn't have a smart handler. + assert(!xmp_files_get_format_info(XmpFileType.XMP_FT_PDF, &formatOptions)); + + + xmp_terminate(); +}