@@ -17,29 +17,48 @@ extern crate rexiv2;
17
17
18
18
use std:: path:: Path ;
19
19
20
+ use std:: sync:: Once ;
21
+
22
+ static INIT : Once = Once :: new ( ) ;
23
+
24
+ ///
25
+ /// Should be called before any test runs. Will ensure that the library is initialized at most once.
26
+ /// This would be the equivalent of a "beforeAll" function in other test libraries.
27
+ ///
28
+ /// Future work: At some strange it might be good to work out if this can be done automatically
29
+ /// by the test runner. It doesn't seem to be right now with the stock cargo test runner but
30
+ /// it might be possible with 3rd party crates.
31
+ ///
32
+ fn setup_test ( ) {
33
+ INIT . call_once ( || rexiv2:: initialize ( ) . expect ( "Unable to initialize rexiv2" ) ) ;
34
+ }
20
35
21
36
#[ test]
22
37
fn new_from_str_path ( ) {
38
+ setup_test ( ) ;
23
39
let sample_path = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/tst/sample.png" ) ;
24
40
let meta = rexiv2:: Metadata :: new_from_path ( sample_path) . unwrap ( ) ;
25
41
assert_eq ! ( meta. get_media_type( ) . unwrap( ) , rexiv2:: MediaType :: Png ) ;
26
42
}
27
43
28
44
#[ test]
29
45
fn new_from_path ( ) {
46
+ setup_test ( ) ;
30
47
let sample_path = Path :: new ( concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/tst/sample.png" ) ) ;
31
48
let meta = rexiv2:: Metadata :: new_from_path ( sample_path) . unwrap ( ) ;
32
49
assert_eq ! ( meta. get_media_type( ) . unwrap( ) , rexiv2:: MediaType :: Png ) ;
33
50
}
34
51
35
52
#[ test]
36
53
fn new_from_buffer ( ) {
54
+ setup_test ( ) ;
37
55
let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.png" ) ) . unwrap ( ) ;
38
56
assert_eq ! ( meta. get_media_type( ) . unwrap( ) , rexiv2:: MediaType :: Png ) ;
39
57
}
40
58
41
59
#[ test]
42
60
fn new_from_buffer_error ( ) {
61
+ setup_test ( ) ;
43
62
let mut bytes = include_bytes ! ( "sample.png" ) . to_vec ( ) ;
44
63
bytes. swap ( 0 , 1 ) ;
45
64
let meta_result = rexiv2:: Metadata :: new_from_buffer ( & bytes) ;
@@ -53,24 +72,49 @@ fn new_from_buffer_error() {
53
72
54
73
#[ test]
55
74
fn supports_exif ( ) {
75
+ setup_test ( ) ;
56
76
let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.png" ) ) . unwrap ( ) ;
57
77
assert_eq ! ( meta. supports_exif( ) , true ) ;
58
78
}
59
79
60
80
#[ test]
61
81
fn supports_iptc ( ) {
82
+ setup_test ( ) ;
62
83
let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.png" ) ) . unwrap ( ) ;
63
84
assert_eq ! ( meta. supports_iptc( ) , true ) ;
64
85
}
65
86
66
87
#[ test]
67
88
fn supports_xmp ( ) {
89
+ setup_test ( ) ;
68
90
let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.png" ) ) . unwrap ( ) ;
69
91
assert_eq ! ( meta. supports_xmp( ) , true ) ;
70
92
}
71
93
94
+ #[ test]
95
+ fn supports_bmff ( ) {
96
+ setup_test ( ) ;
97
+ // iPhone devices use the HEIC (BMFF) file format which only works properly after gexiv2 has been initialized
98
+ // (and the underlying libraries are the right version gexiv2 v0.13.0/Exiv2 v0.27.4)
99
+ // I copied a photo off an iPhone and shrunk it down to ensure that reading tags works
100
+
101
+ let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.HEIC" ) ) . unwrap ( ) ;
102
+ let gps = meta. get_gps_info ( ) . unwrap ( ) ;
103
+ assert_eq ! ( gps. latitude as i32 , -27 ) ;
104
+ assert_eq ! ( gps. longitude as i32 , 114 ) ;
105
+ let phone_model = meta. get_tag_string ( "Exif.Image.Model" ) . unwrap ( ) ;
106
+ assert_eq ! ( phone_model, "iPhone XS" ) ;
107
+
108
+ // This seems strange since we can read the above information
109
+ // We may be missing a "supports" function for bmff tags, or the functions may be returning incorrectly
110
+ assert_eq ! ( meta. supports_exif( ) , false ) ;
111
+ assert_eq ! ( meta. supports_iptc( ) , false ) ;
112
+ assert_eq ! ( meta. supports_xmp( ) , false ) ;
113
+ }
114
+
72
115
#[ test]
73
116
fn log_levels ( ) {
117
+ setup_test ( ) ;
74
118
assert_eq ! ( rexiv2:: get_log_level( ) , rexiv2:: LogLevel :: WARN ) ;
75
119
rexiv2:: set_log_level ( rexiv2:: LogLevel :: INFO ) ;
76
120
assert_eq ! ( rexiv2:: get_log_level( ) , rexiv2:: LogLevel :: INFO ) ;
@@ -79,6 +123,7 @@ fn log_levels() {
79
123
#[ test]
80
124
#[ cfg( feature = "raw-tag-access" ) ]
81
125
fn get_tag_raw ( ) {
126
+ setup_test ( ) ;
82
127
let meta = rexiv2:: Metadata :: new_from_buffer ( include_bytes ! ( "sample.png" ) ) . unwrap ( ) ;
83
128
meta. set_tag_string ( "Exif.Image.DateTime" , "2020:07:12 11:16:35" )
84
129
. unwrap ( ) ;
0 commit comments