gecko-dev/storage/test/gtest/test_AsXXX_helpers.cpp

116 строки
3.2 KiB
C++
Исходник Обычный вид История

/*
*Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "storage_test_harness.h"
#include "mozIStorageRow.h"
#include "mozIStorageResultSet.h"
/**
* This file tests AsXXX (AsInt32, AsInt64, ...) helpers.
*/
////////////////////////////////////////////////////////////////////////////////
//// Event Loop Spinning
class Spinner : public AsyncStatementSpinner
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_ASYNCSTATEMENTSPINNER
Spinner() {}
protected:
~Spinner() override = default;
};
NS_IMPL_ISUPPORTS_INHERITED0(Spinner,
AsyncStatementSpinner)
NS_IMETHODIMP
Spinner::HandleResult(mozIStorageResultSet *aResultSet)
{
nsCOMPtr<mozIStorageRow> row;
do_check_true(NS_SUCCEEDED(aResultSet->GetNextRow(getter_AddRefs(row))) && row);
do_check_eq(row->AsInt32(0), 0);
do_check_eq(row->AsInt64(0), 0);
do_check_eq(row->AsDouble(0), 0.0);
uint32_t len = 100;
do_check_eq(row->AsSharedUTF8String(0, &len), (const char*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(row->AsSharedWString(0, &len), (const char16_t*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(row->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
do_check_eq(len, 0);
do_check_eq(row->IsNull(0), true);
return NS_OK;
}
Bug 1315138 - gtestify storage/test/*.cpp. r=mak,erahm. This change is mostly straightforward, except for the following. - It removes all the printing from the do_check_* macros because gtest macros do appropriate printing. - test_StatementCache.cpp needs some special gtest magic for the type parameterization. - It merges the four tests in test_unlock_notify.cpp because they rely on being executed in order, and so aren't independent. - storage_test_harness_tail.h is no longer necessary because gtest provides the test looping functionality. - It uses #include and the preprocessor to remove the duplication between test_deadlock_detector.cpp and xpcom/tests/DeadlockDetector.cpp. - It makes the test in test_service_init_background_thread.cpp a death test to force it to be the first storage gtest, because it fails otherwise. - It adds code to undo the SQLite mutex hooking as necessary, so that tests don't interfere with each other. - It de-virtualizes Spinner's destructor (as identified in bug 1318282). --HG-- rename : storage/test/storage_test_harness.h => storage/test/gtest/storage_test_harness.h rename : storage/test/test_AsXXX_helpers.cpp => storage/test/gtest/test_AsXXX_helpers.cpp rename : storage/test/test_StatementCache.cpp => storage/test/gtest/test_StatementCache.cpp rename : storage/test/test_asyncStatementExecution_transaction.cpp => storage/test/gtest/test_asyncStatementExecution_transaction.cpp rename : storage/test/test_async_callbacks_with_spun_event_loops.cpp => storage/test/gtest/test_async_callbacks_with_spun_event_loops.cpp rename : storage/test/test_binding_params.cpp => storage/test/gtest/test_binding_params.cpp rename : storage/test/test_deadlock_detector.cpp => storage/test/gtest/test_deadlock_detector.cpp rename : storage/test/test_file_perms.cpp => storage/test/gtest/test_file_perms.cpp rename : storage/test/test_mutex.cpp => storage/test/gtest/test_mutex.cpp rename : storage/test/test_service_init_background_thread.cpp => storage/test/gtest/test_service_init_background_thread.cpp rename : storage/test/test_statement_scoper.cpp => storage/test/gtest/test_statement_scoper.cpp rename : storage/test/test_transaction_helper.cpp => storage/test/gtest/test_transaction_helper.cpp rename : storage/test/test_true_async.cpp => storage/test/gtest/test_true_async.cpp rename : storage/test/test_unlock_notify.cpp => storage/test/gtest/test_unlock_notify.cpp extra : rebase_source : dbb695c112564efa1945116be1a8435988982e74
2016-11-11 01:59:23 +03:00
TEST(storage_AsXXX_helpers, NULLFallback)
{
nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
nsCOMPtr<mozIStorageStatement> stmt;
(void)db->CreateStatement(NS_LITERAL_CSTRING(
"SELECT NULL"
), getter_AddRefs(stmt));
nsCOMPtr<mozIStorageValueArray> valueArray = do_QueryInterface(stmt);
do_check_true(valueArray);
bool hasMore;
do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore);
do_check_eq(stmt->AsInt32(0), 0);
do_check_eq(stmt->AsInt64(0), 0);
do_check_eq(stmt->AsDouble(0), 0.0);
uint32_t len = 100;
do_check_eq(stmt->AsSharedUTF8String(0, &len), (const char*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(stmt->AsSharedWString(0, &len), (const char16_t*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(stmt->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
do_check_eq(len, 0);
do_check_eq(stmt->IsNull(0), true);
do_check_eq(valueArray->AsInt32(0), 0);
do_check_eq(valueArray->AsInt64(0), 0);
do_check_eq(valueArray->AsDouble(0), 0.0);
len = 100;
do_check_eq(valueArray->AsSharedUTF8String(0, &len), (const char*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(valueArray->AsSharedWString(0, &len), (const char16_t*)nullptr);
do_check_eq(len, 0);
len = 100;
do_check_eq(valueArray->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
do_check_eq(len, 0);
do_check_eq(valueArray->IsNull(0), true);
}
Bug 1315138 - gtestify storage/test/*.cpp. r=mak,erahm. This change is mostly straightforward, except for the following. - It removes all the printing from the do_check_* macros because gtest macros do appropriate printing. - test_StatementCache.cpp needs some special gtest magic for the type parameterization. - It merges the four tests in test_unlock_notify.cpp because they rely on being executed in order, and so aren't independent. - storage_test_harness_tail.h is no longer necessary because gtest provides the test looping functionality. - It uses #include and the preprocessor to remove the duplication between test_deadlock_detector.cpp and xpcom/tests/DeadlockDetector.cpp. - It makes the test in test_service_init_background_thread.cpp a death test to force it to be the first storage gtest, because it fails otherwise. - It adds code to undo the SQLite mutex hooking as necessary, so that tests don't interfere with each other. - It de-virtualizes Spinner's destructor (as identified in bug 1318282). --HG-- rename : storage/test/storage_test_harness.h => storage/test/gtest/storage_test_harness.h rename : storage/test/test_AsXXX_helpers.cpp => storage/test/gtest/test_AsXXX_helpers.cpp rename : storage/test/test_StatementCache.cpp => storage/test/gtest/test_StatementCache.cpp rename : storage/test/test_asyncStatementExecution_transaction.cpp => storage/test/gtest/test_asyncStatementExecution_transaction.cpp rename : storage/test/test_async_callbacks_with_spun_event_loops.cpp => storage/test/gtest/test_async_callbacks_with_spun_event_loops.cpp rename : storage/test/test_binding_params.cpp => storage/test/gtest/test_binding_params.cpp rename : storage/test/test_deadlock_detector.cpp => storage/test/gtest/test_deadlock_detector.cpp rename : storage/test/test_file_perms.cpp => storage/test/gtest/test_file_perms.cpp rename : storage/test/test_mutex.cpp => storage/test/gtest/test_mutex.cpp rename : storage/test/test_service_init_background_thread.cpp => storage/test/gtest/test_service_init_background_thread.cpp rename : storage/test/test_statement_scoper.cpp => storage/test/gtest/test_statement_scoper.cpp rename : storage/test/test_transaction_helper.cpp => storage/test/gtest/test_transaction_helper.cpp rename : storage/test/test_true_async.cpp => storage/test/gtest/test_true_async.cpp rename : storage/test/test_unlock_notify.cpp => storage/test/gtest/test_unlock_notify.cpp extra : rebase_source : dbb695c112564efa1945116be1a8435988982e74
2016-11-11 01:59:23 +03:00
TEST(storage_AsXXX_helpers, asyncNULLFallback)
{
nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
nsCOMPtr<mozIStorageAsyncStatement> stmt;
(void)db->CreateAsyncStatement(NS_LITERAL_CSTRING(
"SELECT NULL"
), getter_AddRefs(stmt));
nsCOMPtr<mozIStoragePendingStatement> pendingStmt;
do_check_true(NS_SUCCEEDED(stmt->ExecuteAsync(nullptr, getter_AddRefs(pendingStmt))));
do_check_true(pendingStmt);
stmt->Finalize();
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<Spinner> asyncSpin(new Spinner());
db->AsyncClose(asyncSpin);
asyncSpin->SpinUntilCompleted();
}