Skip to content

Commit 21f8fef

Browse files
authored
Merge pull request #1809 from deltachat/test-get-width-height
add a higher-level test for dc_get_filemeta()
2 parents 04629c4 + 1566b71 commit 21f8fef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/message.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ pub async fn dc_empty_server(context: &Context, flags: u32) {
17321732
#[cfg(test)]
17331733
mod tests {
17341734
use super::*;
1735+
use crate::chat::ChatItem;
17351736
use crate::test_utils as test;
17361737

17371738
#[test]
@@ -1874,4 +1875,35 @@ mod tests {
18741875
assert_eq!(webrtc_type, VideochatType::Jitsi);
18751876
assert_eq!(url, "https://j.si/foo");
18761877
}
1878+
1879+
#[async_std::test]
1880+
async fn test_get_width_height() {
1881+
let t = test::TestContext::new().await;
1882+
1883+
// test that get_width() and get_height() are returning some dimensions for images;
1884+
// (as the device-chat contains a welcome-images, we check that)
1885+
t.ctx.update_device_chats().await.ok();
1886+
let (device_chat_id, _) =
1887+
chat::create_or_lookup_by_contact_id(&t.ctx, DC_CONTACT_ID_DEVICE, Blocked::Not)
1888+
.await
1889+
.unwrap();
1890+
1891+
let mut has_image = false;
1892+
let chatitems = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await;
1893+
for chatitem in chatitems {
1894+
if let ChatItem::Message { msg_id } = chatitem {
1895+
if let Ok(msg) = Message::load_from_db(&t.ctx, msg_id.clone()).await {
1896+
if msg.get_viewtype() == Viewtype::Image {
1897+
has_image = true;
1898+
// just check that width/height are inside some reasonable ranges
1899+
assert!(msg.get_width() > 100);
1900+
assert!(msg.get_height() > 100);
1901+
assert!(msg.get_width() < 4000);
1902+
assert!(msg.get_height() < 4000);
1903+
}
1904+
}
1905+
}
1906+
}
1907+
assert!(has_image);
1908+
}
18771909
}

0 commit comments

Comments
 (0)