MCPcopy Create free account
hub / github.com/apache/tvm-ffi / TEST

Function TEST

tests/cpp/test_any.cc:32–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30using namespace tvm::ffi::testing;
31
32TEST(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
79TEST(Any, Enum) {
80 enum class ENum : int {

Callers

nothing calls this directly

Calls 15

TPrimExprClass · 0.85
AnyEqualClass · 0.85
AnyHashClass · 0.85
StableHashCombineFunction · 0.85
TFloatClass · 0.85
CopyToTVMFFIAnyMethod · 0.80
TIntClass · 0.70
StringClass · 0.50
BytesClass · 0.50
has_valueMethod · 0.45
kindMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected