michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "storage_test_harness.h" michael@0: michael@0: #include "mozStorageHelper.h" michael@0: michael@0: /** michael@0: * This file test our statement scoper in mozStorageHelper.h. michael@0: */ michael@0: michael@0: void michael@0: test_automatic_reset() michael@0: { michael@0: nsCOMPtr db(getMemoryDatabase()); michael@0: michael@0: // Need to create a table to populate sqlite_master with an entry. michael@0: (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING( michael@0: "CREATE TABLE test (id INTEGER PRIMARY KEY)" michael@0: )); michael@0: michael@0: nsCOMPtr stmt; michael@0: (void)db->CreateStatement(NS_LITERAL_CSTRING( michael@0: "SELECT * FROM sqlite_master" michael@0: ), getter_AddRefs(stmt)); michael@0: michael@0: // Reality check - make sure we start off in the right state. michael@0: int32_t state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY); michael@0: michael@0: // Start executing the statement, which will put it into an executing state. michael@0: { michael@0: mozStorageStatementScoper scoper(stmt); michael@0: bool hasMore; michael@0: do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore))); michael@0: michael@0: // Reality check that we are executing. michael@0: state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == michael@0: mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING); michael@0: } michael@0: michael@0: // And we should be ready again. michael@0: state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY); michael@0: } michael@0: michael@0: void michael@0: test_Abandon() michael@0: { michael@0: nsCOMPtr db(getMemoryDatabase()); michael@0: michael@0: // Need to create a table to populate sqlite_master with an entry. michael@0: (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING( michael@0: "CREATE TABLE test (id INTEGER PRIMARY KEY)" michael@0: )); michael@0: michael@0: nsCOMPtr stmt; michael@0: (void)db->CreateStatement(NS_LITERAL_CSTRING( michael@0: "SELECT * FROM sqlite_master" michael@0: ), getter_AddRefs(stmt)); michael@0: michael@0: // Reality check - make sure we start off in the right state. michael@0: int32_t state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY); michael@0: michael@0: // Start executing the statement, which will put it into an executing state. michael@0: { michael@0: mozStorageStatementScoper scoper(stmt); michael@0: bool hasMore; michael@0: do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore))); michael@0: michael@0: // Reality check that we are executing. michael@0: state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == michael@0: mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING); michael@0: michael@0: // And call Abandon. We should not reset now when we fall out of scope. michael@0: scoper.Abandon(); michael@0: } michael@0: michael@0: // And we should still be executing. michael@0: state = -1; michael@0: (void)stmt->GetState(&state); michael@0: do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING); michael@0: } michael@0: michael@0: void (*gTests[])(void) = { michael@0: test_automatic_reset, michael@0: test_Abandon, michael@0: }; michael@0: michael@0: const char *file = __FILE__; michael@0: #define TEST_NAME "statement scoper" michael@0: #define TEST_FILE file michael@0: #include "storage_test_harness_tail.h"