tor-browser

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

TestStringifyUtils.cpp (1314B)


      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 #include "gtest/gtest.h"
      8 #include "mozilla/dom/quota/StringifyUtils.h"
      9 
     10 namespace mozilla::dom::quota {
     11 
     12 class B;
     13 class A : public Stringifyable {
     14 public:
     15  A() : mB(nullptr) {}
     16  virtual void DoStringify(nsACString& aData) override;
     17  void setB(B* aB) { mB = aB; }
     18 
     19 private:
     20  B* mB;
     21 };
     22 
     23 class B : public Stringifyable {
     24 public:
     25  B() : mA(nullptr) {}
     26  virtual void DoStringify(nsACString& aData) override;
     27  void setA(A* aA) { mA = aA; }
     28 
     29 private:
     30  A* mA;
     31 };
     32 
     33 void A::DoStringify(nsACString& aData) {
     34  aData.Append("Class A content."_ns);
     35  mB->Stringify(aData);
     36 }
     37 
     38 void B::DoStringify(nsACString& aData) {
     39  aData.Append("Class B content.");
     40  mA->Stringify(aData);
     41 }
     42 
     43 TEST(DOM_Quota_StringifyUtils, Nested)
     44 {
     45  A a1;
     46  A a2;
     47  B b;
     48  a1.setB(&b);
     49  b.setA(&a2);
     50  a2.setB(&b);
     51  nsCString msg;
     52  a1.Stringify(msg);
     53 
     54  EXPECT_EQ(
     55      0, strcmp("{Class A content.{Class B content.{Class A content.(...)}}}",
     56                msg.get()));
     57 }
     58 
     59 }  // namespace mozilla::dom::quota