storage/test/test_AsXXX_helpers.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  *Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 #include "storage_test_harness.h"
     7 #include "mozIStorageRow.h"
     8 #include "mozIStorageResultSet.h"
    10 /**
    11  * This file tests AsXXX (AsInt32, AsInt64, ...) helpers.
    12  */
    14 ////////////////////////////////////////////////////////////////////////////////
    15 //// Event Loop Spinning
    17 class Spinner : public AsyncStatementSpinner
    18 {
    19 public:
    20   NS_DECL_ISUPPORTS
    21   NS_DECL_ASYNCSTATEMENTSPINNER
    22   Spinner() {}
    23 };
    25 NS_IMPL_ISUPPORTS_INHERITED0(Spinner,
    26                              AsyncStatementSpinner)
    28 NS_IMETHODIMP
    29 Spinner::HandleResult(mozIStorageResultSet *aResultSet)
    30 {
    31   nsCOMPtr<mozIStorageRow> row;
    32   do_check_true(NS_SUCCEEDED(aResultSet->GetNextRow(getter_AddRefs(row))) && row);
    34   do_check_eq(row->AsInt32(0), 0);
    35   do_check_eq(row->AsInt64(0), 0);
    36   do_check_eq(row->AsDouble(0), 0.0);
    38   uint32_t len = 100;
    39   do_check_eq(row->AsSharedUTF8String(0, &len), (const char*)nullptr);
    40   do_check_eq(len, 0);
    41   len = 100;
    42   do_check_eq(row->AsSharedWString(0, &len), (const char16_t*)nullptr);
    43   do_check_eq(len, 0);
    44   len = 100;
    45   do_check_eq(row->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
    46   do_check_eq(len, 0);
    48   do_check_eq(row->IsNull(0), true);
    49   return NS_OK;
    50 }
    52 void
    53 test_NULLFallback()
    54 {
    55   nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
    57   nsCOMPtr<mozIStorageStatement> stmt;
    58   (void)db->CreateStatement(NS_LITERAL_CSTRING(
    59     "SELECT NULL"
    60   ), getter_AddRefs(stmt));
    62   nsCOMPtr<mozIStorageValueArray> valueArray = do_QueryInterface(stmt);
    63   do_check_true(valueArray);
    65   bool hasMore;
    66   do_check_true(NS_SUCCEEDED(stmt->ExecuteStep(&hasMore)) && hasMore);
    68   do_check_eq(stmt->AsInt32(0), 0);
    69   do_check_eq(stmt->AsInt64(0), 0);
    70   do_check_eq(stmt->AsDouble(0), 0.0);
    71   uint32_t len = 100;
    72   do_check_eq(stmt->AsSharedUTF8String(0, &len), (const char*)nullptr);
    73   do_check_eq(len, 0);
    74   len = 100;
    75   do_check_eq(stmt->AsSharedWString(0, &len), (const char16_t*)nullptr);
    76   do_check_eq(len, 0);
    77   len = 100;
    78   do_check_eq(stmt->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
    79   do_check_eq(len, 0);
    80   do_check_eq(stmt->IsNull(0), true);
    82   do_check_eq(valueArray->AsInt32(0), 0);
    83   do_check_eq(valueArray->AsInt64(0), 0);
    84   do_check_eq(valueArray->AsDouble(0), 0.0);
    85   len = 100;
    86   do_check_eq(valueArray->AsSharedUTF8String(0, &len), (const char*)nullptr);
    87   do_check_eq(len, 0);
    88   len = 100;
    89   do_check_eq(valueArray->AsSharedWString(0, &len), (const char16_t*)nullptr);
    90   do_check_eq(len, 0);
    91   len = 100;
    92   do_check_eq(valueArray->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
    93   do_check_eq(len, 0);
    94   do_check_eq(valueArray->IsNull(0), true);
    95 }
    97 void
    98 test_asyncNULLFallback()
    99 {
   100   nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
   102   nsCOMPtr<mozIStorageAsyncStatement> stmt;
   103   (void)db->CreateAsyncStatement(NS_LITERAL_CSTRING(
   104     "SELECT NULL"
   105   ), getter_AddRefs(stmt));
   107   nsCOMPtr<mozIStoragePendingStatement> pendingStmt;
   108   do_check_true(NS_SUCCEEDED(stmt->ExecuteAsync(nullptr, getter_AddRefs(pendingStmt))));
   109   do_check_true(pendingStmt);
   110   stmt->Finalize();
   111   nsRefPtr<Spinner> asyncSpin(new Spinner());
   112   db->AsyncClose(asyncSpin);
   113   asyncSpin->SpinUntilCompleted();
   115 }
   117 void (*gTests[])(void) = {
   118   test_NULLFallback
   119 , test_asyncNULLFallback
   120 };
   122 const char *file = __FILE__;
   123 #define TEST_NAME "AsXXX helpers"
   124 #define TEST_FILE file
   125 #include "storage_test_harness_tail.h"

mercurial