diff options
Diffstat (limited to 'src/components/rpc_base')
-rw-r--r-- | src/components/rpc_base/include/rpc_base/validation_report.h | 122 | ||||
-rw-r--r-- | src/components/rpc_base/test/rpc_base_test.cc | 22 | ||||
-rw-r--r-- | src/components/rpc_base/test/validation_report_test.cc | 2 |
3 files changed, 12 insertions, 134 deletions
diff --git a/src/components/rpc_base/include/rpc_base/validation_report.h b/src/components/rpc_base/include/rpc_base/validation_report.h deleted file mode 100644 index 4397112d54..0000000000 --- a/src/components/rpc_base/include/rpc_base/validation_report.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ -#define SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ - -#include <string> -#include <list> - -namespace rpc { - -class ValidationReport; -typedef std::list<ValidationReport> ValidationReports; - -class ValidationReport { - public: - explicit ValidationReport(const std::string& object_name); - const std::string& object_name() const; - const std::string& validation_info() const; - void set_validation_info(const std::string& info); - const ValidationReports& subobject_reports() const; - ValidationReport& ReportSubobject(const std::string& object_name); - - private: - std::string object_name_; - std::string validation_info_; - ValidationReports subobject_reports_; -}; - -std::string PrettyFormat(const ValidationReport& report); - -// Implementation - -namespace impl { -inline void PrettyFormat(const ValidationReport& report, - const std::string& parent_path, - std::string* result) { - std::string object_path = parent_path; - if (!object_path.empty() && report.object_name()[0] != '[') { - object_path.append("."); - } - object_path.append(report.object_name()); - if (!report.validation_info().empty()) { - result->append(object_path); - result->append(": "); - result->append(report.validation_info()); - result->append("\n"); - } - const ValidationReports& subreports = report.subobject_reports(); - for (ValidationReports::const_iterator i = subreports.begin(), - end = subreports.end(); - i != end; - ++i) { - PrettyFormat(*i, object_path, result); - } -} -} // namespace impl - -inline ValidationReport::ValidationReport(const std::string& object_name) - : object_name_(object_name) {} - -inline const std::string& ValidationReport::object_name() const { - return object_name_; -} - -inline const std::string& ValidationReport::validation_info() const { - return validation_info_; -} - -inline void ValidationReport::set_validation_info(const std::string& info) { - validation_info_ = info; -} - -inline const std::list<ValidationReport>& ValidationReport::subobject_reports() - const { - return subobject_reports_; -} - -inline ValidationReport& ValidationReport::ReportSubobject( - const std::string& object_name) { - subobject_reports_.push_back(ValidationReport(object_name)); - return subobject_reports_.back(); -} - -inline std::string PrettyFormat(const ValidationReport& report) { - std::string result; - impl::PrettyFormat(report, "", &result); - return result; -} - -} // namespace rpc - -#endif // SRC_COMPONENTS_RPC_BASE_INCLUDE_RPC_BASE_VALIDATION_REPORT_H_ diff --git a/src/components/rpc_base/test/rpc_base_test.cc b/src/components/rpc_base/test/rpc_base_test.cc index c4ffbc321e..d81e01db6c 100644 --- a/src/components/rpc_base/test/rpc_base_test.cc +++ b/src/components/rpc_base/test/rpc_base_test.cc @@ -320,7 +320,7 @@ TEST(ValidatedTypes, ReportUninitializedIntType) { ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); - ASSERT_EQ("val: value is not initialized\n", PrettyFormat(report)); + ASSERT_EQ("val: value is not initialized", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectInitializedIntType) { @@ -328,7 +328,7 @@ TEST(ValidatedTypes, ReportIncorrectInitializedIntType) { ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); - ASSERT_EQ("val: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ("val: value initialized incorrectly", PrettyFormat(report)); } TEST(ValidatedTypes, ReportUninitializedOptionalType) { @@ -344,7 +344,7 @@ TEST(ValidatedTypes, ReportIncorrectInitializedOptionalType) { ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); - ASSERT_EQ("val: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ("val: value initialized incorrectly", PrettyFormat(report)); } TEST(ValidatedTypes, ReportUninitializedNullableIntType) { @@ -352,7 +352,7 @@ TEST(ValidatedTypes, ReportUninitializedNullableIntType) { ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); - ASSERT_EQ("val: value is not initialized\n", PrettyFormat(report)); + ASSERT_EQ("val: value is not initialized", PrettyFormat(report)); } TEST(ValidatedTypes, ReportNullInitializedNullableIntType) { @@ -369,7 +369,7 @@ TEST(ValidatedTypes, ReportNoninitializedIntArray) { ASSERT_FALSE(array.is_valid()); ValidationReport report("array"); array.ReportErrors(&report); - ASSERT_EQ("array: object is not initialized\n", PrettyFormat(report)); + ASSERT_EQ("array: object is not initialized", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray1) { @@ -378,7 +378,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray1) { ASSERT_FALSE(array.is_valid()); ValidationReport report("array"); array.ReportErrors(&report); - ASSERT_EQ("array[0]: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ("array[0]: value initialized incorrectly", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray2) { @@ -390,7 +390,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray2) { ASSERT_FALSE(array.is_valid()); ValidationReport report("array"); array.ReportErrors(&report); - ASSERT_EQ("array: array has invalid size\n", PrettyFormat(report)); + ASSERT_EQ("array: array has invalid size", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedArray3) { @@ -403,7 +403,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedArray3) { array.ReportErrors(&report); ASSERT_EQ( "array: array has invalid size\n" - "array[2]: value initialized incorrectly\n", + "array[2]: value initialized incorrectly", PrettyFormat(report)); } @@ -411,7 +411,7 @@ TEST(ValidatedTypes, ReportUninitializedMap) { Map<Integer<int8_t, 1, 10>, 1, 3> map; ValidationReport report("map"); map.ReportErrors(&report); - ASSERT_EQ("map: object is not initialized\n", PrettyFormat(report)); + ASSERT_EQ("map: object is not initialized", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedMap1) { @@ -419,7 +419,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedMap1) { map["aha"] = 42; ValidationReport report("map"); map.ReportErrors(&report); - ASSERT_EQ("map[\"aha\"]: value initialized incorrectly\n", + ASSERT_EQ("map[\"aha\"]: value initialized incorrectly", PrettyFormat(report)); } @@ -433,7 +433,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedMap2) { map.ReportErrors(&report); ASSERT_EQ( "map[\"haha\"]: value initialized incorrectly\n" - "map[\"muhahaha\"]: value initialized incorrectly\n", + "map[\"muhahaha\"]: value initialized incorrectly", PrettyFormat(report)); } diff --git a/src/components/rpc_base/test/validation_report_test.cc b/src/components/rpc_base/test/validation_report_test.cc index 596bfdb20d..10effe7dd2 100644 --- a/src/components/rpc_base/test/validation_report_test.cc +++ b/src/components/rpc_base/test/validation_report_test.cc @@ -75,7 +75,7 @@ class ValidationReportTest : public testing::Test { } else { temp = ""; } - result = parent_name + temp + obj_name + ":" + " " + val_info + "\n"; + result = parent_name + temp + obj_name + ":" + " " + val_info; } void ClearValidationInfo() { |