tor-browser

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

TestSmartCrashTrimmer.cpp (1457B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include <stdio.h>
      8 #include <string.h>
      9 
     10 #include "gtest/gtest.h"
     11 #include "mozilla/Sprintf.h"
     12 #include "nsContentSecurityUtils.h"
     13 #include "nsStringFwd.h"
     14 #include "nsTString.h"
     15 
     16 #define ASSERT_STRCMP(first, second) ASSERT_TRUE(strcmp(first, second) == 0);
     17 
     18 #define ASSERT_STRCMP_AND_PRINT(first, second)             \
     19  fprintf(stderr, "First: %s\n", first);                   \
     20  fprintf(stderr, "Second: %s\n", second);                 \
     21  fprintf(stderr, "strcmp = %i\n", strcmp(first, second)); \
     22  ASSERT_EQUAL(first, second);
     23 
     24 TEST(SmartCrashTrimmer, Test)
     25 {
     26  static_assert(sPrintfCrashReasonSize == 1024);
     27  {
     28    auto ret = nsContentSecurityUtils::SmartFormatCrashString(
     29        std::string(1025, '.').c_str());
     30    ASSERT_EQ(strlen(ret), 1023ul);
     31  }
     32 
     33  {
     34    auto ret = nsContentSecurityUtils::SmartFormatCrashString(
     35        std::string(1025, '.').c_str(), std::string(1025, 'A').c_str(),
     36        "Hello %s world %s!");
     37    char expected[1025];
     38    SprintfLiteral(expected, "Hello %s world AAAAAAAAAAAAAAAAAAAAAAAAA!",
     39                   std::string(984, '.').c_str());
     40    ASSERT_STRCMP(ret.get(), expected);
     41  }
     42 }