Permalink
Browse files

Increase the test code coverage

Digging into the test coverage I found out that local docs are
deleted when you delete them, so I had code that would never be
called.

Change-Id: I2e4e137e9bb58c9298da24d8d80e5ac39e828df9
Reviewed-on: http://review.couchbase.org/15946
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent 80581c3 commit 81fa70dffae9df27162485533f6de03fe55b518d @trondn trondn committed May 12, 2012
Showing with 66 additions and 6 deletions.
  1. +1 −6 src/instance.c
  2. +65 −0 tests/instance_unit_tests.cc
View
@@ -104,12 +104,7 @@ static cbio_error_t cbio_get_local_document(libcbio_t handle,
err = couchstore_open_local_document(handle->couchstore_handle, id,
nid, &ldoc);
if (err == COUCHSTORE_SUCCESS) {
- cbio_error_t ret;
- if (ldoc->deleted) {
- ret = CBIO_ERROR_ENOENT;
- } else {
- ret = cbio_ldoc2doc(handle, ldoc, doc);
- }
+ cbio_error_t ret = cbio_ldoc2doc(handle, ldoc, doc);
couchstore_free_local_document(ldoc);
return ret;
}
@@ -162,6 +162,50 @@ TEST_F(LibcbioCreateDatabaseTest, reopenDatabaseCreate)
cbio_close_handle(handle);
}
+class LibcbioIllegalReadonlyOpsTest : public LibcbioTest {};
+TEST_F(LibcbioIllegalReadonlyOpsTest, commit)
+{
+ libcbio_t handle;
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle));
+ cbio_close_handle(handle);
+
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_open_handle(dbfile, CBIO_OPEN_RDONLY, &handle));
+
+ EXPECT_EQ(CBIO_ERROR_EINVAL,
+ cbio_commit(handle));
+
+ cbio_close_handle(handle);
+}
+
+TEST_F(LibcbioIllegalReadonlyOpsTest, store)
+{
+ libcbio_t handle;
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle));
+ cbio_close_handle(handle);
+
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_open_handle(dbfile, CBIO_OPEN_RDONLY, &handle));
+
+ libcbio_document_t doc;
+ string key("hello");
+ string value("world");
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_create_empty_document(handle, &doc));
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_document_set_id(doc, key.data(), key.length(), 0));
+ EXPECT_EQ(CBIO_SUCCESS,
+ cbio_document_set_value(doc, value.data(),
+ value.length(), 0));
+ EXPECT_EQ(CBIO_ERROR_EINVAL,
+ cbio_store_document(handle, doc));
+ cbio_document_release(doc);
+
+ cbio_close_handle(handle);
+}
+
class LibcbioDataAccessTest : public LibcbioTest
{
public:
@@ -370,6 +414,14 @@ class LibcbioLocalDocumentTest : public LibcbioDataAccessTest
{
};
+TEST_F(LibcbioLocalDocumentTest, testGetNonExistingLocalDocuments)
+{
+ libcbio_document_t doc;
+ string key("_local/foo");
+ EXPECT_EQ(CBIO_ERROR_ENOENT,
+ cbio_get_document_ex(handle, key.c_str(), key.length(), &doc));
+}
+
TEST_F(LibcbioLocalDocumentTest, testStoreLocalDocuments)
{
string key = "_local/hi-there";
@@ -382,6 +434,19 @@ TEST_F(LibcbioLocalDocumentTest, testDeleteLocalDocuments)
{
string key = "_local/hi-there";
deleteSingleDocument(key);
+ libcbio_document_t doc;
+ EXPECT_EQ(CBIO_ERROR_ENOENT,
+ cbio_get_document_ex(handle, key.data(), key.length(), &doc));
+}
+
+TEST_F(LibcbioLocalDocumentTest, testGetDeleteLocalDocuments)
+{
+ string key = "_local/hi-there";
+ string value = "{ foo:true }";
+ storeSingleDocument(key, value);
+ validateExistingDocument(key, value);
+ deleteSingleDocument(key);
+ validateNonExistingDocument(key);
}
TEST_F(LibcbioLocalDocumentTest, testChangesLocalDocuments)

0 comments on commit 81fa70d

Please sign in to comment.