2 *Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 #include "storage_test_harness.h"
7 #include "mozIStorageRow.h"
8 #include "mozIStorageResultSet.h"
11 * This file tests AsXXX (AsInt32, AsInt64, ...) helpers.
14 ////////////////////////////////////////////////////////////////////////////////
15 //// Event Loop Spinning
17 class Spinner
: public AsyncStatementSpinner
20 NS_DECL_ISUPPORTS_INHERITED
21 NS_DECL_ASYNCSTATEMENTSPINNER
27 NS_IMPL_ISUPPORTS_INHERITED0(Spinner
,
28 AsyncStatementSpinner
)
31 Spinner::HandleResult(mozIStorageResultSet
*aResultSet
)
33 nsCOMPtr
<mozIStorageRow
> row
;
34 do_check_true(NS_SUCCEEDED(aResultSet
->GetNextRow(getter_AddRefs(row
))) && row
);
36 do_check_eq(row
->AsInt32(0), 0);
37 do_check_eq(row
->AsInt64(0), 0);
38 do_check_eq(row
->AsDouble(0), 0.0);
41 do_check_eq(row
->AsSharedUTF8String(0, &len
), (const char*)nullptr);
44 do_check_eq(row
->AsSharedWString(0, &len
), (const char16_t
*)nullptr);
47 do_check_eq(row
->AsSharedBlob(0, &len
), (const uint8_t*)nullptr);
50 do_check_eq(row
->IsNull(0), true);
57 nsCOMPtr
<mozIStorageConnection
> db(getMemoryDatabase());
59 nsCOMPtr
<mozIStorageStatement
> stmt
;
60 (void)db
->CreateStatement(NS_LITERAL_CSTRING(
62 ), getter_AddRefs(stmt
));
64 nsCOMPtr
<mozIStorageValueArray
> valueArray
= do_QueryInterface(stmt
);
65 do_check_true(valueArray
);
68 do_check_true(NS_SUCCEEDED(stmt
->ExecuteStep(&hasMore
)) && hasMore
);
70 do_check_eq(stmt
->AsInt32(0), 0);
71 do_check_eq(stmt
->AsInt64(0), 0);
72 do_check_eq(stmt
->AsDouble(0), 0.0);
74 do_check_eq(stmt
->AsSharedUTF8String(0, &len
), (const char*)nullptr);
77 do_check_eq(stmt
->AsSharedWString(0, &len
), (const char16_t
*)nullptr);
80 do_check_eq(stmt
->AsSharedBlob(0, &len
), (const uint8_t*)nullptr);
82 do_check_eq(stmt
->IsNull(0), true);
84 do_check_eq(valueArray
->AsInt32(0), 0);
85 do_check_eq(valueArray
->AsInt64(0), 0);
86 do_check_eq(valueArray
->AsDouble(0), 0.0);
88 do_check_eq(valueArray
->AsSharedUTF8String(0, &len
), (const char*)nullptr);
91 do_check_eq(valueArray
->AsSharedWString(0, &len
), (const char16_t
*)nullptr);
94 do_check_eq(valueArray
->AsSharedBlob(0, &len
), (const uint8_t*)nullptr);
96 do_check_eq(valueArray
->IsNull(0), true);
100 test_asyncNULLFallback()
102 nsCOMPtr
<mozIStorageConnection
> db(getMemoryDatabase());
104 nsCOMPtr
<mozIStorageAsyncStatement
> stmt
;
105 (void)db
->CreateAsyncStatement(NS_LITERAL_CSTRING(
107 ), getter_AddRefs(stmt
));
109 nsCOMPtr
<mozIStoragePendingStatement
> pendingStmt
;
110 do_check_true(NS_SUCCEEDED(stmt
->ExecuteAsync(nullptr, getter_AddRefs(pendingStmt
))));
111 do_check_true(pendingStmt
);
113 nsRefPtr
<Spinner
> asyncSpin(new Spinner());
114 db
->AsyncClose(asyncSpin
);
115 asyncSpin
->SpinUntilCompleted();
119 void (*gTests
[])(void) = {
121 , test_asyncNULLFallback
124 const char *file
= __FILE__
;
125 #define TEST_NAME "AsXXX helpers"
126 #define TEST_FILE file
127 #include "storage_test_harness_tail.h"