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"
12 * This file test our statement scoper in mozStorageHelper.h.
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)"
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.
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
);
39 do_check_true(NS_SUCCEEDED(stmt
->ExecuteStep(&hasMore
)));
41 // Reality check that we are executing.
43 (void)stmt
->GetState(&state
);
44 do_check_true(state
==
45 mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING
);
48 // And we should be ready again.
50 (void)stmt
->GetState(&state
);
51 do_check_true(state
== mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY
);
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)"
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.
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
);
78 do_check_true(NS_SUCCEEDED(stmt
->ExecuteStep(&hasMore
)));
80 // Reality check that we are executing.
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.
90 // And we should still be executing.
92 (void)stmt
->GetState(&state
);
93 do_check_true(state
== mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING
);
96 void (*gTests
[])(void) = {
101 const char *file
= __FILE__
;
102 #define TEST_NAME "statement scoper"
103 #define TEST_FILE file
104 #include "storage_test_harness_tail.h"