summaryrefslogtreecommitdiffstats
path: root/security/nss/gtests/common
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /security/nss/gtests/common
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'security/nss/gtests/common')
-rw-r--r--security/nss/gtests/common/Makefile41
-rw-r--r--security/nss/gtests/common/common.gyp35
-rw-r--r--security/nss/gtests/common/gtest.gypi35
-rw-r--r--security/nss/gtests/common/gtest.mk36
-rw-r--r--security/nss/gtests/common/gtests.cc22
-rw-r--r--security/nss/gtests/common/manifest.mn21
-rw-r--r--security/nss/gtests/common/scoped_ptrs.h61
7 files changed, 251 insertions, 0 deletions
diff --git a/security/nss/gtests/common/Makefile b/security/nss/gtests/common/Makefile
new file mode 100644
index 000000000..e17bc282c
--- /dev/null
+++ b/security/nss/gtests/common/Makefile
@@ -0,0 +1,41 @@
+#! gmake
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#######################################################################
+# (1) Include initial platform-independent assignments (MANDATORY). #
+#######################################################################
+
+include manifest.mn
+
+#######################################################################
+# (2) Include "global" configuration information. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/config.mk
+
+#######################################################################
+# (3) Include "component" configuration information. (OPTIONAL) #
+#######################################################################
+
+#######################################################################
+# (4) Include "local" platform-dependent assignments (OPTIONAL). #
+#######################################################################
+
+include gtest.mk
+
+#######################################################################
+# (5) Execute "global" rules. (OPTIONAL) #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/rules.mk
+
+#######################################################################
+# (6) Execute "component" rules. (OPTIONAL) #
+#######################################################################
+
+#######################################################################
+# (7) Execute "local" rules. (OPTIONAL). #
+#######################################################################
diff --git a/security/nss/gtests/common/common.gyp b/security/nss/gtests/common/common.gyp
new file mode 100644
index 000000000..c501eba6b
--- /dev/null
+++ b/security/nss/gtests/common/common.gyp
@@ -0,0 +1,35 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+{
+ 'includes': [
+ '../../coreconf/config.gypi',
+ 'gtest.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'gtests',
+ 'type': 'executable',
+ 'sources': [
+ 'gtests.cc'
+ ],
+ 'dependencies': [
+ '<(DEPTH)/exports.gyp:nss_exports',
+ '<(DEPTH)/lib/nss/nss.gyp:nss3',
+ '<(DEPTH)/lib/util/util.gyp:nssutil3',
+ '<(DEPTH)/lib/smime/smime.gyp:smime3',
+ '<(DEPTH)/gtests/google_test/google_test.gyp:gtest',
+ '<(DEPTH)/cmd/lib/lib.gyp:sectool'
+ ]
+ }
+ ],
+ 'target_defaults': {
+ 'include_dirs': [
+ '../../gtests/google_test/gtest/include',
+ '../../gtests/common'
+ ],
+ },
+ 'variables': {
+ 'module': 'nss'
+ }
+}
diff --git a/security/nss/gtests/common/gtest.gypi b/security/nss/gtests/common/gtest.gypi
new file mode 100644
index 000000000..c3bac327b
--- /dev/null
+++ b/security/nss/gtests/common/gtest.gypi
@@ -0,0 +1,35 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+{
+ 'includes': [
+ '../../coreconf/config.gypi'
+ ],
+ 'target_defaults': {
+ 'conditions': [
+ ['OS=="win"', {
+ 'libraries': [
+ '-lws2_32',
+ ],
+ }],
+ ['OS=="android"', {
+ 'libraries': [
+ '-lstdc++',
+ ],
+ }],
+ [ 'fuzz==1', {
+ 'defines': [
+ 'UNSAFE_FUZZER_MODE',
+ ],
+ }],
+ ],
+ 'msvs_settings': {
+ 'VCCLCompilerTool': {
+ 'ExceptionHandling': 1,
+ 'PreprocessorDefinitions': [
+ 'NOMINMAX',
+ ],
+ },
+ },
+ },
+}
diff --git a/security/nss/gtests/common/gtest.mk b/security/nss/gtests/common/gtest.mk
new file mode 100644
index 000000000..ecb324e67
--- /dev/null
+++ b/security/nss/gtests/common/gtest.mk
@@ -0,0 +1,36 @@
+#! gmake
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+include $(CORE_DEPTH)/cmd/platlibs.mk
+
+MKPROG = $(CCC)
+MKSHLIB = $(CCC) $(DSO_LDOPTS) $(DARWIN_SDK_SHLIBFLAGS)
+
+# gtests pick up errors with signed/unsigned comparisons on some platforms
+# even though we disabled -Wsign-compare.
+# This catches that by enabling the warning.
+# Only add -Wsign-compare if -Werror is enabled, lest we add it on the wrong
+# platform.
+ifeq (-Werror,$(filter -Werror -Wsign-compare,$(WARNING_CFLAGS)))
+WARNING_CFLAGS += -Wsign-compare
+endif
+WARNING_CFLAGS := $(filter-out -w44018,$(WARNING_CFLAGS))
+
+ifeq (WINNT,$(OS_ARCH))
+ # -EHsc because gtest has exception handlers
+ OS_CFLAGS += -EHsc -nologo
+ # http://www.suodenjoki.dk/us/archive/2010/min-max.htm
+ OS_CFLAGS += -DNOMINMAX
+
+ # Linking to winsock to get htonl
+ OS_LIBS += Ws2_32.lib
+
+ # On windows, we need to create the parent directory
+ # Needed because we include files from a subdirectory
+ MAKE_OBJDIR = $(INSTALL) -D $(dir $@)
+else
+ CXXFLAGS += -std=c++0x
+endif
diff --git a/security/nss/gtests/common/gtests.cc b/security/nss/gtests/common/gtests.cc
new file mode 100644
index 000000000..c51437cb4
--- /dev/null
+++ b/security/nss/gtests/common/gtests.cc
@@ -0,0 +1,22 @@
+#include "nspr.h"
+#include "nss.h"
+#include "ssl.h"
+
+#include <cstdlib>
+
+#define GTEST_HAS_RTTI 0
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ NSS_NoDB_Init(nullptr);
+ NSS_SetDomesticPolicy();
+ int rv = RUN_ALL_TESTS();
+
+ if (NSS_Shutdown() != SECSuccess) {
+ return 1;
+ }
+
+ return rv;
+}
diff --git a/security/nss/gtests/common/manifest.mn b/security/nss/gtests/common/manifest.mn
new file mode 100644
index 000000000..9834e42a0
--- /dev/null
+++ b/security/nss/gtests/common/manifest.mn
@@ -0,0 +1,21 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+CORE_DEPTH = ../..
+DEPTH = ../..
+MODULE = nss
+
+CPPSRCS = \
+ gtests.cc \
+ $(NULL)
+
+INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
+ -I$(CORE_DEPTH)/gtests/common
+
+REQUIRES = gtest
+
+EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX)
+
+# NOTE: this is not actually used but required to build gtests.o
+PROGRAM = gtests
diff --git a/security/nss/gtests/common/scoped_ptrs.h b/security/nss/gtests/common/scoped_ptrs.h
new file mode 100644
index 000000000..2a96ee94a
--- /dev/null
+++ b/security/nss/gtests/common/scoped_ptrs.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef scoped_ptrs_h__
+#define scoped_ptrs_h__
+
+#include <memory>
+#include "cert.h"
+#include "keyhi.h"
+#include "pk11pub.h"
+
+namespace nss_test {
+
+struct ScopedDelete {
+ void operator()(CERTCertificate* cert) { CERT_DestroyCertificate(cert); }
+ void operator()(CERTCertificateList* list) {
+ CERT_DestroyCertificateList(list);
+ }
+ void operator()(CERTCertList* list) { CERT_DestroyCertList(list); }
+ void operator()(CERTSubjectPublicKeyInfo* spki) {
+ SECKEY_DestroySubjectPublicKeyInfo(spki);
+ }
+ void operator()(PK11SlotInfo* slot) { PK11_FreeSlot(slot); }
+ void operator()(PK11SymKey* key) { PK11_FreeSymKey(key); }
+ void operator()(SECAlgorithmID* id) { SECOID_DestroyAlgorithmID(id, true); }
+ void operator()(SECItem* item) { SECITEM_FreeItem(item, true); }
+ void operator()(SECKEYPublicKey* key) { SECKEY_DestroyPublicKey(key); }
+ void operator()(SECKEYPrivateKey* key) { SECKEY_DestroyPrivateKey(key); }
+};
+
+template <class T>
+struct ScopedMaybeDelete {
+ void operator()(T* ptr) {
+ if (ptr) {
+ ScopedDelete del;
+ del(ptr);
+ }
+ }
+};
+
+#define SCOPED(x) typedef std::unique_ptr<x, ScopedMaybeDelete<x> > Scoped##x
+
+SCOPED(CERTCertificate);
+SCOPED(CERTCertificateList);
+SCOPED(CERTCertList);
+SCOPED(CERTSubjectPublicKeyInfo);
+SCOPED(PK11SlotInfo);
+SCOPED(PK11SymKey);
+SCOPED(SECAlgorithmID);
+SCOPED(SECItem);
+SCOPED(SECKEYPublicKey);
+SCOPED(SECKEYPrivateKey);
+
+#undef SCOPED
+
+} // namespace nss_test
+
+#endif