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