00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <xapian.h>
00024
00025 #include "apitest.h"
00026 #include "testutils.h"
00027
00028 using namespace std;
00029
00031 DEFINE_TESTCASE(badtransaction1, transactions) {
00032 Xapian::WritableDatabase db(get_writable_database("apitest_simpledata"));
00033
00034 TEST_EXCEPTION(Xapian::InvalidOperationError, db.commit_transaction());
00035 TEST_EXCEPTION(Xapian::InvalidOperationError, db.cancel_transaction());
00036
00037 db.begin_transaction();
00038 TEST_EXCEPTION(Xapian::InvalidOperationError, db.begin_transaction());
00039 db.commit_transaction();
00040
00041 TEST_EXCEPTION(Xapian::InvalidOperationError, db.commit_transaction());
00042 TEST_EXCEPTION(Xapian::InvalidOperationError, db.cancel_transaction());
00043
00044 db.begin_transaction();
00045 TEST_EXCEPTION(Xapian::InvalidOperationError, db.begin_transaction());
00046 db.cancel_transaction();
00047
00048 TEST_EXCEPTION(Xapian::InvalidOperationError, db.commit_transaction());
00049 TEST_EXCEPTION(Xapian::InvalidOperationError, db.cancel_transaction());
00050
00051 db.begin_transaction();
00052 db.commit_transaction();
00053
00054 db.begin_transaction();
00055 db.cancel_transaction();
00056
00057 return true;
00058 }
00059
00061 DEFINE_TESTCASE(committransaction1, transactions) {
00062 Xapian::WritableDatabase db(get_writable_database("apitest_simpledata"));
00063
00064 Xapian::doccount docs = db.get_doccount();
00065 db.begin_transaction();
00066 Xapian::Document doc;
00067 doc.set_data("testing");
00068 doc.add_term("befuddlement");
00069 db.add_document(doc);
00070 TEST_EXCEPTION(Xapian::InvalidOperationError, db.begin_transaction());
00071 TEST_EQUAL(db.get_doccount(), docs + 1);
00072 TEST_EQUAL(db.get_termfreq("befuddlement"), 1);
00073 db.commit_transaction();
00074 TEST_EQUAL(db.get_doccount(), docs + 1);
00075 TEST_EQUAL(db.get_termfreq("befuddlement"), 1);
00076
00077 return true;
00078 }
00079
00081 DEFINE_TESTCASE(canceltransaction1, transactions) {
00082 Xapian::WritableDatabase db(get_writable_database("apitest_simpledata"));
00083
00084 Xapian::doccount docs = db.get_doccount();
00085 db.begin_transaction();
00086 Xapian::Document doc;
00087 doc.set_data("testing");
00088 doc.add_term("befuddlement");
00089 db.add_document(doc);
00090 TEST_EXCEPTION(Xapian::InvalidOperationError, db.begin_transaction());
00091 TEST_EQUAL(db.get_doccount(), docs + 1);
00092 TEST_EQUAL(db.get_termfreq("befuddlement"), 1);
00093 db.cancel_transaction();
00094 TEST_EQUAL(db.get_doccount(), docs);
00095 TEST_EQUAL(db.get_termfreq("befuddlement"), 0);
00096
00097 return true;
00098 }
00099
00101
00102 DEFINE_TESTCASE(canceltransaction2, transactions) {
00103 Xapian::WritableDatabase db(get_writable_database("apitest_simpledata"));
00104
00105 Xapian::doccount docs = db.get_doccount();
00106 Xapian::Document doc0;
00107 doc0.set_data("pending");
00108 doc0.add_term("pending_update");
00109 Xapian::docid docid = db.add_document(doc0);
00110
00111 db.begin_transaction();
00112 TEST_EQUAL(db.get_doccount(), docs + 1);
00113 Xapian::Document doc;
00114 doc.set_data("testing");
00115 doc.add_term("befuddlement");
00116 db.add_document(doc);
00117 TEST_EQUAL(db.get_doccount(), docs + 2);
00118 db.cancel_transaction();
00119
00120 TEST_EQUAL(db.get_doccount(), docs + 1);
00121 TEST(db.term_exists("pending_update"));
00122 Xapian::Document doc_out = db.get_document(docid);
00123 TEST_EQUAL(doc_out.get_data(), "pending");
00124
00125 return true;
00126 }