Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/encryptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl CblRef for Encryptable {

impl From<*mut CBLEncryptable> for Encryptable {
fn from(cbl_ref: *mut CBLEncryptable) -> Self {
Self::reference(cbl_ref)
Self::take_ownership(cbl_ref)
}
}

Expand All @@ -80,6 +80,11 @@ impl Encryptable {
}
}

/// Takes ownership of the CBL ref, the reference counter is not increased so dropping the instance will free the ref.
pub(crate) const fn take_ownership(cbl_ref: *mut CBLEncryptable) -> Self {
Self { cbl_ref }
}

////////

/// Creates Encryptable object with null value.
Expand Down
12 changes: 10 additions & 2 deletions src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
};
use crate::{
CblRef, Database, Dict, Document, Error, ListenerToken, MutableDict, Result, check_error,
release, retain,
release,
slice::{from_str, self},
c_api::{
CBLListener_Remove, CBLAuth_CreatePassword, CBLAuth_CreateSession, CBLAuthenticator,
Expand Down Expand Up @@ -107,6 +107,14 @@ impl Clone for Endpoint {
}
}

impl Drop for Endpoint {
fn drop(&mut self) {
unsafe {
release(self.get_ref());
}
}
}

/** An opaque object representing authentication credentials for a remote server. */
#[derive(Debug, PartialEq, Eq)]
pub struct Authenticator {
Expand Down Expand Up @@ -786,7 +794,7 @@ impl Replicator {
database: config
.database
.as_ref()
.map(|d| retain(d.get_ref()))
.map(|d| d.get_ref())
.unwrap_or(ptr::null_mut()),
endpoint: config.endpoint.get_ref(),
replicatorType: config.replicator_type.clone().into(),
Expand Down
7 changes: 6 additions & 1 deletion tests/database_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern crate lazy_static;
use self::couchbase_lite::*;
use self::tempdir::TempDir;
use lazy_static::lazy_static;
use utils::init_logging;
use utils::{init_logging, LeakChecker};

pub mod utils;

Expand All @@ -44,6 +44,7 @@ fn delete_file() {
pub const DB_NAME: &str = "test_db";

init_logging();
let _leak_checker = LeakChecker::new();

let tmp_dir = TempDir::new("cbl_rust").expect("create temp dir");
let cfg = DatabaseConfiguration {
Expand All @@ -66,6 +67,7 @@ fn copy_file() {
pub const DB_NAME_BACKUP: &str = "test_db_backup";

init_logging();
let _leak_checker = LeakChecker::new();

// Initial DB
let tmp_dir = TempDir::new("cbl_rust").expect("create temp dir");
Expand Down Expand Up @@ -147,6 +149,9 @@ fn db_properties() {
#[test]
#[cfg(feature = "enterprise")]
fn db_encryption_key() {
init_logging();
let _leak_checker = LeakChecker::new();

let tmp_dir = TempDir::new("cbl_rust").expect("create temp dir");
let cfg_no_encryption = DatabaseConfiguration {
directory: tmp_dir.path(),
Expand Down
13 changes: 13 additions & 0 deletions tests/document_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ extern crate couchbase_lite;

use self::couchbase_lite::*;
use std::time::Duration;
use utils::{init_logging, LeakChecker};

pub mod utils;

#[test]
fn document_new() {
init_logging();
let _leak_checker = LeakChecker::new();

let document = Document::new();
assert_ne!(document.id(), "");
assert_eq!(document.revision_id(), None);
Expand All @@ -18,6 +22,9 @@ fn document_new() {

#[test]
fn document_new_with_id() {
init_logging();
let _leak_checker = LeakChecker::new();

let document = Document::new_with_id("foo");
assert_eq!(document.id(), "foo");
assert_eq!(document.revision_id(), None);
Expand Down Expand Up @@ -70,6 +77,9 @@ fn document_sequence() {

#[test]
fn document_properties() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut document = Document::new();
let mut properties = MutableDict::new();
properties.at("foo").put_bool(false);
Expand All @@ -87,6 +97,9 @@ fn document_properties() {

#[test]
fn document_properties_as_json() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut document = Document::new();
document
.set_properties_as_json(r#"{"foo":true,"bar":true}"#)
Expand Down
36 changes: 36 additions & 0 deletions tests/fleece_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
extern crate couchbase_lite;

use couchbase_lite::*;
use utils::{init_logging, LeakChecker};

pub mod utils;

#[test]
fn empty_values() {
init_logging();
let _leak_checker = LeakChecker::new();

let v = Value::default();
assert_eq!(v.get_type(), ValueType::Undefined);
assert!(!v.is_type(ValueType::Bool));
Expand All @@ -38,6 +44,9 @@ fn empty_values() {

#[test]
fn basic_values() {
init_logging();
let _leak_checker = LeakChecker::new();

let doc = Fleece::parse_json(r#"{"i":1234,"f":12.34,"a":[1, 2],"s":"Foo"}"#).unwrap();
let dict = doc.as_dict();
assert_eq!(dict.count(), 4);
Expand Down Expand Up @@ -82,6 +91,9 @@ fn basic_values() {

#[test]
fn nested_borrow_check() {
init_logging();
let _leak_checker = LeakChecker::new();

let v: Value;
let mut str = String::new();

Expand Down Expand Up @@ -116,6 +128,9 @@ fn borrow_check() {

#[test]
fn dict_to_hash_set() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut mut_dict = MutableDict::new();

mut_dict.at("id1").put_bool(true);
Expand All @@ -132,6 +147,9 @@ fn dict_to_hash_set() {

#[test]
fn mutable_dict() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut dict = MutableDict::new();
assert_eq!(dict.count(), 0);
assert_eq!(dict.get("a"), Value::UNDEFINED);
Expand All @@ -152,6 +170,9 @@ fn mutable_dict() {

#[test]
fn mutable_dict_to_from_hash_map() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut dict = MutableDict::new();

dict.at("id1").put_string("value1");
Expand All @@ -170,6 +191,9 @@ fn mutable_dict_to_from_hash_map() {

#[test]
fn dict_exact_size_iterator() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut mut_dict = MutableDict::new();
mut_dict.at("1").put_string("value1");
mut_dict.at("2").put_string("value2");
Expand All @@ -182,6 +206,9 @@ fn dict_exact_size_iterator() {

#[test]
fn dict_from_iterator() {
init_logging();
let _leak_checker = LeakChecker::new();

let dict: MutableDict = Fleece::parse_json(r#"{"1": "value1","f":12.34}"#)
.unwrap()
.as_dict()
Expand All @@ -202,6 +229,9 @@ fn dict_from_iterator() {

#[test]
fn array_at() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut mut_arr = MutableArray::new();
assert!(mut_arr.at(0).is_none());
mut_arr.append().put_string("value1");
Expand All @@ -210,6 +240,9 @@ fn array_at() {

#[test]
fn array_exact_size_iterator() {
init_logging();
let _leak_checker = LeakChecker::new();

let mut mut_arr = MutableArray::new();
mut_arr.append().put_string("value1");
mut_arr.append().put_string("value2");
Expand All @@ -222,6 +255,9 @@ fn array_exact_size_iterator() {

#[test]
fn array_from_iterator() {
init_logging();
let _leak_checker = LeakChecker::new();

let arr: MutableArray = Fleece::parse_json(r#"["value1","value2"]"#)
.unwrap()
.as_array()
Expand Down
Loading