OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_CERT_INTERNAL_TEST_HELPERS_H_ |
| 6 #define NET_CERT_INTERNAL_TEST_HELPERS_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "net/der/input.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 // Creates a der::Input from an std::string. The lifetimes are a bit subtle |
| 17 // when using this function: |
| 18 // |
| 19 // The returned der::Input() is only valid so long as the input string is alive |
| 20 // and is not mutated. |
| 21 // |
| 22 // Note that the input parameter has been made a pointer to prevent callers |
| 23 // from accidentally passing an r-value. |
| 24 der::Input InputFromString(const std::string* s); |
| 25 |
| 26 // Helper structure that maps a PEM block header (for instance "CERTIFICATE") to |
| 27 // the destination where the value for that block should be written. |
| 28 struct PemBlockMapping { |
| 29 const char* block_name; |
| 30 std::string* value; |
| 31 }; |
| 32 |
| 33 // ReadTestDataFromPemFile() is a helper function that reads a PEM test file |
| 34 // rooted in the "src/" directory. |
| 35 // |
| 36 // * file_path_ascii: |
| 37 // The path to the PEM file, relative to src. For instance |
| 38 // "net/data/verify_signed_data_unittest/foopy.pem" |
| 39 // |
| 40 // * mappings: |
| 41 // An array of length |mappings_length| which maps the expected PEM |
| 42 // headers to the destination to write its data. |
| 43 // |
| 44 // The function ensures that each of the chosen mappings is satisfied exactly |
| 45 // once. In other words, the header must be present, have valid data, and |
| 46 // appear no more than once. |
| 47 ::testing::AssertionResult ReadTestDataFromPemFile( |
| 48 const std::string& file_path_ascii, |
| 49 const PemBlockMapping* mappings, |
| 50 size_t mappings_length); |
| 51 |
| 52 // This is the same as the variant above, however it uses template magic so an |
| 53 // mappings array can be passed in directly (and the correct length is |
| 54 // inferred). |
| 55 template <size_t N> |
| 56 ::testing::AssertionResult ReadTestDataFromPemFile( |
| 57 const std::string& file_path_ascii, |
| 58 const PemBlockMapping(&mappings)[N]) { |
| 59 return ReadTestDataFromPemFile(file_path_ascii, mappings, N); |
| 60 } |
| 61 |
| 62 } // namespace net |
| 63 |
| 64 #endif // NET_CERT_INTERNAL_TEST_HELPERS_H_ |
OLD | NEW |