// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/parse_number.h" #include <limits> #include <sstream> #include "base/strings/string_number_conversions.h" #include "testing/gtest/include/gtest/gtest.h" namespace net { namespace { // Returns a decimal string that is one larger than the maximum value that type // T can represent. template <typename T> std::string CreateOverflowString() { … } // Returns a decimal string that is one less than the minimum value that // (signed) type T can represent. template <typename T> std::string CreateUnderflowString() { … } // These are potentially valid inputs, along with whether they're non-negative // or "strict" (minimal representations). const struct { … } kAnnotatedTests[] = …; // These are invalid inputs that can not be parsed regardless of the format // used (they are neither valid negative or non-negative values). const char* kInvalidParseTests[] = …; // This wrapper calls func() and expects the result to match |expected_output|. template <typename OutputType, typename ParseFunc, typename ExpectationType> void ExpectParseIntSuccess(ParseFunc func, std::string_view input, ParseIntFormat format, ExpectationType expected_output) { … } // This wrapper calls func() and expects the failure to match |expected_error|. template <typename OutputType, typename ParseFunc> void ExpectParseIntFailure(ParseFunc func, std::string_view input, ParseIntFormat format, ParseIntError expected_error) { … } // Common tests for both ParseInt*() and ParseUint*() // // When testing ParseUint*() the |format| parameter is not applicable and // should be passed as NON_NEGATIVE. template <typename T, typename ParseFunc> void TestParseIntUsingFormat(ParseFunc func, ParseIntFormat format) { … } // Common tests to run for each of the versions of ParseInt*(). // // The `func` parameter should be a function pointer to the particular // ParseInt*() function to test. template <typename T, typename ParseFunc> void TestParseInt(ParseFunc func) { … } // Common tests to run for each of the versions of ParseUint*(). // // The `func` parameter should be a function pointer to the particular // ParseUint*() function to test. template <typename T, typename ParseFunc> void TestParseUint(ParseFunc func) { … } TEST(ParseNumberTest, ParseInt32) { … } TEST(ParseNumberTest, ParseInt64) { … } TEST(ParseNumberTest, ParseUint32) { … } TEST(ParseNumberTest, ParseUint64) { … } } // namespace } // namespace net