Commit 1ce8eb06 authored by kmarshall's avatar kmarshall Committed by Commit bot

Define canonical enum for "HeliumResult" status values.

Add HeliumResult-to-string mapping for easier logging.
Add unit tests for string conversion functions.

R=lethalantidote@chromium.org,gcasto@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2385913002
Cr-Commit-Position: refs/heads/master@{#422683}
parent 076dd1eb
...@@ -94,6 +94,9 @@ component("net") { ...@@ -94,6 +94,9 @@ component("net") {
source_set("helium") { source_set("helium") {
sources = [ sources = [
"helium/helium_errors.h",
"helium/helium_result.cc",
"helium/helium_result.h",
"helium/vector_clock.cc", "helium/vector_clock.cc",
"helium/vector_clock.h", "helium/vector_clock.h",
] ]
...@@ -110,7 +113,7 @@ source_set("helium") { ...@@ -110,7 +113,7 @@ source_set("helium") {
source_set("net_export") { source_set("net_export") {
sources = [ sources = [
"blimp_net_export.h", "blimp_net_export.h",
] ]
} }
...@@ -159,6 +162,7 @@ source_set("unit_tests") { ...@@ -159,6 +162,7 @@ source_set("unit_tests") {
"delta_encoding_unittest.cc", "delta_encoding_unittest.cc",
"engine_authentication_handler_unittest.cc", "engine_authentication_handler_unittest.cc",
"engine_connection_manager_unittest.cc", "engine_connection_manager_unittest.cc",
"helium/helium_result_unittest.cc",
"helium/vector_clock_unittest.cc", "helium/vector_clock_unittest.cc",
"input_message_unittest.cc", "input_message_unittest.cc",
"ssl_client_transport_unittest.cc", "ssl_client_transport_unittest.cc",
......
// Copyright 2016 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.
// This file intentionally does not have header guards, it's included
// inside a macro to generate enum values.
// This file contains the list of Helium error codes.
HELIUM_ERROR(INTERNAL_ERROR, 1)
// The operation could not be performed because the connection to the peer was
// lost.
HELIUM_ERROR(DISCONNECTED, 2)
// Copyright 2016 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.
#include "blimp/net/helium/helium_result.h"
#include "base/logging.h"
namespace blimp {
const char* HeliumResultToString(HeliumResult result) {
switch (result) {
case HeliumResult::SUCCESS:
return "SUCCESS";
break;
#define HELIUM_ERROR(label, value) \
case HeliumResult::ERR_##label: \
return "ERR_" #label;
break;
#include "blimp/net/helium/helium_errors.h"
#undef HELIUM_ERROR
}
NOTREACHED();
return "";
}
} // namespace blimp
// Copyright 2016 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 BLIMP_NET_HELIUM_HELIUM_RESULT_H_
#define BLIMP_NET_HELIUM_HELIUM_RESULT_H_
#include "blimp/net/blimp_net_export.h"
namespace blimp {
// Defines the canonical list of Helium result codes.
// HeliumResult::OK is the only non-error code.
// All other codes are considered errors and are prefixed by ERR_.
// See error_list.h for the unprefixed list of error codes.
//
// (Approach is inspired by net/base/net_errors.h)
enum HeliumResult {
SUCCESS,
#define HELIUM_ERROR(label, value) ERR_##label = value,
#include "blimp/net/helium/helium_errors.h"
#undef HELIUM_ERROR
};
// Gets a human-readable string representation of |result|.
const char* BLIMP_NET_EXPORT HeliumResultToString(HeliumResult result);
} // namespace blimp
#endif // BLIMP_NET_HELIUM_HELIUM_RESULT_H_
// Copyright 2016 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.
#include "blimp/net/helium/helium_result.h"
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blimp {
namespace {
class HeliumResultTest : public testing::Test {
public:
HeliumResultTest() {}
~HeliumResultTest() override {}
};
TEST_F(HeliumResultTest, HeliumResultToString) {
// The exhaustive list of errors need not be specified here, but enough are
// specified that we can verify that the switch/case mapping works as
// intended.
EXPECT_STREQ("SUCCESS", HeliumResultToString(HeliumResult::SUCCESS));
EXPECT_STREQ("ERR_INTERNAL_ERROR",
HeliumResultToString(HeliumResult::ERR_INTERNAL_ERROR));
EXPECT_STREQ("ERR_DISCONNECTED",
HeliumResultToString(HeliumResult::ERR_DISCONNECTED));
}
} // namespace
} // namespace blimp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment