Skip to content
Snippets Groups Projects
Commit c8ac48d5 authored by Markus Törnqvist's avatar Markus Törnqvist
Browse files

Implement row_count

This does not seem to be directly called, but it
should be a convenient short-hand.
parent ebb01e22
No related branches found
No related tags found
Loading
Pipeline #163650007 failed
...@@ -51,7 +51,13 @@ pub struct MessageModel { ...@@ -51,7 +51,13 @@ pub struct MessageModel {
} }
impl MessageModel { impl MessageModel {
fn load(&mut self, sid: i64, _peer_name: QString) { #[allow(dead_code)]
pub fn row_count(&self) -> i32 {
log::trace!("rowCount called, returning {}", self.messages.len());
self.messages.len() as i32
}
pub fn load(&mut self, sid: i64, _peer_name: QString) {
(self as &mut dyn QAbstractListModel).begin_reset_model(); (self as &mut dyn QAbstractListModel).begin_reset_model();
self.messages.clear(); self.messages.clear();
......
// TODO: Write the qt5-model tests here use rstest::rstest;
use harbour_whisperfish::model::MessageModel;
use harbour_whisperfish::store::Storage;
use harbour_whisperfish::store::{NewMessage, NewSession};
use qmetaobject::QString;
mod common;
use common::*;
#[rstest]#[actix_rt::test]
async fn test_load_and_row_count(in_memory_db: Storage) {
let session_config = NewSession {
source: String::from("+358501234567"),
message: String::from("whisperfish on paras:DDDD ja signal:DDD"),
timestamp: 0,
sent: true,
received: false,
unread: false,
is_group: false,
group_id: None,
group_name: None,
group_members: None,
has_attachment: false,
};
setup_db(&in_memory_db);
setup_session(&in_memory_db, &session_config);
let new_messages = vec![NewMessage {
session_id: 1,
source: String::from("+358501234567"),
text: String::from("nyt joni ne velat!"),
timestamp: 1024,
sent: false,
received: true,
flags: 0,
attachment: None,
mime_type: None,
has_attachment: false,
outgoing: false,
}];
setup_messages(&in_memory_db, new_messages);
// Actual testing
let mut mm = MessageModel::default();
assert_eq!(mm.row_count(), 0);
mm.load(1, QString::from("WHY IS THIS NEEDED WHEN IT ISN'T NEEDED ELSEWHERE?!"));
assert_eq!(mm.row_count(), 1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment