storage/test/test_statement_scoper.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "storage_test_harness.h"
michael@0 8
michael@0 9 #include "mozStorageHelper.h"
michael@0 10
michael@0 11 /**
michael@0 12 * This file test our statement scoper in mozStorageHelper.h.
michael@0 13 */
michael@0 14
michael@0 15 void
michael@0 16 test_automatic_reset()
michael@0 17 {
michael@0 18 nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
michael@0 19
michael@0 20 // Need to create a table to populate sqlite_master with an entry.
michael@0 21 (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
michael@0 22 "CREATE TABLE test (id INTEGER PRIMARY KEY)"
michael@0 23 ));
michael@0 24
michael@0 25 nsCOMPtr<mozIStorageStatement> stmt;
michael@0 26 (void)db->CreateStatement(NS_LITERAL_CSTRING(
michael@0 27 "SELECT * FROM sqlite_master"
michael@0 28 ), getter_AddRefs(stmt));
michael@0 29
michael@0 30 // Reality check - make sure we start off in the right state.
michael@0 31 int32_t state = -1;
michael@0 32 (void)stmt->GetState(&state);
michael@0 33 do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
michael@0 34
michael@0 35 // Start executing the statement, which will put it into an executing state.
michael@0 36 {
michael@0 37 mozStorageStatementScoper scoper(stmt);
michael@0 38 bool hasMore;
michael@0 39 do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)));
michael@0 40
michael@0 41 // Reality check that we are executing.
michael@0 42 state = -1;
michael@0 43 (void)stmt->GetState(&state);
michael@0 44 do_check_true(state ==
michael@0 45 mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
michael@0 46 }
michael@0 47
michael@0 48 // And we should be ready again.
michael@0 49 state = -1;
michael@0 50 (void)stmt->GetState(&state);
michael@0 51 do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
michael@0 52 }
michael@0 53
michael@0 54 void
michael@0 55 test_Abandon()
michael@0 56 {
michael@0 57 nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
michael@0 58
michael@0 59 // Need to create a table to populate sqlite_master with an entry.
michael@0 60 (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
michael@0 61 "CREATE TABLE test (id INTEGER PRIMARY KEY)"
michael@0 62 ));
michael@0 63
michael@0 64 nsCOMPtr<mozIStorageStatement> stmt;
michael@0 65 (void)db->CreateStatement(NS_LITERAL_CSTRING(
michael@0 66 "SELECT * FROM sqlite_master"
michael@0 67 ), getter_AddRefs(stmt));
michael@0 68
michael@0 69 // Reality check - make sure we start off in the right state.
michael@0 70 int32_t state = -1;
michael@0 71 (void)stmt->GetState(&state);
michael@0 72 do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
michael@0 73
michael@0 74 // Start executing the statement, which will put it into an executing state.
michael@0 75 {
michael@0 76 mozStorageStatementScoper scoper(stmt);
michael@0 77 bool hasMore;
michael@0 78 do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)));
michael@0 79
michael@0 80 // Reality check that we are executing.
michael@0 81 state = -1;
michael@0 82 (void)stmt->GetState(&state);
michael@0 83 do_check_true(state ==
michael@0 84 mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
michael@0 85
michael@0 86 // And call Abandon. We should not reset now when we fall out of scope.
michael@0 87 scoper.Abandon();
michael@0 88 }
michael@0 89
michael@0 90 // And we should still be executing.
michael@0 91 state = -1;
michael@0 92 (void)stmt->GetState(&state);
michael@0 93 do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
michael@0 94 }
michael@0 95
michael@0 96 void (*gTests[])(void) = {
michael@0 97 test_automatic_reset,
michael@0 98 test_Abandon,
michael@0 99 };
michael@0 100
michael@0 101 const char *file = __FILE__;
michael@0 102 #define TEST_NAME "statement scoper"
michael@0 103 #define TEST_FILE file
michael@0 104 #include "storage_test_harness_tail.h"

mercurial