tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestHelpers.h (3037B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_FS_TEST_GTEST_TESTHELPERS_H_
      8 #define DOM_FS_TEST_GTEST_TESTHELPERS_H_
      9 
     10 #include "ErrorList.h"
     11 #include "gtest/gtest.h"
     12 #include "mozilla/ErrorNames.h"
     13 #include "mozilla/dom/FileSystemTypes.h"
     14 #include "mozilla/dom/quota/QuotaCommon.h"
     15 #include "mozilla/dom/quota/ResultExtensions.h"
     16 
     17 namespace testing::internal {
     18 
     19 GTEST_API_ ::testing::AssertionResult CmpHelperSTREQ(const char* s1_expression,
     20                                                     const char* s2_expression,
     21                                                     const nsAString& s1,
     22                                                     const nsAString& s2);
     23 
     24 GTEST_API_ ::testing::AssertionResult CmpHelperSTREQ(const char* s1_expression,
     25                                                     const char* s2_expression,
     26                                                     const nsACString& s1,
     27                                                     const nsACString& s2);
     28 
     29 }  // namespace testing::internal
     30 
     31 #define ASSERT_NSEQ(lhs, rhs) \
     32  ASSERT_STREQ(GetStaticErrorName((lhs)), GetStaticErrorName((rhs)))
     33 
     34 #define TEST_TRY_META(tempVar, expr)            \
     35  auto MOZ_REMOVE_PAREN(tempVar) = (expr);      \
     36  ASSERT_TRUE(MOZ_REMOVE_PAREN(tempVar).isOk()) \
     37  << GetStaticErrorName(                        \
     38      mozilla::ToNSResult(MOZ_REMOVE_PAREN(tempVar).unwrapErr()));
     39 
     40 #define TEST_TRY(expr) TEST_TRY_META(MOZ_UNIQUE_VAR(testVar), expr)
     41 
     42 #define TEST_TRY_UNWRAP_META(tempVar, target, expr)                \
     43  auto MOZ_REMOVE_PAREN(tempVar) = (expr);                         \
     44  ASSERT_TRUE(MOZ_REMOVE_PAREN(tempVar).isOk())                    \
     45  << GetStaticErrorName(                                           \
     46      mozilla::ToNSResult(MOZ_REMOVE_PAREN(tempVar).unwrapErr())); \
     47  MOZ_REMOVE_PAREN(target) = MOZ_REMOVE_PAREN(tempVar).unwrap();
     48 
     49 #define TEST_TRY_UNWRAP_ERR_META(tempVar, target, expr) \
     50  auto MOZ_REMOVE_PAREN(tempVar) = (expr);              \
     51  ASSERT_TRUE(MOZ_REMOVE_PAREN(tempVar).isErr());       \
     52  MOZ_REMOVE_PAREN(target) =                            \
     53      mozilla::ToNSResult(MOZ_REMOVE_PAREN(tempVar).unwrapErr());
     54 
     55 #define TEST_TRY_UNWRAP(target, expr) \
     56  TEST_TRY_UNWRAP_META(MOZ_UNIQUE_VAR(testVar), target, expr)
     57 
     58 #define TEST_TRY_UNWRAP_ERR(target, expr) \
     59  TEST_TRY_UNWRAP_ERR_META(MOZ_UNIQUE_VAR(testVar), target, expr)
     60 
     61 namespace mozilla::dom {
     62 
     63 namespace quota {
     64 
     65 struct ClientMetadata;
     66 struct OriginMetadata;
     67 
     68 }  // namespace quota
     69 
     70 namespace fs::test {
     71 
     72 quota::OriginMetadata GetTestOriginMetadata();
     73 quota::ClientMetadata GetTestClientMetadata();
     74 
     75 const Origin& GetTestOrigin();
     76 
     77 }  // namespace fs::test
     78 }  // namespace mozilla::dom
     79 
     80 #endif  // DOM_FS_TEST_GTEST_TESTHELPERS_H_