LCOV - code coverage report
Current view: directory - storage/test - test_statement_scoper.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 39 39 100.0 %
Date: 2012-06-02 Functions: 2 2 100.0 %

       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                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is storage test code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Mozilla Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "storage_test_harness.h"
      41                 : 
      42                 : #include "mozStorageHelper.h"
      43                 : 
      44                 : /**
      45                 :  * This file test our statement scoper in mozStorageHelper.h.
      46                 :  */
      47                 : 
      48                 : void
      49               1 : test_automatic_reset()
      50                 : {
      51               2 :   nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
      52                 : 
      53                 :   // Need to create a table to populate sqlite_master with an entry.
      54               2 :   (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
      55                 :     "CREATE TABLE test (id INTEGER PRIMARY KEY)"
      56               1 :   ));
      57                 : 
      58               2 :   nsCOMPtr<mozIStorageStatement> stmt;
      59               2 :   (void)db->CreateStatement(NS_LITERAL_CSTRING(
      60                 :     "SELECT * FROM sqlite_master"
      61               2 :   ), getter_AddRefs(stmt));
      62                 : 
      63                 :   // Reality check - make sure we start off in the right state.
      64               1 :   PRInt32 state = -1;
      65               1 :   (void)stmt->GetState(&state);
      66               1 :   do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
      67                 : 
      68                 :   // Start executing the statement, which will put it into an executing state.
      69                 :   {
      70               2 :     mozStorageStatementScoper scoper(stmt);
      71                 :     bool hasMore;
      72               1 :     do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)));
      73                 : 
      74                 :     // Reality check that we are executing.
      75               1 :     state = -1;
      76               1 :     (void)stmt->GetState(&state);
      77               1 :     do_check_true(state ==
      78                 :                   mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
      79                 :   }
      80                 : 
      81                 :   // And we should be ready again.
      82               1 :   state = -1;
      83               1 :   (void)stmt->GetState(&state);
      84               1 :   do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
      85               1 : }
      86                 : 
      87                 : void
      88               1 : test_Abandon()
      89                 : {
      90               2 :   nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
      91                 : 
      92                 :   // Need to create a table to populate sqlite_master with an entry.
      93               2 :   (void)db->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
      94                 :     "CREATE TABLE test (id INTEGER PRIMARY KEY)"
      95               1 :   ));
      96                 : 
      97               2 :   nsCOMPtr<mozIStorageStatement> stmt;
      98               2 :   (void)db->CreateStatement(NS_LITERAL_CSTRING(
      99                 :     "SELECT * FROM sqlite_master"
     100               2 :   ), getter_AddRefs(stmt));
     101                 : 
     102                 :   // Reality check - make sure we start off in the right state.
     103               1 :   PRInt32 state = -1;
     104               1 :   (void)stmt->GetState(&state);
     105               1 :   do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_READY);
     106                 : 
     107                 :   // Start executing the statement, which will put it into an executing state.
     108                 :   {
     109               2 :     mozStorageStatementScoper scoper(stmt);
     110                 :     bool hasMore;
     111               1 :     do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)));
     112                 : 
     113                 :     // Reality check that we are executing.
     114               1 :     state = -1;
     115               1 :     (void)stmt->GetState(&state);
     116               1 :     do_check_true(state ==
     117                 :                   mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
     118                 : 
     119                 :     // And call Abandon.  We should not reset now when we fall out of scope.
     120               1 :     scoper.Abandon();
     121                 :   }
     122                 : 
     123                 :   // And we should still be executing.
     124               1 :   state = -1;
     125               1 :   (void)stmt->GetState(&state);
     126               1 :   do_check_true(state == mozIStorageStatement::MOZ_STORAGE_STATEMENT_EXECUTING);
     127               1 : }
     128                 : 
     129                 : void (*gTests[])(void) = {
     130                 :   test_automatic_reset,
     131                 :   test_Abandon,
     132                 : };
     133                 : 
     134                 : const char *file = __FILE__;
     135                 : #define TEST_NAME "statement scoper"
     136                 : #define TEST_FILE file
     137                 : #include "storage_test_harness_tail.h"

Generated by: LCOV version 1.7