/* * Copyright (C) 2018 The Android Open Source Project * * Licensed 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 "utils/variant.h" #include "gmock/gmock.h" #include "gtest/gtest.h" namespace libtextclassifier3 { namespace { TEST(VariantTest, GetType) { EXPECT_EQ(Variant().GetType(), Variant::TYPE_EMPTY); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_INT8_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_UINT8_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_INT_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_UINT_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_INT64_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_UINT64_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_FLOAT_VALUE); EXPECT_EQ(Variant(static_cast(9)).GetType(), Variant::TYPE_DOUBLE_VALUE); EXPECT_EQ(Variant(true).GetType(), Variant::TYPE_BOOL_VALUE); EXPECT_EQ(Variant("hello").GetType(), Variant::TYPE_STRING_VALUE); } TEST(VariantTest, HasValue) { EXPECT_FALSE(Variant().HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(static_cast(9)).HasValue()); EXPECT_TRUE(Variant(true).HasValue()); EXPECT_TRUE(Variant("hello").HasValue()); } TEST(VariantTest, Value) { EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(static_cast(9)).Value(), 9); EXPECT_EQ(Variant(true).Value(), true); EXPECT_EQ(Variant("hello").ConstRefValue(), "hello"); } } // namespace } // namespace libtextclassifier3