• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/c/tf_status_helper.h"
17 
18 #include "tensorflow/core/platform/errors.h"
19 #include "tensorflow/core/platform/test.h"
20 
21 namespace tensorflow {
22 namespace {
23 
TEST(StatusHelper,TestStatusHelper)24 TEST(StatusHelper, TestStatusHelper) {
25   TF_Status* s = TF_NewStatus();
26   Status cc_status(errors::InvalidArgument("some error"));
27   cc_status.SetPayload("key1", "value1");
28   cc_status.SetPayload("key2", "value2");
29   Set_TF_Status_from_Status(s, cc_status);
30   ASSERT_EQ(TF_INVALID_ARGUMENT, TF_GetCode(s));
31   ASSERT_EQ(std::string("some error"), TF_Message(s));
32 
33   Status another_cc_status(StatusFromTF_Status(s));
34   ASSERT_FALSE(another_cc_status.ok());
35   ASSERT_EQ(std::string("some error"), another_cc_status.error_message());
36   ASSERT_EQ(error::INVALID_ARGUMENT, another_cc_status.code());
37   // Ensure the payloads are not lost during conversions
38   ASSERT_EQ(cc_status.GetPayload("key1"), another_cc_status.GetPayload("key1"));
39   ASSERT_EQ(cc_status.GetPayload("key2"), another_cc_status.GetPayload("key2"));
40   TF_DeleteStatus(s);
41 }
42 
43 }  // namespace
44 }  // namespace tensorflow
45