File: test_enum_underlying.cpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (29 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <gtest/gtest.h>

#include <rfl/json.hpp>

namespace test_enum_underlying {

enum class CameraSource : uint32_t { kWide, kInfrared, kZoom };

struct ChangeCameraSourcePayload {
  CameraSource source;
};

constexpr const char* payloads[2] = {R"({"source":20})",
                                     R"({"source":"hello"})"};

TEST(json, test_enum_underlying) {
  const auto res1 = static_cast<int>(
      rfl::json::read<ChangeCameraSourcePayload, rfl::UnderlyingEnums>(
          payloads[0])
          .value()
          .source);
  const auto res2 =
      rfl::json::read<CameraSource, rfl::UnderlyingEnums>(payloads[1]);

  EXPECT_EQ(res1, 20);
  EXPECT_TRUE(!res2);  // should not succeed
}

}  // namespace test_enum_underlying