| 30 | using namespace tvm::ffi::testing; |
| 31 | |
| 32 | TEST(Any, Int) { |
| 33 | AnyView view0; |
| 34 | EXPECT_EQ(view0.CopyToTVMFFIAny().type_index, TypeIndex::kTVMFFINone); |
| 35 | |
| 36 | Optional<int64_t> opt_v0 = view0.as<int64_t>(); |
| 37 | EXPECT_TRUE(!opt_v0.has_value()); |
| 38 | |
| 39 | EXPECT_THROW( |
| 40 | { |
| 41 | try { |
| 42 | [[maybe_unused]] auto v0 = view0.cast<int>(); |
| 43 | } catch (const Error& error) { |
| 44 | EXPECT_EQ(error.kind(), "TypeError"); |
| 45 | std::string what = error.what(); |
| 46 | EXPECT_NE(what.find("Cannot convert from type `None` to `int`"), std::string::npos); |
| 47 | throw; |
| 48 | } |
| 49 | }, |
| 50 | ::tvm::ffi::Error); |
| 51 | |
| 52 | AnyView view1 = 1; |
| 53 | EXPECT_EQ(view1.CopyToTVMFFIAny().type_index, TypeIndex::kTVMFFIInt); |
| 54 | EXPECT_EQ(view1.CopyToTVMFFIAny().v_int64, 1); |
| 55 | |
| 56 | auto int_v1 = view1.cast<int>(); |
| 57 | EXPECT_EQ(int_v1, 1); |
| 58 | |
| 59 | int64_t v1 = 2; |
| 60 | view0 = v1; |
| 61 | EXPECT_EQ(view0.CopyToTVMFFIAny().type_index, TypeIndex::kTVMFFIInt); |
| 62 | EXPECT_EQ(view0.CopyToTVMFFIAny().v_int64, 2); |
| 63 | |
| 64 | uint64_t v2 = static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) + 1; |
| 65 | EXPECT_THROW( |
| 66 | { |
| 67 | try { |
| 68 | view0 = v2; |
| 69 | } catch (const Error& error) { |
| 70 | EXPECT_EQ(error.kind(), "OverflowError"); |
| 71 | std::string what = error.what(); |
| 72 | EXPECT_NE(what.find("is too large to fit in int64_t"), std::string::npos); |
| 73 | throw; |
| 74 | } |
| 75 | }, |
| 76 | ::tvm::ffi::Error); |
| 77 | } |
| 78 | |
| 79 | TEST(Any, Enum) { |
| 80 | enum class ENum : int { |
nothing calls this directly
no test coverage detected