|  | 
|  | 1 | +/* Copyright (c) 2021 PaddlePaddle 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 | +#include "paddle/pten/common/data_type.h" | 
|  | 16 | + | 
|  | 17 | +#include <gtest/gtest.h> | 
|  | 18 | +#include <iostream> | 
|  | 19 | +#include <sstream> | 
|  | 20 | + | 
|  | 21 | +TEST(DataType, OStream) { | 
|  | 22 | +  std::ostringstream oss; | 
|  | 23 | +  oss << pten::DataType::UNDEFINED; | 
|  | 24 | +  EXPECT_EQ(oss.str(), "Undefined"); | 
|  | 25 | +  oss.str(""); | 
|  | 26 | +  oss << pten::DataType::BOOL; | 
|  | 27 | +  EXPECT_EQ(oss.str(), "bool"); | 
|  | 28 | +  oss.str(""); | 
|  | 29 | +  oss << pten::DataType::INT8; | 
|  | 30 | +  EXPECT_EQ(oss.str(), "int8"); | 
|  | 31 | +  oss.str(""); | 
|  | 32 | +  oss << pten::DataType::UINT8; | 
|  | 33 | +  EXPECT_EQ(oss.str(), "uint8"); | 
|  | 34 | +  oss.str(""); | 
|  | 35 | +  oss << pten::DataType::INT16; | 
|  | 36 | +  EXPECT_EQ(oss.str(), "int16"); | 
|  | 37 | +  oss.str(""); | 
|  | 38 | +  oss << pten::DataType::INT32; | 
|  | 39 | +  EXPECT_EQ(oss.str(), "int32"); | 
|  | 40 | +  oss.str(""); | 
|  | 41 | +  oss << pten::DataType::INT64; | 
|  | 42 | +  EXPECT_EQ(oss.str(), "int64"); | 
|  | 43 | +  oss.str(""); | 
|  | 44 | +  oss << pten::DataType::BFLOAT16; | 
|  | 45 | +  EXPECT_EQ(oss.str(), "bfloat16"); | 
|  | 46 | +  oss.str(""); | 
|  | 47 | +  oss << pten::DataType::FLOAT16; | 
|  | 48 | +  EXPECT_EQ(oss.str(), "float16"); | 
|  | 49 | +  oss.str(""); | 
|  | 50 | +  oss << pten::DataType::FLOAT32; | 
|  | 51 | +  EXPECT_EQ(oss.str(), "float32"); | 
|  | 52 | +  oss.str(""); | 
|  | 53 | +  oss << pten::DataType::FLOAT64; | 
|  | 54 | +  EXPECT_EQ(oss.str(), "float64"); | 
|  | 55 | +  oss.str(""); | 
|  | 56 | +  oss << pten::DataType::COMPLEX64; | 
|  | 57 | +  EXPECT_EQ(oss.str(), "complex64"); | 
|  | 58 | +  oss.str(""); | 
|  | 59 | +  oss << pten::DataType::COMPLEX128; | 
|  | 60 | +  EXPECT_EQ(oss.str(), "complex128"); | 
|  | 61 | +  oss.str(""); | 
|  | 62 | +  try { | 
|  | 63 | +    oss << pten::DataType::NUM_DATA_TYPES; | 
|  | 64 | +  } catch (paddle::platform::EnforceNotMet &exception) { | 
|  | 65 | +    std::string ex_msg = exception.what(); | 
|  | 66 | +    EXPECT_TRUE(ex_msg.find("Invalid enum data type") != std::string::npos); | 
|  | 67 | +  } | 
|  | 68 | +} | 
0 commit comments