Bumping manifests a=b2g-bump
[gecko.git] / storage / test / test_AsXXX_helpers.cpp
blob6067bf0ca18d3d809a50d72f08f152a2105109d3
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.
14 ////////////////////////////////////////////////////////////////////////////////
15 //// Event Loop Spinning
17 class Spinner : public AsyncStatementSpinner
19 public:
20 NS_DECL_ISUPPORTS_INHERITED
21 NS_DECL_ASYNCSTATEMENTSPINNER
22 Spinner() {}
23 protected:
24 virtual ~Spinner() {}
27 NS_IMPL_ISUPPORTS_INHERITED0(Spinner,
28 AsyncStatementSpinner)
30 NS_IMETHODIMP
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);
40 uint32_t len = 100;
41 do_check_eq(row->AsSharedUTF8String(0, &len), (const char*)nullptr);
42 do_check_eq(len, 0);
43 len = 100;
44 do_check_eq(row->AsSharedWString(0, &len), (const char16_t*)nullptr);
45 do_check_eq(len, 0);
46 len = 100;
47 do_check_eq(row->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
48 do_check_eq(len, 0);
50 do_check_eq(row->IsNull(0), true);
51 return NS_OK;
54 void
55 test_NULLFallback()
57 nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
59 nsCOMPtr<mozIStorageStatement> stmt;
60 (void)db->CreateStatement(NS_LITERAL_CSTRING(
61 "SELECT NULL"
62 ), getter_AddRefs(stmt));
64 nsCOMPtr<mozIStorageValueArray> valueArray = do_QueryInterface(stmt);
65 do_check_true(valueArray);
67 bool hasMore;
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);
73 uint32_t len = 100;
74 do_check_eq(stmt->AsSharedUTF8String(0, &len), (const char*)nullptr);
75 do_check_eq(len, 0);
76 len = 100;
77 do_check_eq(stmt->AsSharedWString(0, &len), (const char16_t*)nullptr);
78 do_check_eq(len, 0);
79 len = 100;
80 do_check_eq(stmt->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
81 do_check_eq(len, 0);
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);
87 len = 100;
88 do_check_eq(valueArray->AsSharedUTF8String(0, &len), (const char*)nullptr);
89 do_check_eq(len, 0);
90 len = 100;
91 do_check_eq(valueArray->AsSharedWString(0, &len), (const char16_t*)nullptr);
92 do_check_eq(len, 0);
93 len = 100;
94 do_check_eq(valueArray->AsSharedBlob(0, &len), (const uint8_t*)nullptr);
95 do_check_eq(len, 0);
96 do_check_eq(valueArray->IsNull(0), true);
99 void
100 test_asyncNULLFallback()
102 nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
104 nsCOMPtr<mozIStorageAsyncStatement> stmt;
105 (void)db->CreateAsyncStatement(NS_LITERAL_CSTRING(
106 "SELECT NULL"
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);
112 stmt->Finalize();
113 nsRefPtr<Spinner> asyncSpin(new Spinner());
114 db->AsyncClose(asyncSpin);
115 asyncSpin->SpinUntilCompleted();
119 void (*gTests[])(void) = {
120 test_NULLFallback
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"