Skip to content

Commit

Permalink
CBL-6350 : Implement GetRevisionHistory API
Browse files Browse the repository at this point in the history
Implemented CBLDocument_GetRevisionHistory for end-to-end testing.
  • Loading branch information
pasin committed Oct 21, 2024
1 parent b698649 commit 3afae3c
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/CBLDocument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ CBLDatabase* _cbl_nullable CBLDocument::database() const {
}


#pragma mark - REVISION HISTORY:


alloc_slice CBLDocument::getRevisionHistory() const {
if (!_collection) {
return fleece::nullslice;
}

auto doc = _collection->getDocument(_docID, false, true);
if (!doc) {
return fleece::nullslice;
}

auto c4doc = doc->_c4doc.useLocked();
assert(c4doc);
return c4doc->getRevisionHistory(UINT_MAX, nullptr, 0);
}


#pragma mark - SAVING:


Expand Down
5 changes: 5 additions & 0 deletions src/CBLDocument_CAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ unsigned CBLDocument_Generation(const CBLDocument* doc) noexcept {
return doc->generation();
}

/** Private API */
FLSliceResult CBLDocument_GetRevisionHistory(const CBLDocument* doc) noexcept {
return FLSliceResult(doc->getRevisionHistory());
}

FLMutableDict CBLDocument_MutableProperties(CBLDocument* doc) noexcept {
return doc->mutableProperties();
}
Expand Down
3 changes: 3 additions & 0 deletions src/CBLDocument_Internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public:
auto c4doc = _c4doc.useLocked();
return c4doc ? c4doc->selectedRev().flags : (kRevNew | kRevLeaf);
}


alloc_slice getRevisionHistory() const;


#pragma mark - Properties:
Expand Down
2 changes: 2 additions & 0 deletions src/CBLPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ FLMutableArray CBLCollection_GetIndexesInfo(const CBLCollection* collection,
FLSliceResult CBLDocument_CanonicalRevisionID(const CBLDocument* doc) CBLAPI;

unsigned CBLDocument_Generation(const CBLDocument* doc) CBLAPI;

FLSliceResult CBLDocument_GetRevisionHistory(const CBLDocument* doc) CBLAPI;

FLSlice CBLReplicator_UserAgent(const CBLReplicator* repl) CBLAPI;

Expand Down
1 change: 1 addition & 0 deletions src/exports/CBL_Exports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ CBLDatabase_LastSequence

CBLDocument_CanonicalRevisionID
CBLDocument_Generation
CBLDocument_GetRevisionHistory

CBLError_GetCaptureBacktraces
CBLError_SetCaptureBacktraces
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL.def
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ CBLDatabase_DeleteDocumentByID
CBLDatabase_LastSequence
CBLDocument_CanonicalRevisionID
CBLDocument_Generation
CBLDocument_GetRevisionHistory
CBLError_GetCaptureBacktraces
CBLError_SetCaptureBacktraces
CBLQuery_SetListenerCallbackDelay
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL.exp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ _CBLDatabase_DeleteDocumentByID
_CBLDatabase_LastSequence
_CBLDocument_CanonicalRevisionID
_CBLDocument_Generation
_CBLDocument_GetRevisionHistory
_CBLError_GetCaptureBacktraces
_CBLError_SetCaptureBacktraces
_CBLQuery_SetListenerCallbackDelay
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ CBL_C {
CBLDatabase_LastSequence;
CBLDocument_CanonicalRevisionID;
CBLDocument_Generation;
CBLDocument_GetRevisionHistory;
CBLError_GetCaptureBacktraces;
CBLError_SetCaptureBacktraces;
CBLQuery_SetListenerCallbackDelay;
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL_Android.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ CBL_C {
CBLDatabase_LastSequence;
CBLDocument_CanonicalRevisionID;
CBLDocument_Generation;
CBLDocument_GetRevisionHistory;
CBLError_GetCaptureBacktraces;
CBLError_SetCaptureBacktraces;
CBLQuery_SetListenerCallbackDelay;
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL_EE.def
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ CBLDatabase_DeleteDocumentByID
CBLDatabase_LastSequence
CBLDocument_CanonicalRevisionID
CBLDocument_Generation
CBLDocument_GetRevisionHistory
CBLError_GetCaptureBacktraces
CBLError_SetCaptureBacktraces
CBLQuery_SetListenerCallbackDelay
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL_EE.exp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ _CBLDatabase_DeleteDocumentByID
_CBLDatabase_LastSequence
_CBLDocument_CanonicalRevisionID
_CBLDocument_Generation
_CBLDocument_GetRevisionHistory
_CBLError_GetCaptureBacktraces
_CBLError_SetCaptureBacktraces
_CBLQuery_SetListenerCallbackDelay
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL_EE.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ CBL_C {
CBLDatabase_LastSequence;
CBLDocument_CanonicalRevisionID;
CBLDocument_Generation;
CBLDocument_GetRevisionHistory;
CBLError_GetCaptureBacktraces;
CBLError_SetCaptureBacktraces;
CBLQuery_SetListenerCallbackDelay;
Expand Down
1 change: 1 addition & 0 deletions src/exports/generated/CBL_EE_Android.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ CBL_C {
CBLDatabase_LastSequence;
CBLDocument_CanonicalRevisionID;
CBLDocument_Generation;
CBLDocument_GetRevisionHistory;
CBLError_GetCaptureBacktraces;
CBLError_SetCaptureBacktraces;
CBLQuery_SetListenerCallbackDelay;
Expand Down
39 changes: 38 additions & 1 deletion test/DocumentTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,43 @@ TEST_CASE_METHOD(DocumentTest, "Save Document into Different Collection", "[Docu
CBLDocument_Release(doc);
}

#pragma mark - Revision History

/*
https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0005-Version-Vector.md
2. TestDocumentRevisionHistory
Description
Test that the document's timestamp returns value as expected.
Steps
1. Create a new document with id = "doc1"
2. Get document's _revisionIDs and check that the value returned is an empty array.
3. Save the document into the default collection.
4. Get document's _revisionIDs and check that the value returned is an array containing a
single revision id which is the revision id of the documnt.
5. Get the document id = "doc1" from the database.
6. Get document's _revisionIDs and check that the value returned is an array containing a
single revision id which is the revision id of the documnt.
*/
TEST_CASE_METHOD(DocumentTest, "Revision History", "[Document]") {
CBLDocument* doc = CBLDocument_CreateWithID("foo"_sl);

alloc_slice revHistory = CBLDocument_GetRevisionHistory(doc);
CHECK(revHistory == nullslice);

CBLError error;
REQUIRE(CBLCollection_SaveDocument(col, doc, &error));
revHistory = CBLDocument_GetRevisionHistory(doc);
CHECK(revHistory != nullslice);
CBLDocument_Release(doc);

doc = CBLCollection_GetMutableDocument(col, "foo"_sl, &error);
revHistory = CBLDocument_GetRevisionHistory(doc);
CHECK(revHistory != nullslice);
CBLDocument_Release(doc);
}

#pragma mark - Delete Document:

TEST_CASE_METHOD(DocumentTest, "Delete Non Existing Document", "[Document]") {
Expand Down Expand Up @@ -1156,4 +1193,4 @@ TEST_CASE_METHOD(DocumentTest, "Collection Change Notifications", "[Document]")
createDocument(col, "bar", "greeting", "yo.");
CHECK(collectionListenerCalls == 0);
CHECK(docListenerCalls == 0);
}
}

0 comments on commit 3afae3c

Please sign in to comment.