summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-08-17 17:10:12 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-08-17 17:10:12 +0200
commit008bc99860fd353a5da5d06e6be5937f4a358aed (patch)
treed50b38f704b90b83895a21fd610bcf78c31b2cc9 /test
parent4ec8ba6ace7234ddc24a7d362a34d9055a83812c (diff)
parent7eef6a59ba38582bed5d459974211eb1f53e1f5d (diff)
Merge branch 'release/debian/0.32.2-1'debian/0.32.2-1
Diffstat (limited to 'test')
l---------test/jfif/Dimensions.vala1
l---------test/jfif/GdkSupport.vala1
-rw-r--r--test/jfif/JfifSupport-Test.vala44
l---------test/jfif/JfifSupport.vala1
l---------test/jfif/PhotoFileAdapter.vala1
-rw-r--r--test/jfif/PhotoFileFormat-jfifstub.vala95
l---------test/jfif/PhotoFileSniffer.vala1
-rw-r--r--test/jfif/PhotoMetadata-stub.vala8
-rw-r--r--test/jfif/ProgressMonitor-stub.vala2
l---------test/jfif/file.vala1
l---------test/jfif/string.vala1
-rw-r--r--test/jfif/util_core-stub.vala1
-rw-r--r--test/jfif/util_image-stub.vala2
-rw-r--r--test/meson.build20
l---------test/shotwell-street.jpg1
15 files changed, 180 insertions, 0 deletions
diff --git a/test/jfif/Dimensions.vala b/test/jfif/Dimensions.vala
new file mode 120000
index 0000000..741567a
--- /dev/null
+++ b/test/jfif/Dimensions.vala
@@ -0,0 +1 @@
+../../src/Dimensions.vala \ No newline at end of file
diff --git a/test/jfif/GdkSupport.vala b/test/jfif/GdkSupport.vala
new file mode 120000
index 0000000..17a8df5
--- /dev/null
+++ b/test/jfif/GdkSupport.vala
@@ -0,0 +1 @@
+../../src/photos/GdkSupport.vala \ No newline at end of file
diff --git a/test/jfif/JfifSupport-Test.vala b/test/jfif/JfifSupport-Test.vala
new file mode 100644
index 0000000..0fe94b5
--- /dev/null
+++ b/test/jfif/JfifSupport-Test.vala
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: LGPLv2.1-or-later
+
+[CCode (cname="TEST_DATA_DIR")]
+extern const string TEST_DATA_DIR;
+
+void add_jfif_sof_tests () {
+ Test.add_func ("/unit/photos/jfif/is_sof", () => {
+ Jpeg.Marker m = (Jpeg.Marker)0x8f;
+ assert(! m.is_sof());
+ m = (Jpeg.Marker)0xc0;
+ assert(m.is_sof());
+ m = (Jpeg.Marker)0xc4;
+ assert(! m.is_sof());
+ m = (Jpeg.Marker)0xe0;
+ assert(! m.is_sof());
+ });
+}
+
+void add_jfif_sniff_fast_tests () {
+ Test.add_func ("/functional/photos/jfif/sniff_fast", () => {
+ File f = File.new_for_path(TEST_DATA_DIR + "/shotwell-street.jpg");
+ JfifSniffer s = new JfifSniffer(f, PhotoFileSniffer.Options.NO_MD5);
+ bool is_corrupted = false;
+ try {
+ DetectedPhotoInformation detected = s.sniff(out is_corrupted);
+ assert(!is_corrupted);
+ assert(detected.channels == 3);
+ assert(detected.bits_per_channel == 8);
+ assert(detected.format_name == "jpeg");
+ assert(detected.image_dim.width == 360);
+ assert(detected.image_dim.height == 236);
+ } catch (Error err) {
+ assert_not_reached();
+ }
+ });
+}
+
+void main (string[] args) {
+ Test.init (ref args);
+ add_jfif_sof_tests();
+ add_jfif_sniff_fast_tests();
+ Test.run();
+}
+
diff --git a/test/jfif/JfifSupport.vala b/test/jfif/JfifSupport.vala
new file mode 120000
index 0000000..17fb7cf
--- /dev/null
+++ b/test/jfif/JfifSupport.vala
@@ -0,0 +1 @@
+../../src/photos/JfifSupport.vala \ No newline at end of file
diff --git a/test/jfif/PhotoFileAdapter.vala b/test/jfif/PhotoFileAdapter.vala
new file mode 120000
index 0000000..042870d
--- /dev/null
+++ b/test/jfif/PhotoFileAdapter.vala
@@ -0,0 +1 @@
+../../src/photos/PhotoFileAdapter.vala \ No newline at end of file
diff --git a/test/jfif/PhotoFileFormat-jfifstub.vala b/test/jfif/PhotoFileFormat-jfifstub.vala
new file mode 100644
index 0000000..db6b4a9
--- /dev/null
+++ b/test/jfif/PhotoFileFormat-jfifstub.vala
@@ -0,0 +1,95 @@
+// stub for JFIF support test
+
+public enum PhotoFileFormat {
+ JFIF,
+ UNKNOWN;
+
+ public static PhotoFileFormat[] get_supported() { return { JFIF }; }
+
+ public static PhotoFileFormat from_pixbuf_name(string name) {
+ if (name == "jpeg") {
+ return PhotoFileFormat.JFIF;
+ } else {
+ return PhotoFileFormat.UNKNOWN;
+ }
+ }
+
+ public void init() { JfifFileFormatDriver.init(); }
+
+ public PhotoFileFormatDriver get_driver() {
+ return JfifFileFormatDriver.get_instance();
+ }
+
+ public PhotoFileReader create_reader(string filepath) {
+ return get_driver().create_reader(filepath);
+ }
+
+ public PhotoFileWriter create_writer(string filepath) throws PhotoFormatError {
+ PhotoFileWriter writer = get_driver().create_writer(filepath);
+ return writer;
+ }
+
+ public PhotoFileMetadataWriter create_metadata_writer(string filepath) throws PhotoFormatError {
+ PhotoFileMetadataWriter writer = get_driver().create_metadata_writer(filepath);
+ return writer;
+ }
+
+ public PhotoFileSniffer create_sniffer(File file, PhotoFileSniffer.Options options) {
+ return get_driver().create_sniffer(file, options);
+ }
+}
+
+public errordomain PhotoFormatError {
+ READ_ONLY
+}
+
+public abstract class PhotoFileFormatDriver {
+ public abstract PhotoFileFormatProperties get_properties();
+
+ public abstract PhotoFileReader create_reader(string filepath);
+
+ public abstract PhotoMetadata create_metadata();
+
+ public abstract bool can_write_image();
+
+ public abstract bool can_write_metadata();
+
+ public abstract PhotoFileWriter? create_writer(string filepath);
+
+ public abstract PhotoFileMetadataWriter? create_metadata_writer(string filepath);
+
+ public abstract PhotoFileSniffer create_sniffer(File file, PhotoFileSniffer.Options options);
+}
+
+public enum PhotoFileFormatFlags {
+ NONE = 0x00000000,
+}
+
+public abstract class PhotoFileFormatProperties {
+ public abstract PhotoFileFormat get_file_format();
+
+ public abstract PhotoFileFormatFlags get_flags();
+
+ public virtual bool is_recognized_extension(string ext) {
+ return is_in_ci_array(ext, get_known_extensions());
+ }
+
+ public abstract string get_default_extension();
+
+ public abstract string[] get_known_extensions();
+
+ public abstract string get_default_mime_type();
+
+ public abstract string[] get_mime_types();
+
+ public abstract string get_user_visible_name();
+
+ public File convert_file_extension(File file) {
+ string name, ext;
+ disassemble_filename(file.get_basename(), out name, out ext);
+ if (ext != null && is_recognized_extension(ext))
+ return file;
+
+ return file.get_parent().get_child("%s.%s".printf(name, get_default_extension()));
+ }
+}
diff --git a/test/jfif/PhotoFileSniffer.vala b/test/jfif/PhotoFileSniffer.vala
new file mode 120000
index 0000000..d64385c
--- /dev/null
+++ b/test/jfif/PhotoFileSniffer.vala
@@ -0,0 +1 @@
+../../src/photos/PhotoFileSniffer.vala \ No newline at end of file
diff --git a/test/jfif/PhotoMetadata-stub.vala b/test/jfif/PhotoMetadata-stub.vala
new file mode 100644
index 0000000..2d5b364
--- /dev/null
+++ b/test/jfif/PhotoMetadata-stub.vala
@@ -0,0 +1,8 @@
+// stub class for photo metadata needed by the JFIF Support test
+public class PhotoMetadata {
+ public PhotoMetadata() { }
+ public void read_from_file(File file) throws Error { }
+ public void write_to_file(File file) throws Error { }
+ public string? exif_hash() { return null; }
+ public string? thumbnail_hash() { return null; }
+}
diff --git a/test/jfif/ProgressMonitor-stub.vala b/test/jfif/ProgressMonitor-stub.vala
new file mode 100644
index 0000000..9290ad1
--- /dev/null
+++ b/test/jfif/ProgressMonitor-stub.vala
@@ -0,0 +1,2 @@
+// Needed to include util/file.vala without core/util.vala as well
+public delegate bool ProgressMonitor(uint64 current, uint64 total, bool do_event_loop = true);
diff --git a/test/jfif/file.vala b/test/jfif/file.vala
new file mode 120000
index 0000000..c0f398e
--- /dev/null
+++ b/test/jfif/file.vala
@@ -0,0 +1 @@
+../../src/util/file.vala \ No newline at end of file
diff --git a/test/jfif/string.vala b/test/jfif/string.vala
new file mode 120000
index 0000000..39f7f39
--- /dev/null
+++ b/test/jfif/string.vala
@@ -0,0 +1 @@
+../../src/util/string.vala \ No newline at end of file
diff --git a/test/jfif/util_core-stub.vala b/test/jfif/util_core-stub.vala
new file mode 100644
index 0000000..6af313b
--- /dev/null
+++ b/test/jfif/util_core-stub.vala
@@ -0,0 +1 @@
+public DateTime? coarsify_date_time(DateTime? dt) { return dt; }
diff --git a/test/jfif/util_image-stub.vala b/test/jfif/util_image-stub.vala
new file mode 100644
index 0000000..45ebe40
--- /dev/null
+++ b/test/jfif/util_image-stub.vala
@@ -0,0 +1,2 @@
+Gdk.Pixbuf resize_pixbuf(Gdk.Pixbuf pixbuf, Dimensions resized, Gdk.InterpType interp) { return pixbuf; }
+Gdk.Pixbuf scale_pixbuf(Gdk.Pixbuf pixbuf, int scale, Gdk.InterpType interp, bool scale_up) { return pixbuf; }
diff --git a/test/meson.build b/test/meson.build
index de1f012..5319cfc 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -2,4 +2,24 @@ natural_collate_test = executable('natural-collate-test',
['NaturalCollate-Test.vala', 'NaturalCollate.vala'],
dependencies : gio)
+jfif_support_test = executable('jfif-support-test',
+ ['jfif/JfifSupport-Test.vala',
+ 'jfif/PhotoFileSniffer.vala',
+ 'jfif/PhotoFileAdapter.vala',
+ 'jfif/JfifSupport.vala',
+ 'jfif/GdkSupport.vala',
+ 'jfif/Dimensions.vala',
+ 'jfif/string.vala',
+ 'jfif/file.vala',
+ 'jfif/util_core-stub.vala',
+ 'jfif/ProgressMonitor-stub.vala',
+ 'jfif/PhotoMetadata-stub.vala',
+ 'jfif/PhotoFileFormat-jfifstub.vala',
+ 'jfif/util_image-stub.vala'],
+ dependencies : [gio, gee, gtk, gexiv2, math],
+ c_args : ['-DTEST_DATA_DIR="@0@"'.format(meson.current_source_dir())]
+ )
+
+
test('natural-collate', natural_collate_test)
+test('jfif-support', jfif_support_test)
diff --git a/test/shotwell-street.jpg b/test/shotwell-street.jpg
new file mode 120000
index 0000000..02e2438
--- /dev/null
+++ b/test/shotwell-street.jpg
@@ -0,0 +1 @@
+../data/icons/shotwell-street.jpg \ No newline at end of file