Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: net/cert/internal/test_helpers.h

Issue 1290553002: [refactor] Extract some test helpers for certificate verification unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_mapper
Patch Set: rebase onto master Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/cert/internal/test_helpers.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/internal/test_helpers.h
diff --git a/net/cert/internal/test_helpers.h b/net/cert/internal/test_helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..99405ba8e5f3bdcea3ad8c802e5ec86b807f0c3b
--- /dev/null
+++ b/net/cert/internal/test_helpers.h
@@ -0,0 +1,64 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_CERT_INTERNAL_TEST_HELPERS_H_
+#define NET_CERT_INTERNAL_TEST_HELPERS_H_
+
+#include <string>
+#include <vector>
+
+#include "net/der/input.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+// Creates a der::Input from an std::string. The lifetimes are a bit subtle
+// when using this function:
+//
+// The returned der::Input() is only valid so long as the input string is alive
+// and is not mutated.
+//
+// Note that the input parameter has been made a pointer to prevent callers
+// from accidentally passing an r-value.
+der::Input InputFromString(const std::string* s);
+
+// Helper structure that maps a PEM block header (for instance "CERTIFICATE") to
+// the destination where the value for that block should be written.
+struct PemBlockMapping {
+ const char* block_name;
+ std::string* value;
+};
+
+// ReadTestDataFromPemFile() is a helper function that reads a PEM test file
+// rooted in the "src/" directory.
+//
+// * file_path_ascii:
+// The path to the PEM file, relative to src. For instance
+// "net/data/verify_signed_data_unittest/foopy.pem"
+//
+// * mappings:
+// An array of length |mappings_length| which maps the expected PEM
+// headers to the destination to write its data.
+//
+// The function ensures that each of the chosen mappings is satisfied exactly
+// once. In other words, the header must be present, have valid data, and
+// appear no more than once.
+::testing::AssertionResult ReadTestDataFromPemFile(
+ const std::string& file_path_ascii,
+ const PemBlockMapping* mappings,
+ size_t mappings_length);
+
+// This is the same as the variant above, however it uses template magic so an
+// mappings array can be passed in directly (and the correct length is
+// inferred).
+template <size_t N>
+::testing::AssertionResult ReadTestDataFromPemFile(
+ const std::string& file_path_ascii,
+ const PemBlockMapping(&mappings)[N]) {
+ return ReadTestDataFromPemFile(file_path_ascii, mappings, N);
+}
+
+} // namespace net
+
+#endif // NET_CERT_INTERNAL_TEST_HELPERS_H_
« no previous file with comments | « no previous file | net/cert/internal/test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698