MCPcopy Create free account
hub / github.com/apache/thrift / main

Function main

test/cpp/src/EnumClassTest.cpp:36–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34using namespace thrift::test;
35
36int main() {
37 std::cout << "Testing pure_enums=enum_class with ThriftTest types..." << std::endl;
38
39 // Compile-time verification that Numberz is an enum class
40 static_assert(std::is_enum<Numberz>::value, "Numberz should be an enum type");
41 // enum class doesn't implicitly convert to int, which is a key characteristic
42 static_assert(!std::is_convertible<Numberz, int>::value,
43 "Numberz should be enum class (not implicitly convertible to int)");
44 std::cout << " ✓ Compile-time verification: Numberz is enum class" << std::endl;
45
46 // Test 1: Verify enum class can be used with scoped names
47 {
48 Numberz num = Numberz::ONE;
49 assert(static_cast<int>(num) == 1);
50 std::cout << " ✓ Enum class scoped access works (Numberz::ONE)" << std::endl;
51 }
52
53 // Test 2: Verify different enum values
54 {
55 Numberz two = Numberz::TWO;
56 Numberz five = Numberz::FIVE;
57 assert(static_cast<int>(two) == 2);
58 assert(static_cast<int>(five) == 5);
59 std::cout << " ✓ Multiple enum class values work" << std::endl;
60 }
61
62 // Test 3: Verify enum class comparison
63 {
64 Numberz a = Numberz::THREE;
65 Numberz b = Numberz::THREE;
66 Numberz c = Numberz::FIVE;
67 assert(a == b);
68 assert(a != c);
69 std::cout << " ✓ Enum class comparison works" << std::endl;
70 }
71
72 // Test 4: Verify enum class in switch statement
73 {
74 Numberz num = Numberz::EIGHT;
75 bool found = false;
76 switch(num) {
77 case Numberz::ONE:
78 break;
79 case Numberz::TWO:
80 break;
81 case Numberz::EIGHT:
82 found = true;
83 break;
84 default:
85 break;
86 }
87 assert(found);
88 std::cout << " ✓ Enum class in switch statements works" << std::endl;
89 }
90
91 // Test 5: Verify to_string() works with enum class
92 {
93 Numberz one = Numberz::ONE;

Callers

nothing calls this directly

Calls 2

strMethod · 0.80
to_stringFunction · 0.50

Tested by

no test coverage detected