From a76b8883af29aa29b601b3f555a020fce0375e5e Mon Sep 17 00:00:00 2001 From: Jihoon Son Date: Wed, 10 Aug 2016 23:11:56 +0900 Subject: [PATCH 1/3] Make code() public and add message() --- cpp/src/arrow/util/status.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/util/status.h b/cpp/src/arrow/util/status.h index 6ba2035bcd3..d5585313c72 100644 --- a/cpp/src/arrow/util/status.h +++ b/cpp/src/arrow/util/status.h @@ -138,6 +138,18 @@ class ARROW_EXPORT Status { // Get the POSIX code associated with this Status, or -1 if there is none. int16_t posix_code() const; + StatusCode code() const { + return ((state_ == NULL) ? StatusCode::OK : static_cast(state_[4])); + } + + std::string message() const { + uint32_t length; + memcpy(&length, state_, sizeof(length)); + std::string msg; + msg.append((state_ + 7), length); + return msg; + } + private: // OK status has a NULL state_. Otherwise, state_ is a new[] array // of the following form: @@ -147,10 +159,6 @@ class ARROW_EXPORT Status { // state_[7..] == message const char* state_; - StatusCode code() const { - return ((state_ == NULL) ? StatusCode::OK : static_cast(state_[4])); - } - Status(StatusCode code, const std::string& msg, int16_t posix_code); static const char* CopyState(const char* s); }; From 4275c704d9a155d3bce7fd85ddfd54154c6670a9 Mon Sep 17 00:00:00 2001 From: Jihoon Son Date: Mon, 15 Aug 2016 22:46:02 +0900 Subject: [PATCH 2/3] Add tests for status --- cpp/src/arrow/util/CMakeLists.txt | 1 + cpp/src/arrow/util/status-test.cc | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cpp/src/arrow/util/status-test.cc diff --git a/cpp/src/arrow/util/CMakeLists.txt b/cpp/src/arrow/util/CMakeLists.txt index 4e941fb5f5c..13c0d7514fe 100644 --- a/cpp/src/arrow/util/CMakeLists.txt +++ b/cpp/src/arrow/util/CMakeLists.txt @@ -70,3 +70,4 @@ endif() ADD_ARROW_TEST(bit-util-test) ADD_ARROW_TEST(buffer-test) ADD_ARROW_TEST(memory-pool-test) +ADD_ARROW_TEST(status-test) \ No newline at end of file diff --git a/cpp/src/arrow/util/status-test.cc b/cpp/src/arrow/util/status-test.cc new file mode 100644 index 00000000000..5487bfeda0b --- /dev/null +++ b/cpp/src/arrow/util/status-test.cc @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include + +#include "arrow/util/status.h" +#include "arrow/test-util.h" + +namespace arrow { + +TEST(StatusTest, TestCodeAndMessage) { + Status ok = Status::OK(); + ASSERT_EQ(StatusCode::OK, ok.code()); + Status file_error = Status::IOError("file error"); + ASSERT_EQ(StatusCode::IOError, file_error.code()); + ASSERT_EQ("file error", file_error.message()); +} + +TEST(StatusTest, TestToString) { + Status file_error = Status::IOError("file error"); + ASSERT_EQ("IOError: file error", file_error.ToString()); +} + +} // namespace arrow From d1186bf5e548fb138e62d02a0712fa6fa51f2dd3 Mon Sep 17 00:00:00 2001 From: Jihoon Son Date: Mon, 15 Aug 2016 22:53:48 +0900 Subject: [PATCH 3/3] Fix compilation failure --- cpp/src/arrow/util/status-test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/util/status-test.cc b/cpp/src/arrow/util/status-test.cc index 5487bfeda0b..45e0ff361ac 100644 --- a/cpp/src/arrow/util/status-test.cc +++ b/cpp/src/arrow/util/status-test.cc @@ -15,8 +15,7 @@ // specific language governing permissions and limitations // under the License. -#include -#include +#include "gtest/gtest.h" #include "arrow/util/status.h" #include "arrow/test-util.h"