tor-browser

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

gtests.cc (1100B)


      1 #include "nspr.h"
      2 #include "nss.h"
      3 
      4 #include <cstdlib>
      5 
      6 #define GTEST_HAS_RTTI 0
      7 #include "gtest/gtest.h"
      8 
      9 // Tests are passed the location of their source directory
     10 // so that they can load extra resources from there.
     11 std::string g_source_dir;
     12 
     13 void usage(const char *progname) {
     14  PR_fprintf(PR_STDERR, "Usage: %s [-s <dir>] [-d <dir> [-w]]\n", progname);
     15  exit(2);
     16 }
     17 
     18 int main(int argc, char **argv) {
     19  ::testing::InitGoogleTest(&argc, argv);
     20 
     21  const char *workdir = "";
     22  uint32_t flags = NSS_INIT_READONLY;
     23 
     24  for (int i = 0; i < argc; i++) {
     25    if (!strcmp(argv[i], "-s")) {
     26      if (i + 1 >= argc) {
     27        usage(argv[0]);
     28      }
     29      i++;
     30      g_source_dir = argv[i];
     31    } else if (!strcmp(argv[i], "-d")) {
     32      if (i + 1 >= argc) {
     33        usage(argv[0]);
     34      }
     35      i++;
     36      workdir = argv[i];
     37    } else if (!strcmp(argv[i], "-w")) {
     38      flags &= ~NSS_INIT_READONLY;
     39    }
     40  }
     41 
     42  if (NSS_Initialize(workdir, "", "", SECMOD_DB, flags) != SECSuccess) {
     43    return 1;
     44  }
     45  int rv = RUN_ALL_TESTS();
     46 
     47  if (NSS_Shutdown() != SECSuccess) {
     48    return 1;
     49  }
     50 
     51  return rv;
     52 }