tor-browser

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

TestLogging.cpp (1292B)


      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 
      9 #include "SandboxLogging.h"
     10 
     11 #include <errno.h>
     12 
     13 namespace mozilla {
     14 
     15 TEST(SandboxLogging, ErrorName1)
     16 {
     17  char buf[32];
     18  ssize_t n = GetLibcErrorName(buf, sizeof(buf), EINVAL);
     19  EXPECT_EQ(n, 6);
     20  EXPECT_STREQ(buf, "EINVAL");
     21 }
     22 
     23 TEST(SandboxLogging, ErrorName2)
     24 {
     25  char buf[32];
     26  ssize_t n = GetLibcErrorName(buf, sizeof(buf), EIO);
     27  EXPECT_EQ(n, 3);
     28  EXPECT_STREQ(buf, "EIO");
     29 }
     30 
     31 TEST(SandboxLogging, ErrorName3)
     32 {
     33  char buf[32];
     34  ssize_t n = GetLibcErrorName(buf, sizeof(buf), ESTALE);
     35  EXPECT_EQ(n, 6);
     36  EXPECT_STREQ(buf, "ESTALE");
     37 }
     38 
     39 TEST(SandboxLogging, ErrorNameFail)
     40 {
     41  char buf[32];
     42  ssize_t n = GetLibcErrorName(buf, sizeof(buf), 4095);
     43  EXPECT_EQ(n, 10);
     44  EXPECT_STREQ(buf, "error 4095");
     45 }
     46 
     47 TEST(SandboxLogging, ErrorNameTrunc)
     48 {
     49  char buf[] = "++++++++";
     50  ssize_t n = GetLibcErrorName(buf, 3, EINVAL);
     51  EXPECT_EQ(n, 6);
     52  EXPECT_STREQ(buf, "EI");
     53  EXPECT_STREQ(buf + 3, "+++++");
     54 }
     55 
     56 }  // namespace mozilla