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